-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from skiptirengu/development
Complete rewrite from scratch
- Loading branch information
Showing
20 changed files
with
5,995 additions
and
621 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
env: { | ||
node: true | ||
}, | ||
parserOptions: { | ||
sourceType: 'module' | ||
}, | ||
extends: 'standard', | ||
'rules': { | ||
// allow paren-less arrow functions | ||
'arrow-parens': 0, | ||
// allow async-await | ||
'generator-star-spacing': 0, | ||
// 2 lines | ||
'indent': ['error', 2], | ||
// require space on single line objects | ||
'object-curly-spacing': ['error', 'always'], | ||
// and arrays | ||
'array-bracket-spacing': ['error', 'always'] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,7 @@ node_modules/ | |
*.txt | ||
tmp/ | ||
.vscode/ | ||
*.jpg | ||
*.jpg | ||
.nyc_output | ||
out/ | ||
docs |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: node_js | ||
sudo: false | ||
|
||
node_js: | ||
- "6" | ||
- "7" | ||
- "8" | ||
- "9" | ||
- "10" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
'use strict' | ||
|
||
const MediaSplit = require('./../index.js') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const progress = require('cli-progress') | ||
|
||
const log = console.log | ||
const { green, cyan, red } = require('chalk') | ||
|
||
class Command { | ||
constructor (argv) { | ||
this.argv = argv | ||
} | ||
|
||
readTemplateFile () { | ||
try { | ||
const content = fs.readFileSync(this.argv.template, { enconding: 'utf-8' }) | ||
return content.toString().trim().split('\n') | ||
} catch (e) { | ||
return null | ||
} | ||
} | ||
|
||
parseMetadataInfo () { | ||
const meta = new Map() | ||
for (const data of this.argv.metadata) { | ||
const split = data.split('=') | ||
if (!split || split.length !== 2) { | ||
return null | ||
} else { | ||
meta.set(split[ 0 ], split[ 1 ]) | ||
} | ||
} | ||
return meta | ||
} | ||
|
||
createDefaultProgressBar (opts = {}) { | ||
const options = Object.assign({ | ||
clearOnComplete: true, | ||
stopOnComplete: true | ||
}, opts) | ||
return new progress.Bar(options, progress.Presets.shades_classic) | ||
} | ||
|
||
formatFiles (sections) { | ||
return ' - ' + sections.map((section) => cyan(section)).join(', ') | ||
} | ||
|
||
friendlyByteSize (size) { | ||
const megaByte = (size / 1024 / 1024).toFixed(1) | ||
return `${megaByte}MB` | ||
} | ||
|
||
run () { | ||
const sections = this.readTemplateFile() | ||
if (sections === null) { | ||
log(red(`Unable to open template file ${this.argv.template}`)) | ||
return | ||
} | ||
|
||
const metadata = this.parseMetadataInfo() | ||
if (metadata === null) { | ||
log(red('Wrong metadata input!')) | ||
return | ||
} | ||
|
||
const split = new MediaSplit({ | ||
concurrency: this.argv.concurrency, | ||
input: this.argv.input, | ||
sections: sections, | ||
metadata: metadata, | ||
output: this.argv.output || '.', | ||
format: this.argv.format, | ||
audioonly: this.argv.audioonly | ||
}) | ||
|
||
let downloadBar | ||
let splitBar | ||
let currentSections = [] | ||
|
||
split.on('data', (sections) => { | ||
splitBar = this.createDefaultProgressBar({ | ||
format: 'Progress [{bar}] {percentage}% | {value}/{total} | Tracks{files}', | ||
stopOnComplete: false | ||
}) | ||
splitBar.start(sections.length, 0, { files: '' }) | ||
}) | ||
|
||
split.on('beforeSplit', (info) => { | ||
currentSections.push(info.name) | ||
currentSections.sort() | ||
splitBar.update(splitBar.value, { files: this.formatFiles(currentSections) }) | ||
}) | ||
|
||
split.on('afterSplit', (info) => { | ||
currentSections = currentSections.filter((section) => section !== info.name) | ||
splitBar.increment(1, { files: this.formatFiles(currentSections) }) | ||
}) | ||
|
||
split.once('url', (file, info, cached) => { | ||
downloadBar = this.createDefaultProgressBar({ | ||
format: 'Download [{bar}] {percentage}% | {friendlyValue} / {friendlyTotal}' | ||
}) | ||
if (cached) { | ||
log(green('Found cached video on ') + cyan(path.resolve(file))) | ||
} else { | ||
log(green('Found video! saving to ') + cyan(path.resolve(file))) | ||
} | ||
}) | ||
|
||
split.once('downloadLength', (total) => { | ||
downloadBar.start(total, 0, { | ||
friendlyValue: this.friendlyByteSize(0), | ||
friendlyTotal: this.friendlyByteSize(total) | ||
}) | ||
}) | ||
|
||
split.on('downloadProgress', (chunk) => { | ||
const value = downloadBar.value + chunk | ||
downloadBar.update(value, { friendlyValue: this.friendlyByteSize(value) }) | ||
}) | ||
|
||
split.parse().then(() => { | ||
splitBar.stop() | ||
log(green('Successfully parsed all files!')) | ||
}).catch((err) => { | ||
if (splitBar) splitBar.stop() | ||
if (downloadBar) downloadBar.stop() | ||
log(red(err.message)) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = Command |
Oops, something went wrong.