Created
August 31, 2019 20:09
-
-
Save ig0rmin/0ce854b68072e36dda0fc9861c709aac to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
import sys | |
import re | |
import os.path | |
def print_help(): | |
print "Usage: %s time.txt source.mvk" % (sys.argv[0]) | |
# Filename == basename with extension | |
def guess_title_and_performer(filename): | |
r = re.compile("^([\w\s]+)-([\w\s]+)-\w+\.\w+$") | |
#TODO: Support more cases | |
m = r.match(filename) | |
if m == None: | |
return ("", "") | |
else: | |
return (m.group(1).strip(), m.group(2).strip()) | |
def youtube_timestamp_to_cuesheet(yt): | |
yts = [int(s) for s in yt.split(":")] | |
return "%02d:%02d:00" % (yts[0]*60 + yts[1], yts[2]) | |
def main(): | |
if len(sys.argv) != 3: | |
print_help() | |
return | |
r = re.compile("([0-9]{2}:[0-9]{2}:[0-9]{2}) - (.*)") | |
timestamps = [] | |
with open(sys.argv[1], 'r') as f: | |
for l in f: | |
m = r.match(l) | |
if m != None: | |
timestamps.append((m.group(1), m.group(2))) | |
if len(timestamps) == 0: | |
print "No timestamps found in %s" % (sys.argv[1]) | |
return | |
outpath = os.path.splitext(sys.argv[2])[0] + ".cue" | |
out = open(outpath, 'w') | |
filebase = os.path.basename(sys.argv[2]) | |
title, performer = guess_title_and_performer(filebase) | |
print >>out, 'TITLE "%s"' % (title) | |
print >>out, 'PERFORMER "%s"' % (performer) | |
print >>out, 'FILE "%s" MP3' % (filebase) | |
for i in range(0, len(timestamps)): | |
print >>out, '\tTRACK %02d AUDIO' % (i+1) | |
print >>out, '\t\tTITLE "%s"' % (timestamps[i][1]) | |
print >>out, '\t\tPERFORMER "%s"' % (performer) | |
print >>out, '\t\tINDEX 01 %s' % (youtube_timestamp_to_cuesheet(timestamps[i][0])) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment