From acb08047545bac48e87c760ca2a396324a659fe4 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Fri, 7 Dec 2012 00:23:00 -0800 Subject: [PATCH] support cover art... rename toc to cdtoc so that we don't send it as part of the entry.. add year and genre too... there are two ways to get the title, one seems to work some of the time, the second one I need to find the disc that it doesn't work.. leave it commented out for now.. [git-p4: depot-paths = "//depot/": change = 1669] --- audioraw.py | 88 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 14 deletions(-) diff --git a/audioraw.py b/audioraw.py index ecd9e19..a54e6a8 100644 --- a/audioraw.py +++ b/audioraw.py @@ -8,7 +8,7 @@ import cdrtoc from DIDLLite import MusicTrack, AudioItem, MusicAlbum, Resource, ResourceList from FSStorage import FSObject, registerklassfun -from twisted.web import resource, server +from twisted.web import resource, server, static from twisted.internet.interfaces import IPullProducer from zope.interface import implements @@ -98,6 +98,8 @@ class AudioResource(resource.Resource): self.start = start self.cnt = cnt + def __repr__(self): + return '' % (`self.f`, self.dec, self.start, self.cnt) def calcrange(self, rng, l): rng = rng.strip() unit, rangeset = rng.split('=') @@ -153,7 +155,7 @@ class AudioResource(resource.Resource): class AudioDisc(FSObject, MusicAlbum): def __init__(self, *args, **kwargs): self.cuesheet = kwargs.pop('cuesheet') - self.toc = kwargs.pop('toc', {}) + self.cdtoc = kwargs.pop('toc', {}) self.kwargs = kwargs.copy() self.file = kwargs.pop('file') @@ -161,19 +163,37 @@ class AudioDisc(FSObject, MusicAlbum): samprate = kwargs.pop('samplerate') bitsps = kwargs.pop('bitspersample') samples = kwargs.pop('samples') + tags = kwargs.pop('tags', {}) + picts = kwargs.pop('pictures', {}) totalbytes = nchan * samples * bitsps / 8 FSObject.__init__(self, kwargs.pop('path')) # XXX - exclude track 1 pre-gap? - kwargs['content'] = AudioResource(self.file, - kwargs.pop('decoder'), 0, samples) + kwargs['content'] = cont = resource.Resource() + cont.putChild('audio', AudioResource(file, + kwargs.pop('decoder'), 0, samples)) #print 'doing construction' MusicAlbum.__init__(self, *args, **kwargs) #print 'adding resource' - self.url = '%s/%s' % (self.cd.urlbase, self.id) + self.url = '%s/%s/audio' % (self.cd.urlbase, self.id) + if 'cover' in picts: + pict = picts['cover'][0] + #print 'p:', `pict` + cont.putChild('cover', static.Data(pict[7], pict[1])) + self.albumArtURI = '%s/%s/cover' % (self.cd.urlbase, + self.id) + self.res = ResourceList() + if 'DYEAR' in tags: + self.year = tags['DYEAR'] + if 'DGENRE' in tags: + self.genre = tags['DGENRE'] + #if 'DTITLE' in tags: + # self.artist, self.album = tags['DTITLE'][0].split(' / ', 1) + self.url = '%s/%s/audio' % (self.cd.urlbase, self.id) + r = Resource(self.url, 'http-get:*:%s:*' % makeaudiomt(bitsps, samprate, nchan)) r.size = totalbytes @@ -233,11 +253,22 @@ class AudioDisc(FSObject, MusicAlbum): #print 'track: %d, kwargs: %s' % (i, `kwargs`) kwargs['originalTrackNumber'] = i try: - oi = self.toc['tracks'][i]['TITLE'] - pass + tinfo = self.cdtoc['tracks'][i] except KeyError: - pass + tinfo = {} + if 'TITLE' in self.cdtoc: + kwargs['album'] = self.cdtoc['TITLE'] + + if 'TITLE' in tinfo: + oi = tinfo['TITLE'] + + if 'PERFORMER' in tinfo: + kwargs['artist'] = tinfo['PERFORMER'] + + print 'kwargs:', `kwargs` + import traceback + traceback.print_stack() return AudioRawTrack, oi, (), kwargs # XXX - figure out how to make custom mix-ins w/ other than AudioItem @@ -250,16 +281,31 @@ class AudioRawBase(FSObject): bitsps = kwargs.pop('bitspersample') samples = kwargs.pop('samples') startsamp = kwargs.pop('start', 0) + tags = kwargs.pop('tags', {}) + picts = kwargs.pop('pictures', {}) totalbytes = nchan * samples * bitsps / 8 FSObject.__init__(self, kwargs.pop('path')) #print 'AudioRaw:', `startsamp`, `samples` - kwargs['content'] = AudioResource(file, - kwargs.pop('decoder'), startsamp, samples) + kwargs['content'] = cont = resource.Resource() + cont.putChild('audio', AudioResource(file, + kwargs.pop('decoder'), startsamp, samples)) self.baseObject.__init__(self, *args, **kwargs) - self.url = '%s/%s' % (self.cd.urlbase, self.id) + if 'DYEAR' in tags: + self.year = tags['DYEAR'][0] + if 'DGENRE' in tags: + self.genre = tags['DGENRE'][0] + #if 'DTITLE' in tags: + # self.artist, self.album = tags['DTITLE'][0].split(' / ', 1) + self.url = '%s/%s/audio' % (self.cd.urlbase, self.id) + if 'cover' in picts: + pict = picts['cover'][0] + cont.putChild('cover', static.Data(pict[7], pict[1])) + self.albumArtURI = '%s/%s/cover' % (self.cd.urlbase, + self.id) + self.res = ResourceList() r = Resource(self.url, 'http-get:*:%s:*' % makeaudiomt(bitsps, samprate, nchan)) @@ -271,6 +317,13 @@ class AudioRawBase(FSObject): r.nrAudioChannels = nchan self.res.append(r) + def doUpdate(self): + print 'dU:', `self`, self.baseObject.doUpdate + print self.__class__.__bases__ + import traceback + traceback.print_stack() + self.baseObject.doUpdate(self) + class AudioRaw(AudioRawBase, AudioItem): baseObject = AudioItem @@ -293,13 +346,20 @@ def detectaudioraw(origpath, fobj): 'samplerate': obj.samplerate, 'bitspersample': obj.bitspersample, 'samples': obj.totalsamples, + 'tags': obj.tags, + 'pictures': obj.pictures, } if obj.cuesheet is not None: - print 'tags:', `obj.tags` - if 'jmg_toc' in obj.tags: + try: args['toc'] = cdrtoc.parsetoc( - obj.tags['jmg_toc'][0]) + obj.tags['cd.toc'][0]) + except KeyError: + pass + except: + import traceback + print 'WARNING: failed to parse toc:' + traceback.print_exc() args['cuesheet'] = obj.cuesheet return AudioDisc, args