Coder Social home page Coder Social logo

media-split's Introduction

Media-split

Actions Status

Split audio (and video) files

Install

Make sure you have ffmpeg installed and added to your path then run:

npm install [-g] media-split

If you don't have ffmpeg installed, you can install this or this package which comes with a bundled ffmpeg, and media-split will automatically detect and use it.

npm install [-g] ffmpeg-static

or

npm install [-g] @ffmpeg-installer/ffmpeg

CLI

media-split comes with a built in CLI tool. Type media-split -h to list all options and see an usage example. For input you can use either a YouTube link or a local file.

The template file should be in the following format. For more info, checkout ffmpeg's duration syntax page.

[([hh:]mm:ss[.ms...]) [ - ([hh:]mm:ss[.ms...])]] My Music Name

A template file usually looks like this:

[00:00] eli filosov [ p h i l o ] - oneofone_rwrk
[01:30] Swishers [SwuM x bsd.u]
[03:28] sweetbn _ i held you so close i forgot the world
[05:52 - 07:49] emune - Gretchen
[07:52 - 09:50] jhfly - sheets
[10:00] arbour - elusive
[11:30] tomppabeats - will you stay here with me
[12:40] tomppabeats - lonely but not when you hold me
[13:31 - 15:30] Bassti - To All The Ladys In The Place
[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.

Library

You can also use media-split as a library.

let MediaSplit = require('media-split');
let split = new MediaSplit({ input: 'myaudio.mp3', sections: ['[01:30] My audio'] });
split.parse().then((sections) => {
  for (let section of sections) {
    console.log(section.name);      // filename
    console.log(section.start);     // section start
    console.log(section.end);       // section end
    console.log(section.trackName); // track name
  }
});

new MediaSplit(options)

Returns: MediaSplit

Param Type Description
options object
options.downloadCover boolean Whether to download the cover from the YouTube video
options.input string The input file. Can be either a file path or a YouTube url
options.concurrency number Number of parallel workers MediaSplit will spawn at once
options.sections Array.<string> Sections to extract from the input source. Supported formats are [01:30 - 03:50] File or [01:30] File
options.output string Output path
options.format string Output format (mp3, m4a, flac, etc)
options.audioonly boolean Force download only audio files when using a url as input
options.quality string The download quality when downloading from YouTube (highest/lowest/highestaudio/lowestaudio/highestvideo/lowestvideo)
options.inputParams Array.<string> Additional input parameters for FFMpeg
options.outputParams Array.<string> Additional output parameters for FFMpeg

MediaSplit.parse() โ‡’ Promise.<Array.<object>>

Split the media

"url" (input, info, cached)

URL event. This event is emitted only once.

Param Type Description
input string The input file
info object The video info
cached boolean Whether the file was cached or not

"data" (sections)

Data event. This event is emitted only once.

Param Type Description
sections Array.<object> Array with the parsed sections

"beforeSplit" (info, index)

Emitted before a section is split.

Param Type Description
info object Section info
index number Index

"afterSplit" (info, index)

Emitted after a section is split.

Param Type Description
info object Section info
index number Section index

"downloadProgress" (chunk, downloaded, total)

Download progress.

Param Type Description
chunk number Chunk length in bytes
downloaded number Total downloaded in bytes
total number Total download length in bytes

"downloadLength" (length)

Total download length. This event is emitted only once.

Param Type Description
length number Length in bytes

License

Licensed under the incredibly permissive MIT license

media-split's People

Contributors

dependabot[bot] avatar sergiu-omg avatar skiptirengu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

media-split's Issues

Possibility to define output format

Hello @skiptirengu and thank you for this script.

FFMPEG is powerfull tool. Maybe a way for us to define output file format?
I can convert m4a into mp3... but would be fun if it could stay m4a :) ๐Ÿ‘

Regex does not handle local folders with a dot in the name

If I have a folder name with a dot, like "/Users/tommie/Git/Github.com/my-project/my-file.mp3", then it is recognized as a url and tries to find a youtube video by id instead, which of course will fail.

I played around a bit with the regex and tried multiple urls + linux/unix and windows folders with dots and it seem to work as expected with my proposed fix below (do not allow any slash before the url, by this in the start: ^(?!\/)):

Today:
const urlRe = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/g

Replace with:
const urlRe = /^(?!\/)(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/g

Update dependency ytdl-core to more recent version

Running media-split from a fresh install errors with:

Error: Cannot find module 'm3u8stream/lib/parse-time'
Require stack:
- <path>/ytdl-core/lib/info-extras.js
- <path>/node_modules/ytdl-core/lib/info.js
- <path>/node_modules/ytdl-core/lib/index.js
- <path>/node_modules/media-split/lib/MediaSplit.js

media-split currently relies on ytdl-core version 0.29.7, which imports parseTime from m3u8stream/lib/parse-time, however m3u8stream has since renamed /lib/ to /dist/.

Updating the ytdl-core dependency to the version containing the change (^1.0.0) will fix.

See:

Commit in ytdl-core updating path:

Readme.MD error

In your readme,you still write npm install [-g] mp3-split, what should be npm install [-g] media-split

video resize

im using this great package and was wandering: is there an ability to resize the splitted videos?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.