Last active
August 2, 2019 10:33
-
-
Save retrography/3a0de783a78a71777d35937ed324b6fb to your computer and use it in GitHub Desktop.
Create cue sheet for a list of id3-tagged audio files
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/env python3 | |
from sys import argv | |
from mediafile import MediaFile | |
def main(): | |
args = argv[1:] | |
first_file = True | |
lines = [] | |
for filename in args: | |
tags = MediaFile(filename) | |
cuefile = tags.albumartist + " - " + tags.album + ".cue" | |
if first_file: | |
lines.append('REM DATE ' + str(tags.year)) | |
lines.append('REM GENRE ' + tags.genre) | |
lines.append('PERFORMER "' + tags.albumartist + '"') | |
lines.append('TITLE "' + tags.album + '"') | |
first_file = False | |
lines.append('FILE "' + filename + '" WAVE') | |
lines.append('\tTRACK ' + format(tags.track, '02') + " AUDIO") | |
lines.append('\t\tTITLE "' + tags.title + '"') | |
lines.append('\t\tPERFORMER "' + tags.artist + '"') | |
lines.append('\t\tINDEX 01 00:00:00') | |
cue = open(cuefile,"w+") | |
cue.write("\n".join(lines)) | |
cue.close() | |
if __name__ == "__main__": | |
main() |
Sorry for such stupid question, but how to use this script? running script itself in the folder full od dsf makes nothing
The syntax should be something like ./cuer.rb *.dsf
Running this on a bunch of .dsf
with ffmpeg
installed yields:
./cuer.rb:19:in '<main>': undefined method '[]' for nil:NilClass (NoMethodError)
I made pretty much the same script in Pyhon:
#!/usr/bin/env python
from sys import argv
from argparse import ArgumentParser
import subprocess
import json
import os
def main():
args = parse_args()
first_file = True
for filename in args.src:
result = subprocess.run(['ffprobe', '-v', 'quiet', '-print_format', 'json', '-show_format', filename],
stdout=subprocess.PIPE)
metadata = json.loads(result.stdout)['format']
if first_file:
print('REM GENRE ' + metadata['tags']['genre'])
print('REM DATE ' + metadata['tags']['date'])
print('REM PERFORMER "' + metadata['tags']['artist'] + '"')
print('REM TITLE "' + metadata['tags']['album'] + '"')
first_file = False
print_file_info(os.path.basename(metadata['filename']), metadata['tags'])
def print_file_info(filename, tags):
print('FILE "' + filename + '" WAVE')
print(' TRACK ' + tags['track'] + ' AUDIO')
print(' TITLE "' + tags['title'] + '"')
print(' PERFORMER "' + tags['artist'] + '"')
print(' INDEX 01 00:00:00')
def parse_args():
parser = ArgumentParser()
parser.add_argument('--src', nargs='*')
raw_args = argv[1:]
args = parser.parse_args(raw_args)
return args
if __name__ == "__main__":
main()
Syntax:
./cuer.py --src some/folder/*.dsf
Thanks, @klizas! I rewrote it using Mutagen.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes you have
ffmpeg
up and running.