user-1277
03-07-2019, 11:27 AM
I read @jaybeee's request about converting track list files to cue sheets. Seems like no-one else has done it, so here's a little Python script to do the conversion for you. Hope this helps! I've never used a cue sheet before, but the formatting looks pretty simple.
Code:
# take track list from get_iplayer and convert to a cue sheet
import os
folder = r'K:\Radio'
os.chdir(folder)
filename = '2019-06-28 Glastonbury 2019 Stormzy Live.m4a'
basename, ext = os.path.splitext(filename)
assert os.path.exists(filename)
tracklist_filename = basename + '.tracks.txt'
assert os.path.exists(tracklist_filename)
cuesheet_filename = basename + '.cue'
track_list = open(tracklist_filename).read()
tracks = track_list.split('--------\n') # separator between tracks and header
cuesheet_file = open(cuesheet_filename, 'w')
# first lines: title, artist, date, URL
header_tags = ['TITLE', 'PERFORMER', 'REM DATE', 'REM COMMENT']
header = tracks[0].split('\n')
title, artist = header[:2]
for i, header_line in enumerate(header):
f_str = '{} "{}"\n' if i <= 1 else '{} {}\n'
# use COMMENT if there are more than four lines
if header_line != '':
cuesheet_file.write(f_str.format(header_tags[min(i, len(header_tags) - 1)], header_line))
# write filename to cue sheet
file_type = 'MP3' if ext.lower() == 'mp3' else 'WAVE'
cuesheet_file.write('FILE "{}" {}\n'.format(filename, file_type))
# now go through the tracks
start = '00:00:00'
for i, track in enumerate(tracks):
if i > 0: # first bit is an intro, use title and artist from header
start, artist, title, duration = track.split('\n')[:4]
# gotcha: cue sheet syntax is mm:ss:ff, track list is hh:mm:ss
hours, minutes, seconds = [int(value) for value in start.split(':')]
start = '{:02d}:{:02d}:00'.format(hours * 60 + minutes, seconds)
cuesheet_file.write(' TRACK {:02d} AUDIO\n'.format(i + 1))
cuesheet_file.write(' TITLE "{}"\n'.format(title))
cuesheet_file.write(' PERFORMER "{}"\n'.format(artist))
cuesheet_file.write(' INDEX 01 {}\n'.format(start))