@@ -8,7 +8,7 @@ import cdrtoc
from DIDLLite import MusicTrack, AudioItem, MusicAlbum, Resource, ResourceList
from DIDLLite import MusicTrack, AudioItem, MusicAlbum, Resource, ResourceList
from FSStorage import FSObject, registerklassfun
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 twisted.internet.interfaces import IPullProducer
from zope.interface import implements
from zope.interface import implements
@@ -98,6 +98,8 @@ class AudioResource(resource.Resource):
self.start = start
self.start = start
self.cnt = cnt
self.cnt = cnt
def __repr__(self):
return '<AudioResource file: %s, dec: %s, start:%d, cnt: %d>' % (`self.f`, self.dec, self.start, self.cnt)
def calcrange(self, rng, l):
def calcrange(self, rng, l):
rng = rng.strip()
rng = rng.strip()
unit, rangeset = rng.split('=')
unit, rangeset = rng.split('=')
@@ -153,7 +155,7 @@ class AudioResource(resource.Resource):
class AudioDisc(FSObject, MusicAlbum):
class AudioDisc(FSObject, MusicAlbum):
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs):
self.cuesheet = kwargs.pop('cuesheet')
self.cuesheet = kwargs.pop('cuesheet')
self.toc = kwargs.pop('toc', {})
self.cd toc = kwargs.pop('toc', {})
self.kwargs = kwargs.copy()
self.kwargs = kwargs.copy()
self.file = kwargs.pop('file')
self.file = kwargs.pop('file')
@@ -161,19 +163,37 @@ class AudioDisc(FSObject, MusicAlbum):
samprate = kwargs.pop('samplerate')
samprate = kwargs.pop('samplerate')
bitsps = kwargs.pop('bitspersample')
bitsps = kwargs.pop('bitspersample')
samples = kwargs.pop('samples')
samples = kwargs.pop('samples')
tags = kwargs.pop('tags', {})
picts = kwargs.pop('pictures', {})
totalbytes = nchan * samples * bitsps / 8
totalbytes = nchan * samples * bitsps / 8
FSObject.__init__(self, kwargs.pop('path'))
FSObject.__init__(self, kwargs.pop('path'))
# XXX - exclude track 1 pre-gap?
# 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'
#print 'doing construction'
MusicAlbum.__init__(self, *args, **kwargs)
MusicAlbum.__init__(self, *args, **kwargs)
#print 'adding resource'
#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()
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,
r = Resource(self.url, 'http-get:*:%s:*' % makeaudiomt(bitsps,
samprate, nchan))
samprate, nchan))
r.size = totalbytes
r.size = totalbytes
@@ -233,11 +253,22 @@ class AudioDisc(FSObject, MusicAlbum):
#print 'track: %d, kwargs: %s' % (i, `kwargs`)
#print 'track: %d, kwargs: %s' % (i, `kwargs`)
kwargs['originalTrackNumber'] = i
kwargs['originalTrackNumber'] = i
try:
try:
oi = self.toc['tracks'][i]['TITLE']
pass
tinfo = self.cdtoc['tracks'][i]
except KeyError:
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
return AudioRawTrack, oi, (), kwargs
# XXX - figure out how to make custom mix-ins w/ other than AudioItem
# XXX - figure out how to make custom mix-ins w/ other than AudioItem
@@ -250,16 +281,31 @@ class AudioRawBase(FSObject):
bitsps = kwargs.pop('bitspersample')
bitsps = kwargs.pop('bitspersample')
samples = kwargs.pop('samples')
samples = kwargs.pop('samples')
startsamp = kwargs.pop('start', 0)
startsamp = kwargs.pop('start', 0)
tags = kwargs.pop('tags', {})
picts = kwargs.pop('pictures', {})
totalbytes = nchan * samples * bitsps / 8
totalbytes = nchan * samples * bitsps / 8
FSObject.__init__(self, kwargs.pop('path'))
FSObject.__init__(self, kwargs.pop('path'))
#print 'AudioRaw:', `startsamp`, `samples`
#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.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()
self.res = ResourceList()
r = Resource(self.url, 'http-get:*:%s:*' % makeaudiomt(bitsps,
r = Resource(self.url, 'http-get:*:%s:*' % makeaudiomt(bitsps,
samprate, nchan))
samprate, nchan))
@@ -271,6 +317,13 @@ class AudioRawBase(FSObject):
r.nrAudioChannels = nchan
r.nrAudioChannels = nchan
self.res.append(r)
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):
class AudioRaw(AudioRawBase, AudioItem):
baseObject = AudioItem
baseObject = AudioItem
@@ -293,13 +346,20 @@ def detectaudioraw(origpath, fobj):
'samplerate': obj.samplerate,
'samplerate': obj.samplerate,
'bitspersample': obj.bitspersample,
'bitspersample': obj.bitspersample,
'samples': obj.totalsamples,
'samples': obj.totalsamples,
'tags': obj.tags,
'pictures': obj.pictures,
}
}
if obj.cuesheet is not None:
if obj.cuesheet is not None:
print 'tags:', `obj.tags`
if 'jmg_toc' in obj.tags:
try:
args['toc'] = cdrtoc.parsetoc(
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
args['cuesheet'] = obj.cuesheet
return AudioDisc, args
return AudioDisc, args