Created
May 25, 2019 04:08
-
-
Save bluelovers/874860dbe18a94f37a71c0e5de170490 to your computer and use it in GitHub Desktop.
createPotplayerList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by user on 2019/5/25. | |
*/ | |
import { globbyASync, IOptionsWithReturnGlobList, getOptions } from 'node-novel-globby/g'; | |
import Bluebird = require('bluebird'); | |
import { sortTree } from 'node-novel-globby/lib/glob-sort'; | |
import path = require('path'); | |
import fs = require('fs-extra'); | |
const exts = [ | |
'.avi', | |
'.flv', | |
'.mkv', | |
'.mp4', | |
'.MP4', | |
'.mpg', | |
'.rmvb', | |
'.webm', | |
]; | |
export function extsToPattern(ext = exts) | |
{ | |
return ext.map(v => '**/*' + v) | |
} | |
export function globMergePathAsync(patterns: string[], paths: string[], options?: IOptionsWithReturnGlobList) | |
{ | |
({ patterns, options } = getOptions(patterns, options || {})); | |
return Bluebird.resolve(paths) | |
.map(async function (cwd) | |
{ | |
return await globbyASync(patterns, { | |
...options, | |
absolute: false, | |
cwd, | |
}) | |
//.then(ls => sortTree(ls, null, options)) | |
.then(function (ls) | |
{ | |
return ls.reduce(function (a, b) | |
{ | |
let file = path.join(cwd, b); | |
const ob = b; | |
let i = 1; | |
while (b in a) | |
{ | |
b = ob + i++; | |
} | |
a[b] = file; | |
return a; | |
}, {} as Record<string, string>) | |
}) | |
}) | |
.reduce(async function (list, data) | |
{ | |
return Object.keys(data) | |
.reduce(function (a, b) | |
{ | |
const ob = b; | |
let i = 1; | |
while (b in a) | |
{ | |
b = ob + i++; | |
} | |
a[b] = data[b]; | |
return a | |
}, list); | |
}, [] as string[]) | |
.then(async (data) => { | |
return sortTree(Object.keys(data)) | |
.reduce(function (a, b) | |
{ | |
a.push(data[b]) | |
return a; | |
}, [] as string[]) | |
; | |
}) | |
; | |
} | |
export function createPotplayerList(paths: string[], file: string) | |
{ | |
return globMergePathAsync(extsToPattern(), paths) | |
.map((value, i) => { | |
let idx = i + 1; | |
return `${idx}*file*${value}\n${idx}*played*0`; | |
}) | |
.then(function (ls) | |
{ | |
return `DAUMPLAYLIST\nplayname=\ntopindex=0\nsaveplaypos=0\n${ls.join('\n')}`; | |
}) | |
.then(data => | |
{ | |
console.log(file); | |
return fs.outputFile(file, data) | |
}) | |
; | |
} | |
createPotplayerList([ | |
'W:\\Backup\\ \\BaiduYunDownload', | |
'W:\\Backup\\ \\迅雷下載', | |
], 'W:\\Backup\\ \\456.dpl'); | |
createPotplayerList([ | |
'D:\\Users\\Downloads\\Videos', | |
], 'D:\\Users\\Downloads\\Videos\\456.dpl'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment