# HG changeset patch # User drewp # Date 1334724731 25200 # Node ID d337de14235d7d909e13c2069541530979880385 # Parent 0489c17be95eb103c55ddf25a8206faca2d98406 barcode maker tool Ignore-this: e786d32c8192377f0b967089fcfc536 darcs-hash:20120418045211-312f9-f40c4f39edd8ed2089e6e4b86cbed2500a9ab809.gz diff -r 0489c17be95e -r d337de14235d service/starArduino/makeBarcodes.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/starArduino/makeBarcodes.py Tue Apr 17 21:52:11 2012 -0700 @@ -0,0 +1,97 @@ +import os, re +from subprocess import check_call +from tempfile import NamedTemporaryFile +from pymongo import Connection + +def makeCode(s): + #return 'code' + psFile = NamedTemporaryFile(suffix='.ps') + check_call(['barcode', + '-b', s, + '-E', + '-o', psFile.name]) + svgFile = NamedTemporaryFile(suffix='.svg') + check_call(['pstoedit', + '-f', 'plot-svg', + '-yshift', '580', + '-xshift', '20', + psFile.name, svgFile.name]) + lines = open(svgFile.name).readlines() + return ''.join(lines[2:]) + +def codeElem(s): + return '
%s
' % makeCode(s) + +mpdPaths = Connection("bang", 27017)['barcodePlayer']['mpdPaths'] +# {mpdPath:"music/path/to/album/or/song", "_id":12} +mpdPaths.ensure_index([('mpdPath', 1)]) +def idForMpdPath(p): + match = mpdPaths.find_one({"mpdPath" : p}) + if match: + return match['_id'] + + top = list(mpdPaths.find().sort([('_id', -1)]).limit(1)) + newId = top[0]['_id'] + 1 if top else 0 + mpdPaths.insert({"mpdPath" : p, "_id" : newId}) + return newId + + +out = open("out.xhtml", "w") +out.write(""" + + + + barcodes + + + +
+""") + + +mpdRoot = "/my/music" + +paths = open("mpdPaths.txt").read().strip().splitlines() + +cardsSeen = 0 +for path in paths: + if os.path.isdir(os.path.join(mpdRoot, path)): + albumDir = path.split('/')[-1] + songFile = None + else: + albumDir, songFile = path.split('/')[-2:] + + if '-' in albumDir: + artistName, albumName = albumDir.replace('_', ' ').split('-', 1) + else: + artistName, albumName = '', albumDir + + if artistName in ['', 'Original Soundtrack', 'Various']: + artistName = albumName + albumName = '' + + if songFile: + songName = re.sub(r'(^\d+\.)|(^\d+\s*-)', '', songFile) + songName = songName.rsplit('.',1)[0].replace('_', ' ') + + out.write('
') + out.write('
%s
' % artistName) + out.write('
%s
' % albumName) + + print (albumName, songName if songFile else '') + out.write(codeElem("music %s" % idForMpdPath(path))) + + if songFile: + out.write('
%s
' % songName) + + out.write('
') + cardsSeen += 1 + if cardsSeen % 8 == 0: + out.write('
') + +out.write(""" +
+ + +""")