~ubuntu-branches/ubuntu/lucid/coherence/lucid

« back to all changes in this revision

Viewing changes to coherence/backends/mediadb_storage.py

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2009-05-13 00:34:24 UTC
  • mfrom: (1.1.6 upstream) (3.2.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090513003424-gvdr7y6msehcisoz
Tags: 0.6.4-1
* New upstream release.  Summary of changes.
    - new MediaServer backends that allow access to Picasa Web Albums
    - a TestServer to easily serve and test interaction with, 
        - one or more items and adjust 'upnp_class', 'mimetype'and 'DLNA-flags
        - items that are a GStreamer pipeline or an external program.
    - a new, used in parallel, D-Bus API with an 'org.DLNA' interface with the
      goal to create a common API for all UPnP/DNLA frameworks
    - support for the dlna-playcontainer URI
    - enchancements to the GStreamer MediaRenderer, supporting now
      dlna-playcontainer and SetNextAVTransportURI, and jumping to previous
      and next tracks
    - support for video items served by Ampache
    - base classes for a ScheduledRecording? service
    - some 'compatibility' adjustments for different devices
* Removed MochiKit symbolic link creation from debian/rules.
* Removed dependency on MochiKit in debian/control.

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
    f = f.replace(badchars, '_')
140
140
    return f
141
141
 
 
142
 
142
143
class Container(BackendItem):
143
144
 
144
145
    get_path = None
145
146
 
146
 
    def __init__(self, id, parent_id, name, children_callback=None):
 
147
    def __init__(self, id, parent_id, name, children_callback=None,store=None,play_container=False):
147
148
        self.id = id
148
149
        self.parent_id = parent_id
149
150
        self.name = name
150
151
        self.mimetype = 'directory'
151
 
        self.item = DIDLLite.Container(id, parent_id,self.name)
 
152
        self.store = store
 
153
        self.play_container = play_container
152
154
        self.update_id = 0
153
155
        if children_callback != None:
154
156
            self.children = children_callback
155
157
        else:
156
158
            self.children = []
157
 
        self.item.childCount = self.get_child_count()
158
159
 
159
160
    def add_child(self, child):
160
161
        self.children.append(child)
161
 
        self.item.childCount += 1
162
162
 
163
163
    def get_children(self,start=0,request_count=0):
164
164
        if callable(self.children):
177
177
            return len(self.children)
178
178
 
179
179
    def get_item(self):
180
 
        return self.item
 
180
        item = DIDLLite.Container(self.id, self.parent_id,self.name)
 
181
        item.childCount = self.get_child_count()
 
182
        if self.store and self.play_container == True:
 
183
            if item.childCount > 0:
 
184
                res = DIDLLite.PlayContainerResource(self.store.server.uuid,cid=self.get_id(),fid=self.get_children()[0].get_id())
 
185
                item.res.append(res)
 
186
        return item
181
187
 
182
188
    def get_name(self):
183
189
        return self.name
185
191
    def get_id(self):
186
192
        return self.id
187
193
 
 
194
 
188
195
class Artist(item.Item,BackendItem):
189
196
    """ definition for an artist """
190
197
 
212
219
        all_id = 'artist_all_tracks_%d' % (self.storeID+1000)
213
220
        self.store.containers[all_id] = \
214
221
                Container( all_id, self.storeID+1000, 'All tracks of %s' % self.name,
215
 
                          children_callback=self.get_artist_all_tracks)
 
222
                          children_callback=self.get_artist_all_tracks,
 
223
                          store=self.store,play_container=True)
216
224
 
217
225
        children = [self.store.containers[all_id]] + list(self.store.query(Album, Album.artist == self,sort=Album.title.ascending))
218
226
        if request_count == 0:
238
246
        return '<Artist %d name="%s" musicbrainz="%s">' \
239
247
               % (self.storeID, self.name.encode('ascii', 'ignore'), self.musicbrainz_id)
240
248
 
 
249
 
241
250
class Album(item.Item,BackendItem):
242
251
    """ definition for an album """
243
252
 
270
279
        if len(self.cover)>0:
271
280
            _,ext =  os.path.splitext(self.cover)
272
281
            item.albumArtURI = ''.join((self.store.urlbase,str(self.get_id()),'?cover',ext))
 
282
 
 
283
        if self.get_child_count() > 0:
 
284
            res = DIDLLite.PlayContainerResource(self.store.server.uuid,cid=self.get_id(),fid=self.get_children()[0].get_id())
 
285
            item.res.append(res)
273
286
        return item
274
287
 
275
288
    def get_id(self):
289
302
                  self.cover.encode('ascii', 'ignore'),
290
303
                  self.musicbrainz_id)
291
304
 
 
305
 
292
306
class Track(item.Item,BackendItem):
293
307
    """ definition for a track """
294
308
 
406
420
                  self.album.artist.name.encode('ascii', 'ignore'),
407
421
                  self.location.encode('ascii', 'ignore'))
408
422
 
 
423
 
409
424
class Playlist(item.Item,BackendItem):
410
425
    """ definition for a playlist
411
426
 
424
439
 
425
440
    get_path = None
426
441
 
 
442
 
427
443
class MediaStore(BackendStore):
428
444
    logCategory = 'media_store'
429
445
    implements = ['MediaServer']
430
446
 
431
447
    def __init__(self, server, **kwargs):
 
448
        BackendStore.__init__(self,server,**kwargs)
432
449
        self.info("MediaStore __init__")
433
 
        self.server = server
434
450
        self.update_id = 0
435
451
 
436
452
        self.medialocation = kwargs.get('medialocation','tests/content/audio')
441
457
 
442
458
        self.name = kwargs.get('name','MediaStore')
443
459
 
444
 
        self.urlbase = kwargs.get('urlbase','')
445
 
        if( len(self.urlbase)>0 and
446
 
            self.urlbase[len(self.urlbase)-1] != '/'):
447
 
            self.urlbase += '/'
448
 
 
449
460
        self.containers = {}
450
461
        self.containers[ROOT_CONTAINER_ID] = \
451
462
                Container( ROOT_CONTAINER_ID,-1, self.name)
635
646
 
636
647
        self.containers[AUDIO_ALL_CONTAINER_ID] = \
637
648
                Container( AUDIO_ALL_CONTAINER_ID,ROOT_CONTAINER_ID, 'All tracks',
638
 
                          children_callback=lambda :list(self.db.query(Track,sort=Track.title.ascending)))
 
649
                          children_callback=lambda :list(self.db.query(Track,sort=Track.title.ascending)),
 
650
                          store=self,play_container=True)
639
651
        self.containers[ROOT_CONTAINER_ID].add_child(self.containers[AUDIO_ALL_CONTAINER_ID])
640
652
        self.containers[AUDIO_ALBUM_CONTAINER_ID] = \
641
653
                Container( AUDIO_ALBUM_CONTAINER_ID,ROOT_CONTAINER_ID, 'Albums',