Skip to content

Instantly share code, notes, and snippets.

@steven2358
Last active October 2, 2019 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steven2358/4de3c699a17c1ea925ef to your computer and use it in GitHub Desktop.
Save steven2358/4de3c699a17c1ea925ef to your computer and use it in GitHub Desktop.
Convert a playlist in text format to a cue file
# Convert a playlist in text format to a cue file
# Author: steven2358
# Usage:
# 1. Make a playlist file "playlist.txt" using this format:
'''
Album Artist - Album Name
FileName.mp3
MM:SS:mm - Artist1 - Title1
MM:SS:mm - Artist2 - Title2
MM:SS:mm - Artist3 - Title3
'''
# 2. Run "cue_sheet_converter playlist"
import sys
def parse_args():
fname = sys.argv[1]
return fname
def main():
fname = parse_args()
print(fname)
infile = open(fname+'.txt', 'rt')
outfile = open(fname+'.cue',"wt")
artistTitle = infile.readline()
mp3file = infile.readline()
[artist,albumTitle] = artistTitle.rsplit(" - ")
albumTitle = albumTitle.rstrip()
mp3file = mp3file.rstrip()
outfile.write("PERFORMER \""+artist+"\"\n")
outfile.write("TITLE \""+albumTitle+"\"\n")
outfile.write("FILE \""+mp3file+"\" MP3\n")
counter = 1;
for line in infile:
[trIndex,performer,trTitle] = line.rsplit(" - ")
trTitle = trTitle.rstrip()
track = str(counter).zfill(2)
counter += 1
outfile.write(" TRACK "+track+" AUDIO\n")
outfile.write(" PERFORMER \""+performer+"\"\n")
outfile.write(" TITLE \""+trTitle+"\"\n")
outfile.write(" INDEX 01 "+trIndex+"\n")
outfile.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment