# HG changeset patch
# User drewp@bigasterisk.com
# Date 1334724731 25200
# Node ID 97d7c0bb94089e289767a5f39c85f561db76dcda
# Parent b468fe90d5ef28ab62241fe2f260a59cd98a17a4
barcode maker tool
Ignore-this: e786d32c8192377f0b967089fcfc536
diff -r b468fe90d5ef -r 97d7c0bb9408 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("""
+
+
+
+""")