Skip to content

Commit

Permalink
fix typo & sanitize video names on win32 (snobu#205)
Browse files Browse the repository at this point in the history
* fix typo & sanitize video names on win32
* add warning for invalid path
  • Loading branch information
beppe9000 authored Aug 15, 2020
1 parent 5b62c50 commit a9f8b02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/CommandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const argv: any = yargs.options({
},
closedCaptions: {
alias: 'cc',
describe: 'Check if closed captions are aviable and let the user choose which one to download (will not ask if only one aviable)',
describe: 'Check if closed captions are available and let the user choose which one to download (will not ask if only one available)',
type: 'boolean',
default: false,
demandOption: false
Expand Down Expand Up @@ -183,8 +183,8 @@ function isOutputTemplateValid(argv: any): boolean {
while (match) {
if (!templateElements.includes(match[1])) {
logger.error(
`'${match[0]}' is not aviable as a template element \n` +
`Aviable templates elements: '${templateElements.join("', '")}' \n`,
`'${match[0]}' is not available as a template element \n` +
`Available templates elements: '${templateElements.join("', '")}' \n`,
{ fatal: true }
);

Expand Down
10 changes: 7 additions & 3 deletions src/VideoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ function publishedTimeToString(date: string): string {
const minutes: string = dateJs.getMinutes().toString();
const seconds: string = dateJs.getSeconds().toString();

return `${hours}:${minutes}:${seconds}`;
return `${hours}.${minutes}.${seconds}`;
}


function isoDurationToString(time: string): string {
const duration: Duration = parseDuration(time);

return `${duration.hours ?? '00'}:${duration.minutes ?? '00'}:${duration.seconds?.toFixed(0) ?? '00'}`;
return `${duration.hours ?? '00'}.${duration.minutes ?? '00'}.${duration.seconds?.toFixed(0) ?? '00'}`;
}


Expand Down Expand Up @@ -152,8 +152,12 @@ export function createUniquePath(videos: Array<Video>, outDirs: Array<string>, t
finalTitle = `${title}.${++i}`;
}

const finalFileName = `${finalTitle}.${format}`;
const cleanFileName = sanitizeWindowsName(finalFileName, { replacement: "_" });
if (finalFileName !== cleanFileName) logger.warn(`Not a valid Windows file name: "${finalFileName}".\nReplacing invalid characters with underscores to preserve cross-platform consistency.`);

video.outPath = path.join(outDirs[index], finalFileName);

video.outPath = path.join(outDirs[index], finalTitle + '.' + format);
});

return videos;
Expand Down

0 comments on commit a9f8b02

Please sign in to comment.