comparison amakode.py @ 5:f11c5ed0178e

Make using tagpy optional.
author darius@inchoate.localdomain
date Mon, 12 Nov 2007 15:17:20 +1030
parents 65a9f99302cd
children bdb8597191dc
comparison
equal deleted inserted replaced
4:65a9f99302cd 5:f11c5ed0178e
58 import tempfile 58 import tempfile
59 from logging.handlers import RotatingFileHandler 59 from logging.handlers import RotatingFileHandler
60 import urllib 60 import urllib
61 import urlparse 61 import urlparse
62 import re 62 import re
63 import tagpy 63
64 64 try:
65 import tagpy
66 have_tagpy = True
67 except ImportError, e:
68 have_tagpy = False
69
65 class tagpywrap(dict): 70 class tagpywrap(dict):
66 textfields = ['album', 'artist', 'title', 'comment', 'genre'] 71 textfields = ['album', 'artist', 'title', 'comment', 'genre']
67 numfields = ['year', 'track'] 72 numfields = ['year', 'track']
68 allfields = textfields + numfields 73 allfields = textfields + numfields
69 74
189 # assemble command line for encoder 194 # assemble command line for encoder
190 encoder = [] 195 encoder = []
191 encoder += self.encode[self.tofmt] 196 encoder += self.encode[self.tofmt]
192 197
193 try: 198 try:
194 if (self.tofmt in self.tagopt): 199 if (have_tagpy and self.tofmt in self.tagopt):
195 taginfo = tagpywrap(self.inurl) 200 taginfo = tagpywrap(self.inurl)
196 for f in taginfo.allfields: 201 for f in taginfo.allfields:
197 if (f in taginfo and f in self.tagopt[self.tofmt]): 202 if (f in taginfo and f in self.tagopt[self.tofmt]):
198 inf = taginfo[f] 203 inf = taginfo[f]
199 opt = self.tagopt[self.tofmt][f] 204 opt = self.tagopt[self.tofmt][f]
254 """ The main application""" 259 """ The main application"""
255 260
256 def __init__(self, args): 261 def __init__(self, args):
257 """ Main loop waits for something to do then does it """ 262 """ Main loop waits for something to do then does it """
258 log.debug("Started.") 263 log.debug("Started.")
259 264 if (have_tagpy):
265 log.debug("Using tagpy")
266 else:
267 log.debug("Warning: tagpy is unavailable")
268
260 self.readSettings() 269 self.readSettings()
261 270
262 self.queue = QueueMgr(callback = self.notify, maxjobs = 1) 271 self.queue = QueueMgr(callback = self.notify, maxjobs = 1)
263 272
264 while True: 273 while True: