Skip to content

Commit

Permalink
Custom subgenres tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Marekkon5 committed Jan 9, 2024
1 parent e241172 commit 0345154
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
20 changes: 20 additions & 0 deletions client/src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@
<q-btn flat round icon='mdi-plus' @click='addGenre' color='primary'></q-btn>
</div>
</div>

<!-- Subgenre tag -->
<div class='q-mt-md q-mb-sm'>
<q-checkbox
label='Custom subgenre tag'
:model-value="!!$1t.settings.value.quickTag.subgenreTag"
@update:model-value="(v) => enableCustomSubgenreTag(v)"
></q-checkbox>
<TagFields v-if='$1t.settings.value.quickTag.subgenreTag' class='col-10 q-mt-sm q-mb-md' style='margin-bottom: 20px;' dense v-model='$1t.settings.value.quickTag.subgenreTag'></TagFields>
</div>

</div>
</div>

Expand Down Expand Up @@ -502,6 +513,15 @@ function onSubgenreInput(e: string | null, i: number) {
$1t.settings.value.quickTag.genres[i].subgenres = e.split(",");
}
/// Enable custom subgenre tag
function enableCustomSubgenreTag(enable: boolean) {
if (enable) {
$1t.settings.value.quickTag.subgenreTag = new FrameName('TCON', 'GENRE', '©gen');
} else {
$1t.settings.value.quickTag.subgenreTag = undefined;
}
}
function browseQuickTag() {
$1t.browse('qt', $1t.settings.value.path);
Expand Down
32 changes: 28 additions & 4 deletions client/src/scripts/quicktag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ class QTTrack implements QuickTagFile {
this.custom = this.loadCustom();
// Stupid copy
this.originalGenres = JSON.parse(JSON.stringify(this.genres));
// Add subgenres
if (settings.subgenreTag) {
let subgenres = (this.tags[this.removeAbstractions(settings.subgenreTag.byFormat(this.format))] ?? []);
this.originalGenres.push(...subgenres.filter(g => !this.genres.includes(g)));
this.genres.push(...subgenres.filter(g => !this.genres.includes(g)));
}
}


Expand Down Expand Up @@ -472,10 +478,28 @@ class QTTrack implements QuickTagFile {
}
// Genre change
if (this.genres.join('') != this.originalGenres.join('')) {
changes.push({
type: 'genre',
value: this.genres
})
// Subgenre custom tag
if (this.settings.subgenreTag) {

let subgenres = this.genres.filter((genre) => this.settings.genres.find((g) => g.subgenres.includes(genre)));
let genres = this.genres.filter((g) => !subgenres.includes(g));

changes.push({
type: 'raw',
tag: this.settings.subgenreTag.byFormat(this.format),
value: subgenres
});
changes.push({
type: 'genre',
value: genres
});

} else {
changes.push({
type: 'genre',
value: this.genres
});
}
}

// Note change
Expand Down
6 changes: 5 additions & 1 deletion client/src/scripts/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ class QuickTagSettings {
}
]

// Custom subgenre tag
subgenreTag?: FrameName;

// Manually load from JSON to restore classes
static fromJson(data: any): QuickTagSettings {
let qt: QuickTagSettings = Object.assign(new QuickTagSettings(), data);
Expand All @@ -190,7 +193,8 @@ class QuickTagSettings {
return v;
});
return c;
})
});
qt.subgenreTag = qt.subgenreTag ? FrameName.fromJson(data.subgenreTag) : undefined;
return qt;
}
}
Expand Down

0 comments on commit 0345154

Please sign in to comment.