Skip to content

Commit

Permalink
Added character blacklisting
Browse files Browse the repository at this point in the history
Bumped version to 0.2.0
  • Loading branch information
Wavefarer42 committed Apr 28, 2020
1 parent 0981b43 commit 19d5e37
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 114 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "Hannes Thaller",
"email": "[email protected]",
"homepage": "https://tallic.github.io/name-it/",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"license": "MIT",
"repository": "https://github.com/Tallic/name-it",
Expand Down
12 changes: 10 additions & 2 deletions src/assets/EpisodeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ export default {
}
}).sort((a, b) => a.episodeNumber - b.episodeNumber)
},
formatEpisodeName(episode, format) {
normalizeFileNames(name, blacklist) {
if(blacklist === null || blacklist.length === 0 || name === null || name.length === 0 ){
return name
}

const blacklistSet = new Set(blacklist)
return Array.from(name).map(c => blacklistSet.has(c) ? '' : c).join('')
},
formatEpisodeName(episode, format, blacklist) {
let name = format.replace("{series}", episode.seriesTitle)
.replace("{episode}", episode.episodeTitle);

Expand All @@ -73,6 +81,6 @@ export default {
name = replaceNumberPattern(name, episode.seasonNumber, seasonNumberRegex);
name = replaceNumberPattern(name, episode.seasonNumber, seasonNumberRegexPrefix, "S");

return name
return this.normalizeFileNames(name, blacklist)
}
}
1 change: 1 addition & 0 deletions src/assets/FileService.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default {

return _.sortBy(files, ["weight"])
},

async renameFiles(files, names) {

let promises = [];
Expand Down
100 changes: 50 additions & 50 deletions src/components/EpisodeList.vue
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
<template>
<v-card class="mx-auto scroll" tile>
<v-card class="mx-auto scroll" tile>

<v-toolbar flat>
<v-subheader>Episodes</v-subheader>
<v-spacer></v-spacer>
<v-btn :color="previewColor"
@click="preview = !preview"
class="mx-1" icon>
<v-icon>mdi-set-center-right</v-icon>
</v-btn>
<v-btn class="mx-1" @click="$store.commit('setSearchRequest', true)"
:loading="$store.state.loadingEpisodes"
icon>
<v-icon>mdi-magnify</v-icon>
</v-btn>
<v-chip class="mx-1" :color="chipColor" outlined>{{episodes.length}}</v-chip>
</v-toolbar>
<v-toolbar flat>
<v-subheader>Episodes</v-subheader>
<v-spacer></v-spacer>
<v-btn :color="previewColor"
@click="preview = !preview"
class="mx-1" icon>
<v-icon>mdi-set-center-right</v-icon>
</v-btn>
<v-btn class="mx-1" @click="$store.commit('setSearchRequest', true)"
:loading="$store.state.loadingEpisodes"
icon>
<v-icon>mdi-magnify</v-icon>
</v-btn>
<v-chip class="mx-1" :color="chipColor" outlined>{{episodes.length}}</v-chip>
</v-toolbar>

<v-divider></v-divider>
<v-divider></v-divider>

<v-list shaped :dense="$store.state.denseLists">
<v-list-item v-for="(it, i) in episodes"
:key="it.id"
class="pr-0 my-1">
<v-list shaped :dense="$store.state.denseLists">
<v-list-item v-for="(it, i) in episodes"
:key="it.id"
class="pr-0 my-1">

<v-list-item-action class="mr-2 my-0">
<v-btn icon @click="removeElement(it.id)">
<v-icon>mdi-close</v-icon>
</v-btn>
</v-list-item-action>
<v-list-item-action class="mr-2 my-0">
<v-btn icon @click="removeElement(it.id)">
<v-icon>mdi-close</v-icon>
</v-btn>
</v-list-item-action>

<v-divider vertical></v-divider>
<v-divider vertical></v-divider>

<v-list-item-group v-model="selectedItem" color="primary" style="width: 100%">
<v-list-item :value="i">
<template v-slot:default="{active}">
<v-list-item-content>
<span v-if="preview">{{formatEpisodeName(it)}}</span>
<span v-else>{{it.episodeNumber}}. {{it.episodeTitle}}</span>
<span class="grey--text caption" v-if="active">aired on {{it.date}}</span>
</v-list-item-content>
</template>
</v-list-item>
</v-list-item-group>
<v-list-item-group v-model="selectedItem" color="primary" style="width: 100%">
<v-list-item :value="i">
<template v-slot:default="{active}">
<v-list-item-content>
<span v-if="preview">{{formatEpisodeName(it)}}</span>
<span v-else>{{it.episodeNumber}}. {{it.episodeTitle}}</span>
<span class="grey--text caption" v-if="active">aired on {{it.date}}</span>
</v-list-item-content>
</template>
</v-list-item>
</v-list-item-group>

</v-list-item>
</v-list>
</v-list-item>
</v-list>

<v-card-actions>
<div class="flex-grow-1"></div>
<v-btn :disabled="episodes.length === 0"
@click="clearEpisodes"
text>
clear
</v-btn>
</v-card-actions>
</v-card>
<v-card-actions>
<div class="flex-grow-1"></div>
<v-btn :disabled="episodes.length === 0"
@click="clearEpisodes"
text>
clear
</v-btn>
</v-card-actions>
</v-card>
</template>

<script>
Expand Down Expand Up @@ -114,7 +114,7 @@
this.episodes = this.episodes.filter(it => it.id !== id)
},
formatEpisodeName: function (episode) {
return EpisodeService.formatEpisodeName(episode, this.$store.state.nameFormat)
return EpisodeService.formatEpisodeName(episode, this.$store.state.nameFormat, this.$store.state.blacklist)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/FileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
},
rename: function () {
this.renamingInProgress = true;
const names = this.$store.state.episodes.map(it => EpisodeService.formatEpisodeName(it, this.$store.state.nameFormat))
const names = this.$store.state.episodes.map(it => EpisodeService.formatEpisodeName(it, this.$store.state.nameFormat, this.$store.state.blacklist))
FileService.renameFiles(this.$store.state.files, names)
.then(newFiles => {
this.files = newFiles;
Expand Down
139 changes: 81 additions & 58 deletions src/components/SettingsPopup.vue
Original file line number Diff line number Diff line change
@@ -1,69 +1,76 @@
<template>
<v-dialog v-model="openSettings" width="75%" max-width="75%">
<v-card>
<v-card-title class="headline grey lighten-2" primary-title>
Settings
</v-card-title>
<v-container>
<span class="title">Language</span>
<v-row>
<v-col cols="4">
<v-combobox v-model="languageSelection"
:items="languages"
item-text="name"
item-value="code"
label="Select"
persistent-hint
allow-overflow
single-line></v-combobox>
</v-col>
</v-row>
<span class="title">Renaming Format</span>
<v-row>
<v-col cols="12">
<v-text-field v-model="format"
:label="helpEpisodeRenamed"></v-text-field>
</v-col>
</v-row>
<v-row>
<v-col cols="12">
Examples
<v-list dense>
<v-list-item-group v-model="format" color="primary">
<v-dialog v-model="openSettings" width="75%" max-width="75%">
<v-card>
<v-card-title class="headline grey lighten-2" primary-title>
Settings
</v-card-title>
<v-container>
<span class="title">Language</span>
<v-row>
<v-col cols="4">
<v-combobox v-model="languageSelection"
:items="languages"
item-text="name"
item-value="code"
label="Select"
persistent-hint
allow-overflow
single-line></v-combobox>
</v-col>
</v-row>
<span class="title">Renaming Format</span>
<v-row>
<v-col cols="12">
<v-text-field v-model="format"
:label="helpEpisodeRenamed"></v-text-field>
</v-col>
</v-row>
<v-row>
<v-col cols="12">
Examples
<v-list dense>
<v-list-item-group v-model="format" color="primary">

<v-list-item v-for="it in examples"
:key="it.format"
:value="it.format"
@click="format = it.format">
<template v-slot:default="{active}">
<v-list-item v-for="it in examples"
:key="it.format"
:value="it.format"
@click="format = it.format">
<template v-slot:default="{active}">

<v-list-item-content>
<v-list-item-title>{{it.renamed}}</v-list-item-title>
<v-list-item-subtitle>{{it.format}}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-content>
<v-list-item-title>{{it.renamed}}</v-list-item-title>
<v-list-item-subtitle>{{it.format}}</v-list-item-subtitle>
</v-list-item-content>

</template>
</v-list-item>
</template>
</v-list-item>

</v-list-item-group>
</v-list>
</v-col>
</v-row>
</v-container>
</v-list-item-group>
</v-list>
</v-col>
</v-row>

<v-card-actions>
<div class="flex-grow-1"></div>
<v-btn color="primary" @click="$store.commit('setSettings', false)" text>
Close
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<span class="title">Character Blacklist</span>
<v-row>
<v-col cols="12">
<v-text-field v-model="blacklist"
label="Comma separated list of characters that are removed from the file name"></v-text-field>
</v-col>
</v-row>
</v-container>

<v-card-actions>
<div class="flex-grow-1"></div>
<v-btn color="primary" @click="$store.commit('setSettings', false)" text>
Close
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script>
import EpisodeService from "../assets/EpisodeService";
export default {
name: "SettingsPopup",
Expand All @@ -84,6 +91,14 @@
"seriesTitle": "Game of Thrones",
"date": "2011-4-17",
},
helpEpisodeBroken: {
"id": 1,
"episodeTitle": "Winter Is Coming?",
"episodeNumber": 1,
"seasonNumber": 1,
"seriesTitle": "Game of Thrones",
"date": "2011-4-17",
},
languages: [
{name: "English", code: "en"},
{name: "German", code: "de"},
Expand All @@ -109,8 +124,16 @@
this.$store.commit("setNameFormat", value)
}
},
blacklist: {
get: function () {
return this.$store.state.blacklist
},
set: function (value) {
this.$store.commit("setBlacklist", value)
}
},
helpEpisodeRenamed: function () {
return EpisodeService.formatEpisodeName(this.helpEpisode, this.format)
return EpisodeService.formatEpisodeName(this.helpEpisode, this.format, this.$store.state.blacklist)
},
languageSelection: {
get: function () {
Expand All @@ -124,7 +147,7 @@
return this.formatExamples.map(it => {
return {
format: it,
renamed: EpisodeService.formatEpisodeName(this.helpEpisode, it)
renamed: EpisodeService.formatEpisodeName(this.helpEpisode, it, this.$store.state.blacklist)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@click="$store.commit('setSettings', true)"
:color="settings"
icon>
<v-icon>mdi-settings</v-icon>
<v-icon>mdi-cog</v-icon>
</v-btn>
</v-app-bar>
</template>
Expand Down
3 changes: 2 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default new Vuex.Store({
language: {name: "English", code: "en"},
notify: false,
notificationText: null,
notificationColor: null
notificationColor: null,
blacklist: ['&', '$', '@', ':', ';', '?', ',', '%', '\\', '/', '<', '>']
},
mutations: {
setSearchRequest(state, val) {
Expand Down

0 comments on commit 19d5e37

Please sign in to comment.