Skip to content

Instantly share code, notes, and snippets.

@nitzel
Last active June 5, 2019 14:26
Show Gist options
  • Save nitzel/292367c9c2dd34ff22e3e74d25fb2561 to your computer and use it in GitHub Desktop.
Save nitzel/292367c9c2dd34ff22e3e74d25fb2561 to your computer and use it in GitHub Desktop.
Generates the content of a .cue file to distinguish several tracks in one audiofile. I used this for foobar2000 when having a single audio file that actually contained multiple songs.
#!/usr/bin/env python3
"""
Prints out the content of a cue-file.
You can specify the performer, album, release-year, filename, fileformat
and of course the tracks with their lengths(!) and names.
Echo into a file or copy the output to a cue-file, e.g. python3 print-cue-file-content.py > trackinfo.cue
You can then open the .cue file with VLC, foobar etc.
Author: nitzel
License: Unlicensed, feel free to use it
"""
# CONFIGURATION starts here
performer = "Singer XY"
album = "Best of XY"
year = "2017"
filename = "Best Of XY - Full Album.mp3"
fileformat = "MP3"
"""trackinfo, consisting of the length of the tracks and their names:
each entry: (minutes, seconds, name)
So for a track "Party" that runs 5 minutes and 10 seconds you'd enter:
(5,10,"Party")
This info can be obtained from the CD Cover for example."""
trackInfo = [
(6,29, "Best Song"),
(5,25, "Another Track"),
(4,47, "Not so very best")
]
# CONFIGURATION ends here!
# print header
print("PERFORMER {0}\nTITLE \"{1}\"\nFILE \"{2}\" {3}\nREM DATE {4}".format(performer,album,filename,fileformat,year))
def secondsToString(timeInSeconds):
"""separates minutes and seconds from timeInSeconds to
represent it in MM:SS:00"""
minutes = (int)(timeInSeconds/60)
seconds = (int)(timeInSeconds%60)
millis = 0
return "{0:02d}:{1:02d}:{2:02d}".format(minutes, seconds, millis)
timeInSeconds = 0 # Time that was consumed by previous songs in seconds
for i,(m,s,trackTitle) in enumerate(trackInfo):
trackIndex = i+1
trackStartTime = secondsToString(timeInSeconds)
# Print the calculated values generating an entry for the current song.
print("\tTRACK {0:02d} AUDIO\n\t\tTITLE \"{1}\"\n\t\tINDEX 01 {2}".format(trackIndex, trackTitle, trackStartTime))
# Increment time by the length of the current track
timeInSeconds += m*60 + s
# add the end-time of the last track. not sure if that is cue-standard, but wont hurt.
lastTrackFinishTime = secondsToString(timeInSeconds)
print("\t\tINDEX 02 {0}\n".format(lastTrackFinishTime))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment