Last active
March 25, 2023 22:09
-
-
Save CennoxX/a0a89aef70016c3b880142cc41a6cef2 to your computer and use it in GitHub Desktop.
Converts OnlineTvRecorder cutlists to m3u format, to play with VLC-Player, set the starttime to change the beginning of the video. Internally this converts the cutlist-format to a json representation and thus makes it possible to be the starting point for further transformations.
This file contains hidden or 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
function convertCutlistToM3u(cutlist, starttime = null) { | |
var obj = {}; | |
var lastKey; | |
cutlist.split(/\n\n?/).forEach(l => { | |
var [, key] = l.match(/\[(.*)]/) || []; | |
if (key) { | |
obj[key] = {} | |
lastKey = key; | |
} else { | |
var [prop, val] = l.split("="); | |
obj[lastKey][prop] = val; | |
} | |
}) | |
var cutArray = Array.from(Object.keys(obj)) | |
.filter(key => key.startsWith("Cut")) | |
.map(key => Object.assign({}, obj[key])); | |
Object.keys(obj) | |
.filter(key => key.startsWith("Cut")) | |
.forEach(key => delete obj[key]); | |
obj.Cut = cutArray; | |
obj.Cut.forEach(cut => { | |
for (const prop in cut) { | |
cut[prop] = parseFloat(cut[prop]); | |
} | |
}) | |
var offset = starttime ? obj.Cut[0].Start - starttime : 0; | |
return obj.Cut.map(i => "#EXTVLCOPT:start-time=" + (i.Start - offset) + "\n#EXTVLCOPT:stop-time=" + (i.Start + i.Duration - offset) + "\n" + obj.General.ApplyToFile).join("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment