mirror of
https://github.com/snobu/destreamer.git
synced 2026-02-24 23:38:23 +00:00
Fixes and clean up (#51)
* Simplify main * Fix init * Cleaner output for the end user * Fix extractVideoGuid after sync with dev * TokenCache: Make variable private nit: switch to import * Add option to disable video thumbnails * Create a unique file name to avoid overwrite * Remove os dependency * Reimplement simulate * Update README Co-authored-by: @kylon Co-authored-by: @snobu
This commit is contained in:
13
utils.ts
13
utils.ts
@@ -1,6 +1,7 @@
|
||||
import { execSync } from 'child_process';
|
||||
import colors from 'colors';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
function sanitizeUrls(urls: string[]) {
|
||||
const rex = new RegExp(/(?:https:\/\/)?.*\/video\/[a-z0-9]{8}-(?:[a-z0-9]{4}\-){3}[a-z0-9]{12}$/, 'i');
|
||||
@@ -13,7 +14,7 @@ function sanitizeUrls(urls: string[]) {
|
||||
|
||||
if (!rex.test(url)) {
|
||||
if (url !== '')
|
||||
console.warn(colors.yellow('Invalid URL at line ' + (i+1) + ', skip..\n'));
|
||||
console.warn(colors.yellow('Invalid URL at line ' + (i+1) + ', skip..'));
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -57,3 +58,13 @@ export function checkRequirements() {
|
||||
process.exit(22);
|
||||
}
|
||||
}
|
||||
|
||||
export function makeUniqueTitle(title: string, outDir: string) {
|
||||
let ntitle = title;
|
||||
let k = 0;
|
||||
|
||||
while (fs.existsSync(outDir + path.sep + ntitle + '.mp4'))
|
||||
ntitle = title + ' - ' + (++k).toString();
|
||||
|
||||
return ntitle;
|
||||
}
|
||||
Reference in New Issue
Block a user