Skip to content

Instantly share code, notes, and snippets.

@mkettn
Last active April 19, 2019 17:38
Show Gist options
  • Save mkettn/4e85db9a88b5f25f67ffe0553f3469cb to your computer and use it in GitHub Desktop.
Save mkettn/4e85db9a88b5f25f67ffe0553f3469cb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sys import stdin, stderr, argv
import re
if argv[1]=='-h':
print "%s <ytc-file> > <cue-file>" % (argv[0])
exit(0)
if len(argv) == 2 and not argv[1]=='-':
import io
stdin = io.open(argv[1], 'rt')
header_tpl = """PERFORMER "%s"
TITLE "%s"
"""
track_tpl = """ TRACK %02d AUDIO
TITLE "%s"
PERFORMER "%s"
INDEX 01 %02d:%02d:00
"""
curr_idx = 0
interpret = stdin.readline().strip()
print header_tpl % (interpret, stdin.readline().strip(), )
if len(stdin.readline().strip()) != 0:
stderr.write("Missing Blank line\n")
exit(1)
rgx = re.compile('^(\d{1,2}):(\d{1,2}) (.+)$')
for line in stdin.readlines():
line = line.strip()
if len(line)==0:
break
foo, start_min, start_sec, title, bar = rgx.split(line)
curr_idx = curr_idx + 1
print track_tpl % (curr_idx, title, interpret, int(start_min), int(start_sec))

Motivation

I want to convert a comment or description from youtube without alot effort to a cuesheet.

Usage

ytc2cue expects the input on stdin or a path to a file as the firstparameter and writes to stdout:

$ ytc2cue < youtube_comment.txt > cuesheet.cue 
$ ytc2cue youtube_comment.txt > cuesheet.cue 

Input text format

First line is the interpret, second line is the album name, thrid line is blank. The remaining lines until EOF are formatted as follow: <time> <track title>

Heres an example:

Dethklok
Dethalbum II

00:00 Bloodlines
3:29 The Gears
7:48 Burn The Earth Laser
11:46 Cannon Deth Sentence
16:17 Black Fire Upon Us
21:49 Dethsupport
24:28 The Cyborg Slayers
28:42 I Tamper With the Evidence at the Murder Site Of Odin
33:10 Murmaider II: The Water God
38:49 Comet Song
42:35 Symmetry
47:05 Volcano there you bitches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment