Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sugiruu/media-split
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.0.0
Choose a base ref
...
head repository: sugiruu/media-split
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Feb 1, 2019

  1. Update README.md

    Thiago authored Feb 1, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    8fd203c View commit details

Commits on Feb 13, 2019

  1. Update README.md

    Thiago authored Feb 13, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    5da5ef4 View commit details

Commits on May 23, 2019

  1. Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    764d737 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    154143a View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    50779c3 View commit details

Commits on Jun 6, 2019

  1. Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    c875adc View commit details

Commits on Jun 21, 2019

  1. Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    dc12729 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    e899ced View commit details

Commits on Jun 22, 2019

  1. Option to choose download quality

    * Changed default download quality due to Youtube rate limiting the type with only audio
    * Added -q option to command line
    * Added 'quality' to MediaSplit options
    sugiruu committed Jun 22, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    1f72438 View commit details
  2. Update README [ci skip]

    Thiago authored Jun 22, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    8761577 View commit details

Commits on Jul 12, 2019

  1. Bump lodash from 4.17.11 to 4.17.14

    Bumps [lodash](https://github.com/lodash/lodash) from 4.17.11 to 4.17.14.
    - [Release notes](https://github.com/lodash/lodash/releases)
    - [Commits](lodash/lodash@4.17.11...4.17.14)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Jul 12, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    3ed142c View commit details

Commits on Jul 14, 2019

  1. Merge pull request #5 from skiptirengu/dependabot/npm_and_yarn/lodash…

    …-4.17.14
    
    Bump lodash from 4.17.11 to 4.17.14
    Thiago authored Jul 14, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    5d91533 View commit details

Commits on Sep 12, 2019

  1. Bump eslint-utils from 1.3.1 to 1.4.2

    Bumps [eslint-utils](https://github.com/mysticatea/eslint-utils) from 1.3.1 to 1.4.2.
    - [Release notes](https://github.com/mysticatea/eslint-utils/releases)
    - [Commits](mysticatea/eslint-utils@v1.3.1...v1.4.2)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and Thiago committed Sep 12, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    8cebc96 View commit details

Commits on Feb 10, 2020

  1. Update packages

    - Use yarn instead of npm for package management
    - Apply eslint
    sugiruu committed Feb 10, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    311cd26 View commit details
  2. Fix travis

    sugiruu committed Feb 10, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    6e33289 View commit details
  3. Fix travis build

    - Remove deprecated versions from build matrix
    - Fix async tests
    sugiruu committed Feb 10, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    7268450 View commit details
  4. Fix integration test

    sugiruu committed Feb 10, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    77967f7 View commit details

Commits on Mar 13, 2020

  1. Bump acorn from 7.1.0 to 7.1.1

    Bumps [acorn](https://github.com/acornjs/acorn) from 7.1.0 to 7.1.1.
    - [Release notes](https://github.com/acornjs/acorn/releases)
    - [Commits](acornjs/acorn@7.1.0...7.1.1)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Mar 13, 2020
    Copy the full SHA
    5dce56e View commit details

Commits on Mar 19, 2020

  1. Merge pull request #8 from skiptirengu/dependabot/npm_and_yarn/acorn-…

    …7.1.1
    
    Bump acorn from 7.1.0 to 7.1.1
    Thiago authored Mar 19, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    09e7fb0 View commit details

Commits on Apr 4, 2020

  1. update deps

    sugiruu committed Apr 4, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    c864d1c View commit details
  2. Create nodejs.yml

    Thiago authored Apr 4, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    3294604 View commit details
  3. Update README.md

    Thiago authored Apr 4, 2020
    Copy the full SHA
    57de5d3 View commit details

Commits on Jun 11, 2020

  1. update deps

    sugiruu committed Jun 11, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a337a9a View commit details
  2. bump version

    sugiruu committed Jun 11, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    be4687c View commit details

Commits on Jul 22, 2020

  1. Bump lodash from 4.17.15 to 4.17.19

    Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
    - [Release notes](https://github.com/lodash/lodash/releases)
    - [Commits](lodash/lodash@4.17.15...4.17.19)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Jul 22, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    3f1bcd0 View commit details
  2. Merge pull request #10 from skiptirengu/dependabot/npm_and_yarn/lodas…

    …h-4.17.19
    
    Bump lodash from 4.17.15 to 4.17.19
    Thiago authored Jul 22, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    91bf66f View commit details

Commits on Sep 4, 2020

  1. update packages

    sugiruu committed Sep 4, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f19b157 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    6bd46a2 View commit details
  3. bump version

    sugiruu committed Sep 4, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    2976397 View commit details

Commits on Feb 16, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    lobis Luis Antonio Obis Aparicio
    Copy the full SHA
    ade1699 View commit details
  2. Replace deprecated package 'ffmpeg-binaries' with dropin replacement …

    …'ffmpeg-static'; update 'ytdl-core'
    sergiu-omg committed Feb 16, 2021
    Copy the full SHA
    9f4668f View commit details
  3. Merge pull request #12 from sergiu-omg/replace-deprecated-package-ffm…

    …peg-binaries
    
    Replaces deprecated package 'ffmpeg-binaries' with drop-in replacement 'ffmpeg-static'
    Thiago authored Feb 16, 2021
    Copy the full SHA
    7ab67f3 View commit details

Commits on Feb 17, 2021

  1. prepare for release

    sugiruu committed Feb 17, 2021
    Copy the full SHA
    472f42b View commit details

Commits on May 10, 2021

  1. chore: update packages

    sugiruu committed May 10, 2021
    Copy the full SHA
    13ff5b7 View commit details
  2. chore: downgrade yargs

    sugiruu committed May 10, 2021
    Copy the full SHA
    72efb54 View commit details
  3. Copy the full SHA
    1e33978 View commit details
  4. chore: bump version

    sugiruu committed May 10, 2021
    Copy the full SHA
    8597e97 View commit details

Commits on Jan 4, 2022

  1. update deps

    sugiruu committed Jan 4, 2022
    Copy the full SHA
    aa88992 View commit details
  2. Update nodejs.yml

    Thiago authored Jan 4, 2022
    Copy the full SHA
    babe33a View commit details
  3. fix vulnerabilities

    sugiruu committed Jan 4, 2022
    Copy the full SHA
    fbf8312 View commit details
  4. Copy the full SHA
    a294dc5 View commit details
  5. Update nodejs.yml

    Thiago authored Jan 4, 2022
    Copy the full SHA
    bc790b5 View commit details

Commits on Jan 10, 2022

  1. update packages

    sugiruu committed Jan 10, 2022
    Copy the full SHA
    2a909e9 View commit details
  2. add ffmpeg arguments

    sugiruu committed Jan 10, 2022
    Copy the full SHA
    21f5b07 View commit details
  3. bump

    sugiruu committed Jan 10, 2022
    Copy the full SHA
    e8717d1 View commit details
  4. Copy the full SHA
    2bbe6e9 View commit details
  5. update docs

    sugiruu committed Jan 10, 2022
    Copy the full SHA
    80ef1da View commit details
Showing with 3,355 additions and 5,212 deletions.
  1. +2 −1 .eslintrc.js
  2. +30 −0 .github/workflows/nodejs.yml
  3. +2 −3 .travis.yml
  4. +17 −3 README.md
  5. +12 −4 cli/Command.js
  6. +13 −1 cli/index.js
  7. +6 −6 lib/FFmpeg.js
  8. +40 −12 lib/MediaSplit.js
  9. +0 −5,114 package-lock.json
  10. +25 −23 package.json
  11. +13 −0 spec/Command.spec.js
  12. +7 −7 spec/FFmpeg.spec.js
  13. +36 −38 spec/MediaSplit.spec.js
  14. +3,152 −0 yarn.lock
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ module.exports = {
// require space on single line objects
'object-curly-spacing': ['error', 'always'],
// and arrays
'array-bracket-spacing': ['error', 'always']
'array-bracket-spacing': ['error', 'always'],
'computed-property-spacing': ['error', 'always']
}
}
30 changes: 30 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn install --frozen-lockfile
- run: yarn test
env:
CI: true
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@ language: node_js
sudo: false

node_js:
- "6"
- "7"
- "8"
- "9"
- "10"
- "11"
- "12"
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# Media-split

[![Actions Status](https://github.com/skiptirengu/media-split/workflows/Node.js%20CI/badge.svg)](https://github.com/skiptirengu/media-split/actions)

Split audio (and video) files

## Install

Make sure you have [ffmpeg](https://ffmpeg.org/) installed and added to your path then run:

```bash
npm install [-g] mp3-split
npm install [-g] media-split
```

If you don't have ffmpeg installed, you can install [this package](https://www.npmjs.com/package/ffmpeg-binaries) which
If you don't have ffmpeg installed, you can install [this](https://www.npmjs.com/package/ffmpeg-static) or [this](https://www.npmjs.com/package/@ffmpeg-installer/ffmpeg) package which
comes with a bundled ffmpeg, and media-split will automatically detect and use it.

```bash
npm install [-g] ffmpeg-binaries
npm install [-g] ffmpeg-static
```
or
```bash
npm install [-g] @ffmpeg-installer/ffmpeg
```

## CLI
@@ -42,6 +48,11 @@ A template file usually looks like this:
[15:37] wish you still felt this way [ sophie meiers x 90sFlav ]
```

## Known issues

Sometimes, when downloading videos from YouTube, media-split can fail with the error message "Too many redirects".
This is caused by a third party library and is already being tracked [here](https://github.com/fent/node-ytdl-core/issues/212).

## Library

You can also use media-split as a library.
@@ -72,6 +83,9 @@ split.parse().then((sections) => {
| options.output | <code>string</code> | Output path |
| options.format | <code>string</code> | Output format (mp3, m4a, flac, etc) |
| options.audioonly | <code>boolean</code> | Force download only audio files when using a url as input |
| options.quality | <code>string</code> | The download quality when downloading from YouTube (highest/lowest/highestaudio/lowestaudio/highestvideo/lowestvideo) |
| options.inputParams | <code>Array.&lt;string&gt;</code> | Additional input parameters for FFMpeg
| options.outputParams | <code>Array.&lt;string&gt;</code> | Additional output parameters for FFMpeg

### MediaSplit.parse() ⇒ <code>Promise.&lt;Array.&lt;object&gt;&gt;</code>
Split the media
16 changes: 12 additions & 4 deletions cli/Command.js
Original file line number Diff line number Diff line change
@@ -13,11 +13,16 @@ class Command {
this.argv = argv
}

getSections () {
return this.argv.sections || this.readTemplateFile()
}

readTemplateFile () {
try {
const content = fs.readFileSync(this.argv.template, { enconding: 'utf-8' })
return content.toString().trim().split('\n')
} catch (e) {
log(red(`Unable to open template file ${this.argv.template}`))
return null
}
}
@@ -53,9 +58,9 @@ class Command {
}

run () {
const sections = this.readTemplateFile()
if (sections === null) {
log(red(`Unable to open template file ${this.argv.template}`))
const sections = this.getSections()
if (!sections) {
log(red('No sections found. Unable to continue'))
return
}

@@ -72,7 +77,10 @@ class Command {
metadata: metadata,
output: this.argv.output || '.',
format: this.argv.format,
audioonly: this.argv.audioonly
audioonly: this.argv.audioonly,
quality: this.argv.quality,
inputParams: this.argv.inputParam,
outputParams: this.argv.outputParam
})

let downloadBar
14 changes: 13 additions & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
@@ -7,27 +7,39 @@ const Command = require('./Command.js')

const argv = yargs
.usage('Usage: $0 <command> [options]')
.example('$0 -i myaudio.mp3 -t parse.txt -o /home/Music -m title=Test')
.example('$0 -i myvideo.avi -f mp4 -t parse.txt -o /home/Videos -m title=Test -p:o "\'-vf scale=320:-1\'"')
.alias('a', 'audioonly')
.alias('o', 'output')
.alias('t', 'template')
.alias('i', 'input')
.alias('m', 'metadata')
.alias('c', 'concurrency')
.alias('f', 'format')
.alias('s', 'sections')
.alias('q', 'quality')
.alias('p:i', 'inputParam')
.alias('p:o', 'outputParam')
.describe('o', 'Output path')
.describe('t', 'Template text file')
.describe('i', 'Input file or YouTube URL')
.describe('m', 'Output file metadata with "key=value" format')
.describe('c', 'Max concurrent tasks')
.describe('f', 'Output format (mp3, m4a, flac, etc)')
.describe('a', 'Force download only audio files when using a url as input')
.describe('s', 'Sections to split')
.describe('q', 'Download quality (highest/lowest/highestaudio/lowestaudio/highestvideo/lowestvideo)')
.describe('p:i', 'Additional FFMpeg input parameters')
.describe('p:o', 'Additional FFMpeg output parameters')
.default('f', 'mp3')
.default('t', 'templ.txt')
.default('i', 'input.mp3')
.default('a', false)
.default('c', 3)
.default('q', 'highest')
.array('m').default('m', [])
.array('p:i').default('p:i', [])
.array('p:o').default('p:o', [])
.array('s')
.help('h').alias('h', 'help')
.argv

12 changes: 6 additions & 6 deletions lib/FFmpeg.js
Original file line number Diff line number Diff line change
@@ -11,24 +11,24 @@ function global (lib) {
const libs = {
// local installation
'@ffmpeg-installer/ffmpeg': (lib) => require(lib).path,
'ffmpeg-binaries': (lib) => require(lib),
'ffmpeg': (lib) => {
let proc = spawnSync(lib)
'ffmpeg-static': (lib) => require(lib),
ffmpeg: (lib) => {
const proc = spawnSync(lib)
if (proc.error instanceof Error) {
throw proc.error
} else {
return lib
}
},
[global('@ffmpeg-installer/ffmpeg')]: (lib) => require(lib).path,
[global('ffmpeg-binaries')]: (lib) => require(lib)
[ global('@ffmpeg-installer/ffmpeg') ]: (lib) => require(lib).path,
[ global('ffmpeg-static') ]: (lib) => require(lib)
}

module.exports = null

for (const libName of Object.keys(libs)) {
try {
module.exports = libs[libName](libName)
module.exports = libs[ libName ](libName)
break
} catch (e) {
// eslint-disable-line no-empty
52 changes: 40 additions & 12 deletions lib/MediaSplit.js
Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@ class MediaSplit extends EventEmitter {
* @param {string} options.output - Output path
* @param {string} options.format - Output format (mp3, m4a, flac, etc)
* @param {boolean} options.audioonly - Force download only audio files when using a url as input
* @param {string} options.quality - Download quality
* @param {string[]} options.inputParams - FFMpeg additional input parameters
* @param {string[]} options.outputParams - FFMpeg additional output parameters
* @return MediaSplit
*/
constructor (options = {}) {
@@ -41,10 +44,21 @@ class MediaSplit extends EventEmitter {
sections: [],
output: '.',
format: 'mp3',
audioonly: false
audioonly: false,
quality: 'highest',
inputParams: [],
outputParams: []
}

this._options = Object.assign(defaults, options)
this._options = Object.assign(
defaults,
options,
{
inputParams: this._sanitizeParams(options.inputParams),
outputParams: this._sanitizeParams(options.outputParams)
}
)

this._inputFile = ''
this._downloadOptions = {}
}
@@ -71,7 +85,7 @@ class MediaSplit extends EventEmitter {

_handleUrl () {
return ytdl.getInfo(this._options.input).then((info) => {
this._downloadOptions = { quality: 'highestaudio', filter: this._options.audioonly ? 'audioonly' : undefined }
this._downloadOptions = { quality: this._options.quality, filter: this._options.audioonly ? 'audioonly' : undefined }

const format = ytdl.chooseFormat(info.formats, this._downloadOptions)

@@ -82,7 +96,7 @@ class MediaSplit extends EventEmitter {
}

this._inputFile = path.join(
this._options.output, this._fileName(info.title, format.container)
this._options.output, this._fileName(info.videoDetails.title, format.container)
)

return Promise.all([
@@ -127,6 +141,7 @@ class MediaSplit extends EventEmitter {
let downloadLen
ytdl.downloadFromInfo(info, this._downloadOptions)
.on('progress', (chunk, downloaded, total) => {
total = parseInt(total)
if (!downloadLen) {
this.emit('downloadLength', downloadLen = total)
}
@@ -141,7 +156,7 @@ class MediaSplit extends EventEmitter {
_checkCachedFileIsValid (stat, ytUrl) {
return new Promise((resolve) => {
const reqLib = this._getReqLib(ytUrl)
const parsed = url.parse(ytUrl)
const parsed = new url.URL(ytUrl)
parsed.method = 'HEAD'
const req = reqLib.request(parsed, (response) => {
if (!this._isResponseSuccessful(response)) {
@@ -168,7 +183,7 @@ class MediaSplit extends EventEmitter {
return Promise.resolve(true)
}

const url = `https://img.youtube.com/vi/${info.video_id}/sddefault.jpg`
const url = `https://img.youtube.com/vi/${info.videoDetails.videoId}/sddefault.jpg`
return new Promise((resolve) => {
const outputFile = path.join(this._options.output, 'cover.jpg')
request(url)
@@ -210,7 +225,7 @@ class MediaSplit extends EventEmitter {
const sections = this._options.sections
const parsed = []

for (let index in sections) {
for (const index in sections) {
const curr = sections[ index ]
const line = parseInt(index) + 1
const time = this._extractTimeRangeFromLine(curr)
@@ -226,7 +241,7 @@ class MediaSplit extends EventEmitter {
}

if (line < sections.length && end === null) {
let time = this._extractTimeRangeFromLine(sections[ line ])
const time = this._extractTimeRangeFromLine(sections[ line ])

if (time === null) {
throw new Error(`Line ${line + 1} does not contain a valid time range`)
@@ -282,7 +297,7 @@ class MediaSplit extends EventEmitter {
}

_extractStartAndEndTime (period) {
let [ start, end ] = this._removeBrackets(period).split('-')
const [ start, end ] = this._removeBrackets(period).split('-')
return {
start: `[${start.trim()}]`.match(timeRe).pop(),
end: `[${end.trim()}]`.match(timeRe).pop()
@@ -304,7 +319,7 @@ class MediaSplit extends EventEmitter {

// Number of tasks in execution
let concurrentTasks = 0
let maxTasks = this._options.concurrency
const maxTasks = this._options.concurrency

this.emit('data', sections)

@@ -320,10 +335,11 @@ class MediaSplit extends EventEmitter {
clearInterval(interval)
concurrentTasks++

let args = [
const args = [
'-hide_banner',
'-loglevel', 'repeat+error',
'-y',
...this._options.inputParams,
'-i', this._inputFile,
'-ss', section.start
]
@@ -345,11 +361,14 @@ class MediaSplit extends EventEmitter {
}

// Add metadata info to the arguments
for (let meta of section.metadata) {
for (const meta of section.metadata) {
const [ name, value ] = meta
args.push('-metadata', `${name}=${value}`)
}

// Additional ffmpeg output arguments
args.push(...this._options.outputParams)

// And finally the output path
args.push(path.join(this._options.output, section.name))

@@ -370,6 +389,15 @@ class MediaSplit extends EventEmitter {
return Promise.all(promises)
}

/**
* @param {string[]} params
*/
_sanitizeParams (params) {
return (params || [])
.map((x) => x.replace(/^("|')/gim, '').replace(/("|')$/gim, ''))
.flatMap(x => x.split(' '))
}

_checkAccess (dir, mode) {
return new Promise((resolve, reject) => fs.access(dir, mode, (err) => err ? reject(err) : resolve(dir)))
}
5,114 changes: 0 additions & 5,114 deletions package-lock.json

This file was deleted.

48 changes: 25 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "media-split",
"version": "5.0.0",
"version": "5.4.0",
"description": "Split audio (and video) files",
"main": "index.js",
"author": {
@@ -23,18 +23,18 @@
"repository": "https://github.com/skiptirengu/media-split",
"license": "MIT",
"dependencies": {
"chalk": "^2.4.1",
"cli-progress": "^2.1.0",
"eslint": "^5.3.0",
"global-modules": "^1.0.0",
"miniget": "^1.3.0",
"sanitize-filename": "^1.6.1",
"yargs": "^12.0.1",
"ytdl-core": "^0.24.0"
"chalk": "~4.1.2",
"cli-progress": "^3.9.1",
"eslint": "^8.6.0",
"global-modules": "^2.0.0",
"miniget": "^4.2.1",
"sanitize-filename": "^1.6.3",
"yargs": "~17.3.1",
"ytdl-core": "^4.9.2"
},
"peerDependencies": {
"ffmpeg-binaries": "^4.0.0",
"@ffmpeg-installer/ffmpeg": "^1.0.0"
"@ffmpeg-installer/ffmpeg": "^1.0.20",
"ffmpeg-static": "^4.3.0"
},
"bin": {
"mp3-split": "cli/index.js",
@@ -51,19 +51,21 @@
"lint"
],
"devDependencies": {
"@ffmpeg-installer/ffmpeg": "^1.0.15",
"@types/chai": "^4.1.4",
"chai": "^4.1.2",
"eslint-config-standard": "^12.0.0-alpha.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"jsdoc-to-markdown": "^4.0.1",
"mocha": "^5.2.0",
"mock-require": "^3.0.2",
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@types/chai": "^4.3.0",
"chai": "^4.3.4",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-standard": "^5.0.0",
"mocha": "^9.1.3",
"mock-require": "^3.0.3",
"mp3-duration": "^1.1.0",
"nyc": "^12.0.2",
"nyc": "^15.1.0",
"pre-commit": "^1.2.2"
},
"optionalDependencies": {
"jsdoc-to-markdown": "^7.1.0"
}
}
13 changes: 13 additions & 0 deletions spec/Command.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

const expect = require('chai').expect
const spawnSync = require('child_process').spawnSync
const path = require('path')

describe('Command', () => {
it('should return 0 code', () => {
const binPath = path.resolve('cli/index.js')
const proc = spawnSync('node', [ binPath, 'h' ])
expect(proc.status).to.be.equal(0)
})
})
14 changes: 7 additions & 7 deletions spec/FFmpeg.spec.js
Original file line number Diff line number Diff line change
@@ -26,17 +26,17 @@ describe('FFmpeg', function () {
expect(require1).to.be.equals('foo')
})

it('should fallback to ffmpeg-binaries', function () {
it('should fallback to ffmpeg-static', function () {
mockRequire('@ffmpeg-installer/ffmpeg', errorModule)
mockRequire('ffmpeg-binaries', 1)
mockRequire('ffmpeg-static', 1)
const require1 = require(moduleName)
expect(require1).to.be.equals(1)
})

it('should fallback to ffmpeg on $PATH', function () {
let called = false
mockRequire('@ffmpeg-installer/ffmpeg', errorModule)
mockRequire('ffmpeg-binaries', errorModule)
mockRequire('ffmpeg-static', errorModule)
childProcess.spawnSync = function (cmd) {
called = true
expect(cmd).to.be.equals('ffmpeg')
@@ -48,18 +48,18 @@ describe('FFmpeg', function () {

it('should fallback to global @ffmpeg-installer', function () {
mockRequire('@ffmpeg-installer/ffmpeg', errorModule)
mockRequire('ffmpeg-binaries', errorModule)
mockRequire('ffmpeg-static', errorModule)
childProcess.spawnSync = errorSpawn
mockRequire(path.join(global, '@ffmpeg-installer/ffmpeg'), { path: 'qux' })
expect(require(moduleName)).to.be.equals('qux')
})

it('should fallback to global ffmpeg-binaries', function () {
it('should fallback to global ffmpeg-static', function () {
mockRequire('@ffmpeg-installer/ffmpeg', errorModule)
mockRequire('ffmpeg-binaries', errorModule)
mockRequire('ffmpeg-static', errorModule)
childProcess.spawnSync = errorSpawn
mockRequire(path.join(global, '@ffmpeg-installer/ffmpeg'), errorModule)
mockRequire(path.join(global, 'ffmpeg-binaries'), 2)
mockRequire(path.join(global, 'ffmpeg-static'), 2)
expect(require(moduleName)).to.be.equals(2)
})

74 changes: 36 additions & 38 deletions spec/MediaSplit.spec.js
Original file line number Diff line number Diff line change
@@ -56,14 +56,14 @@ describe('MediaSplit', function () {
})

describe('_checkDownloadCache', function () {
let mockFile = path.join(outputPath, 'mock_file.mp4')
const mockFile = path.join(outputPath, 'mock_file.mp4')

afterEach(() => {
fs.unlinkSync(mockFile)
})

it('should invalidate cache if sizes don\'t match', () => {
let info = { foo: 'bar' }
it('should invalidate cache if sizes don\'t match', async () => {
const info = { foo: 'bar' }
let called = false

fs.writeFileSync(mockFile, 'Foo bar')
@@ -81,18 +81,17 @@ describe('MediaSplit', function () {
split._getReqLib = function () {
return {
request (url, cb) {
// eslint-disable-next-line standard/no-callback-literal
// eslint-disable-next-line node/no-callback-literal
cb({ statusCode: 200, headers: { 'content-length': 123488 } })
return { end: () => null, on: () => null }
}
}
}

split._inputFile = mockFile
return split._checkDownloadCache({ url: 'http://skiptirengu.com/video/' }, info).then(() => {
expect(called).to.be.true
expect(data).to.be.deep.equals(info)
})
await split._checkDownloadCache({ url: 'http://skiptirengu.com/video/' }, info)
expect(called).to.be.true
expect(data).to.be.deep.equals(info)
})
})

@@ -179,7 +178,7 @@ describe('MediaSplit', function () {

function tearDown () {
fs.readdirSync(outputPath).forEach((file) => {
if ([ '.mp3', '.m4a', '.jpg' ].indexOf(path.extname(file)) !== -1) {
if ([ '.mp3', '.m4a', '.jpg', '.mp4' ].indexOf(path.extname(file)) !== -1) {
fs.unlinkSync(path.join(outputPath, file))
}
})
@@ -188,7 +187,9 @@ describe('MediaSplit', function () {
beforeEach(tearDown)
afterEach(tearDown)

it('should parse a url', function () {
it('should parse an url', async function () {
this.timeout(8000)

let counter = 0
let video
let filename
@@ -213,7 +214,7 @@ describe('MediaSplit', function () {
counter++
})
split.on('url', (file, info) => {
video = info.video_id
video = info.videoDetails.videoId
filename = file
})
split.on('data', () => {
@@ -223,20 +224,19 @@ describe('MediaSplit', function () {
progressEvt = total
})

return split.parse().then((sections) => {
expect(video).to.be.equals('kN9SZtwP1ys')
expect(counter).to.be.equals(2)
expect(sections).to.length(2)
expect(dataEvt).to.be.true
expect(progressEvt).to.be.equals(161161)
expect(fs.existsSync(path.join(outputPath, 'Part 1.m4a'))).to.be.true
expect(fs.existsSync(path.join(outputPath, 'Part 2.m4a'))).to.be.true
expect(fs.existsSync(path.join(outputPath, 'cover.jpg'))).to.be.true
expect(fs.existsSync(filename)).to.be.true
})
const sections = await split.parse()
expect(video).to.be.equals('kN9SZtwP1ys')
expect(counter).to.be.equals(2)
expect(sections).to.length(2)
expect(dataEvt).to.be.true
expect(progressEvt).to.be.equals(161161)
expect(fs.existsSync(path.join(outputPath, 'Part 1.m4a'))).to.be.true
expect(fs.existsSync(path.join(outputPath, 'Part 2.m4a'))).to.be.true
expect(fs.existsSync(path.join(outputPath, 'cover.jpg'))).to.be.true
expect(fs.existsSync(filename)).to.be.true
})

it('should parse a local file', function () {
it('should parse a local file', async function () {
let counter = 0
let dataEvt = false

@@ -265,21 +265,19 @@ describe('MediaSplit', function () {
dataEvt = true
})

return split.parse().then((sections) => {
expect(sections).to.length(3)
expect(counter).to.be.equals(3)
const values = [
duration(path.join(outputPath, 'First.mp3')),
duration(path.join(outputPath, 'Second.mp3')),
duration(path.join(outputPath, 'Third.mp3'))
]
return Promise.all(values)
}).then(([ first, second, third ]) => {
expect(first.toString().slice(0, 3)).to.be.equals('2.5')
expect(second.toString().slice(0, 3)).to.be.equals('4.5')
expect(third.toString().slice(0, 3)).to.be.equals('1.4')
expect(dataEvt).to.be.true
})
const sections = await split.parse()
expect(sections).to.length(3)
expect(counter).to.be.equals(3)
const values = [
duration(path.join(outputPath, 'First.mp3')),
duration(path.join(outputPath, 'Second.mp3')),
duration(path.join(outputPath, 'Third.mp3'))
]
const [ first, second, third ] = await Promise.all(values)
expect(first.toString().slice(0, 3)).to.be.equals('2.5')
expect(second.toString().slice(0, 3)).to.be.equals('4.5')
expect(third.toString().slice(0, 3)).to.be.equals('1.4')
expect(dataEvt).to.be.true
})
})
})
3,152 changes: 3,152 additions & 0 deletions yarn.lock

Large diffs are not rendered by default.