Last active
April 6, 2017 20:43
-
-
Save nlac/155784a9cb7d742a9bbdc0ed93e39b92 to your computer and use it in GitHub Desktop.
This script helps to intelligently split merged audio tracks on youtube, generating a list of ffmpeg commands
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
/** | |
* ffmpeg script generator for merged audio tracks on youtube | |
* @author nlac | |
* @desc Helps to intelligently split merged audio tracks (eg. https://www.youtube.com/watch?v=Lf6yNZPwREU) | |
* | |
* Usage: | |
* 1. download the merged track eg. using JDownloader | |
* 2. open the youtube page in a browser + paste this script into the js console | |
* 3. fill the variables in the first line (fullSong is the file name of the downloaded track) | |
* 4. run the script | |
* 5. save the generated log into a BAT file | |
* 6. run the BAT file in the directory of the full track | |
*/ | |
var fullSong = 'songs.m4a', artist = '', album = 'Ultimate Indie 2016', textOnTheRight = 1; | |
var cmds = [], warns = [], prev = undefined, ext = fullSong.match(/\w+$/)[0]; | |
[].forEach.call(document.querySelectorAll('#eow-description a'), function(a, i) { | |
if (a.innerHTML.match(/^(\d\d?[:.])+\d\d$/)) { | |
var parts = a.innerHTML.split(/[:.]/); | |
a._start = 0; | |
for(var pl=parts.length,i=0; i<pl; i++) | |
a._start += Math.pow(60,i) * parts[pl-1-i]; | |
a._txt = (textOnTheRight ? a.nextSibling : a.previousSibling).data.trim().replace(/^[\d.-\s\(\)\[\]]*/, '').replace(/[^\w-– ]/g,'').replace(/ +/g,' ').replace(/–/g,'-'); | |
if (prev) { | |
var len = a._start - prev._start; | |
if (len <= 0 || len > 1200) | |
warns.push('Possibly bad length (' + len + ') found at ' + prev._txt + ' (next item:' + a._txt + ')'); | |
cmds.push('call ffmpeg -ss "' + prev._start + '" -t ' + len + ' -i "' + fullSong + '" -metadata title="' + prev._txt | |
+ '" -metadata artist="' + artist + '" -metadata album="' + album + '" -c:a copy "' + prev._txt + '.' + ext + '"'); | |
} | |
prev = a; | |
} | |
}); | |
if (prev) { | |
var len = 9999999; | |
cmds.push('call ffmpeg -ss "' + prev._start + '" -t ' + len + ' -i "' + fullSong + '" -metadata title="' + prev._txt | |
+ '" -metadata artist="' + artist + '" -metadata album="' + album + '" -c:a copy "' + prev._txt + '.' + ext + '"'); | |
} | |
console.info(cmds.join("\n")); | |
warns.forEach(function(w) {console.warn(w)}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment