Created
September 13, 2009 10:58
-
-
Save alastair/186151 to your computer and use it in GitHub Desktop.
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/python | |
# This script generates URLs to add an AR linking disc n and disc n+1 on a release | |
# put in your albumidentify dir and run generate_rel.py /path/to/music/*disc* | |
# The source files need to have the musicbrainz albumid tag in them | |
import sys | |
import os | |
import tag | |
import albumidentify | |
import sort | |
import re | |
def info(dirs): | |
lastname="" | |
lastid="" | |
for dir in dirs: | |
file = sort.sorted_dir(dir)[0] | |
tags = tag.read_tags(os.path.join(dir,file)) | |
release = tags[tag.ALBUM_ID] | |
releaseurl = u"http://musicbrainz.org/release/%s.html" % (release) | |
album = tags[tag.ALBUM] | |
if tag.ALBUM_ARTIST in tags: | |
artist = tags[tag.ALBUM_ARTIST] | |
else: | |
artist = tags[tag.ARTIST] | |
albumname = re.sub(r' \(disc [0-9].*\)', "", album) | |
if albumname == lastname: | |
print "http://musicbrainz.org/edit/relationship/add.html?link0=album=%s&link1=album=%s" % (lastid, release) | |
else: | |
print "" | |
if tag.DISC_NUMBER in tags: | |
disc = tags[tag.DISC_NUMBER] | |
else: | |
disc = "?" | |
if tag.DISC_TOTAL_NUMBER in tags: | |
total = tags[tag.DISC_TOTAL_NUMBER] | |
else: | |
total = "?" | |
print "%s - %s (%s/%s) - %s" % (artist, album, disc, total, releaseurl) | |
lastid = release | |
lastname = albumname | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
print "usage:",sys.argv[0],"<dirs>" | |
sys.exit(1) | |
info(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment