Fix special character handling (#49)
* Update dependencies * Allow more special characters in file name * Remove slashes from episode names A slash in the episode name (resp. file name) would cause an unexpected directory to be created. * Use same regex for episode names
This commit is contained in:
parent
9001a8e252
commit
4596e96b4e
4 changed files with 747 additions and 862 deletions
1574
package-lock.json
generated
1574
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -117,6 +117,11 @@ class App extends Component {
|
|||
this.setState({ loading: true })
|
||||
try {
|
||||
const seasons = await getTvShow(tvShow)
|
||||
for (const season of seasons) {
|
||||
for (const episode of season.episodes) {
|
||||
episode.name = episode.name.replace(/\s*[\/\\]\s*/g, ' ')
|
||||
}
|
||||
}
|
||||
this.setState((prevState) => {
|
||||
let nextState = {
|
||||
seasons,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,12 @@ import { withTranslation } from 'react-i18next'
|
|||
import Button from './button'
|
||||
import Link from './link'
|
||||
import { flatten } from '../util/array'
|
||||
import { getFileName, getDir, getFileExtension } from '../util/format'
|
||||
import {
|
||||
getFileName,
|
||||
getDir,
|
||||
getFileExtension,
|
||||
INVALID_CHARS,
|
||||
} from '../util/format'
|
||||
|
||||
import CrossIcon from '../icons/cross.svg'
|
||||
import FolderIcon from '../icons/folder.svg'
|
||||
|
|
@ -21,7 +26,6 @@ import KoFiIcon from '../icons/ko-fi.svg'
|
|||
const stat = util.promisify(fs.stat)
|
||||
const mkdir = util.promisify(fs.mkdir)
|
||||
const rename = util.promisify(fs.rename)
|
||||
const INVALID_CHARS = /[#%&\{\}<>\*\?$!'":@]/g
|
||||
|
||||
class FileRename extends Component {
|
||||
constructor(props) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ export function getFileExtension(fileName) {
|
|||
return fileName.split('.').last()
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/31976060
|
||||
// (back-)slashes are removed from episode names directly
|
||||
export const INVALID_CHARS = /[<>:"\|?*]/g
|
||||
|
||||
export function formatEpisodeName(episode, tvShow, template) {
|
||||
return (template || 'missing template')
|
||||
.replace(/\{show_name\}/g, tvShow.name)
|
||||
|
|
@ -23,7 +27,7 @@ export function formatEpisodeName(episode, tvShow, template) {
|
|||
.replace(/\{season_no\}/g, leftPad(episode.season_number, 2, 0))
|
||||
.replace(/\{episode_no\}/g, leftPad(episode.episode_number, 2, 0))
|
||||
.replace(/\{episode_name\}/g, episode.name || 'missing translation')
|
||||
.replace(/[#%&\{\}<>\*\?$!'":@]/g, '')
|
||||
.replace(INVALID_CHARS, '')
|
||||
.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue