Last active
April 4, 2023 01:18
-
-
Save H3wastooshort/2199638699053e25c2112b6369c6d449 to your computer and use it in GitHub Desktop.
Convert youtube comment timestamps to FFMETADATA
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style>.half{width:95%;height:40vh;}</style> | |
</head> | |
<body> | |
Title:<input id="title_text"> Artist:<input id="artist_text"> | |
<textarea id="in_text" class="half"></textarea><br> | |
<textarea id="out_text" class="half"></textarea> | |
<script> | |
artist_text.onchange = title_text.onchange = in_text.onchange = yt_ts_to_ffmeta; | |
const track_time_matcher = /^(\d*?):?(\d+):(\d+) (.*?$)/; | |
// /(^\d+:\d+:?\d+)(.*?$)/mg could make this into JSON with {'h':$1, 'm':$2,'s':$3,'title':'$4'}, | |
function yt_ts_to_ffmeta() { | |
let chapters = []; | |
let text = in_text.value; | |
text = text.replaceAll("\r",""); | |
let lines = text.split("\n"); | |
lines.forEach(l => { | |
let ld = track_time_matcher.exec(l); | |
console.log(ld); | |
if (ld != null) if (typeof ld == "object") { | |
let time = (parseInt(ld[2])*60) + parseInt(ld[3]); | |
if (typeof ld[1] == "string") if (ld[1].length>0) time += parseInt(ld[1])*60*60; | |
chapters.push({'second':time,'name':ld[4]}); | |
} | |
}); | |
//console.dir(chapters); | |
let ffmeta = ";FFMETADATA1\n"; | |
ffmeta += "title=" + title_text.value + "\n"; | |
ffmeta += "artist=" + artist_text.value + "\n"; | |
chapters.forEach((c,i,a) =>{ | |
ffmeta += "[CHAPTER]\nTIMEBASE=1/1\n"; | |
ffmeta += "START=" + c.second + "\n"; | |
ffmeta += "END=" + (i<(a.length-1) ? a[i+1].second : 0) + "\n"; | |
ffmeta += "TITLE=" + (c.name.replaceAll('=','\\=').replaceAll(';','\\;').replaceAll('#','\\#').replaceAll('\\','\\\\')) + "\n"; //ugly as fuck | |
}); | |
//console.log(ffmeta); | |
out_text.value=ffmeta; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made this, so that i can split up this video: https://www.youtube.com/watch?v=iUuafesulN8
It took me an hour in the middle of the night, but im proud
Also: the last END entry will be 0, you have to enter it manually