~ubuntu-branches/ubuntu/maverick/coherence/maverick

« back to all changes in this revision

Viewing changes to coherence/backends/flickr_storage.py

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2010-01-02 10:57:15 UTC
  • mfrom: (1.1.7 upstream) (3.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100102105715-sghzl2nw4lr5b1ob
Tags: 0.6.6.2-1
*  New  upstream release, summary of changes:
    - adding all necessary files to MANIFEST.in, to compensate for the
      gone 'auto-include-all-files-under-version-control' setuptools
      feature.
    - rearranging genre and genres attribute in DIDLLite - thx Caleb  
    - fix face_path typo, fixes #275.   

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from coherence.upnp.core.utils import parse_xml, ReverseProxyResource
35
35
 
36
36
from coherence.upnp.core.DIDLLite import classChooser,Container,PhotoAlbum,Photo,ImageItem,Resource,DIDLElement
37
 
from coherence.upnp.core.DIDLLite import simple_dlna_tags
 
37
from coherence.upnp.core.DIDLLite import simple_dlna_tags, PlayContainerResource
38
38
from coherence.upnp.core.soap_proxy import SOAPProxy
39
39
from coherence.upnp.core.soap_service import errorCode
40
40
 
41
41
from coherence.upnp.core.utils import getPage
42
42
from coherence.backend import BackendItem, BackendStore
43
43
 
44
 
import coherence.extern.louie as louie
45
 
 
46
44
from coherence.extern.simple_plugin import Plugin
47
45
 
48
46
from coherence import log
110
108
        self.id = id
111
109
        self.real_url = None
112
110
        self.obj = obj
 
111
        self.upnp_class = UPnPClass
113
112
        self.store = store
114
113
        self.item = None
115
114
        self.date = None
189
188
                        obj.get('secret').encode('utf-8'))
190
189
 
191
190
        if parent == None:
192
 
            parent_id = -1
 
191
            self.parent_id = -1
193
192
        else:
194
 
            parent_id = parent.get_id()
 
193
            self.parent_id = parent.get_id()
195
194
 
196
195
        if self.mimetype == 'directory':
197
 
            self.item = UPnPClass(self.id, parent_id, self.get_name())
198
 
            if isinstance(self.item, Container):
199
 
                self.item.childCount = 0
200
 
            self.child_count = 0
201
196
            self.children = []
202
197
            self.update_id = 0
203
198
 
229
224
 
230
225
    def add_child(self, child, update=False):
231
226
        self.children.append(child)
232
 
        self.child_count += 1
233
 
        if isinstance(self.item, Container):
234
 
            self.item.childCount += 1
235
227
        if update == True:
236
228
            self.update_id += 1
237
229
 
238
 
 
239
230
    def remove_child(self, child):
240
231
        self.info("remove_from %d (%s) child %d (%s)" % (self.id, self.get_name(), child.id, child.get_name()))
241
232
        if child in self.children:
242
 
            self.child_count -= 1
243
 
            if isinstance(self.item, Container):
244
 
                self.item.childCount -= 1
245
233
            self.children.remove(child)
246
234
            self.update_id += 1
247
235
 
252
240
            return self.children[start:request_count]
253
241
 
254
242
    def get_child_count(self):
255
 
        return self.child_count
 
243
        return len(self.children)
256
244
 
257
245
    def get_id(self):
258
246
        return self.id
288
276
 
289
277
    def get_item(self):
290
278
        if self.item == None:
291
 
            return self.create_item()
 
279
            if self.mimetype == 'directory':
 
280
                self.item = self.upnp_class(self.id, self.parent_id, self.get_name())
 
281
                self.item.childCount = self.get_child_count()
 
282
                if self.get_child_count() > 0:
 
283
                    res = PlayContainerResource(self.store.server.uuid,cid=self.get_id(),fid=self.get_children()[0].get_id())
 
284
                    self.item.res.append(res)
 
285
            else:
 
286
                return self.create_item()
292
287
        return self.item
293
288
 
294
289
    def create_item(self):
297
292
                #print size.get('label'), size.get('source')
298
293
                if size.get('label') == 'Original':
299
294
                    self.original_url = (size.get('source'),size.get('width')+'x'+size.get('height'))
300
 
                    self.url = self.original_url[0]
 
295
                    if self.store.proxy == False:
 
296
                        self.url = self.original_url[0]
 
297
                    else:
 
298
                        self.location = ProxyImage(self.original_url[0])
301
299
                elif size.get('label') == 'Large':
302
300
                    self.large_url = (size.get('source'),size.get('width')+'x'+size.get('height'))
303
 
                    self.url = self.large_url[0]
 
301
                    if self.store.proxy == False:
 
302
                        self.url = self.large_url[0]
 
303
                    else:
 
304
                        self.location = ProxyImage(self.large_url[0])
304
305
                elif size.get('label') == 'Medium':
305
306
                    self.medium_url = (size.get('source'),size.get('width')+'x'+size.get('height'))
306
307
                elif size.get('label') == 'Small':
309
310
                    self.thumb_url = (size.get('source'),size.get('width')+'x'+size.get('height'))
310
311
 
311
312
            self.item = Photo(self.id,self.parent.get_id(),self.get_name())
 
313
            #print self.id, self.store.proxy, self.url
312
314
            self.item.date = self.date
 
315
            self.item.attachments = {}
313
316
            dlna_tags = simple_dlna_tags[:]
314
317
            dlna_tags[3] = 'DLNA.ORG_FLAGS=00f00000000000000000000000000000'
315
318
            if hasattr(self,'original_url'):
316
319
                dlna_pn = 'DLNA.ORG_PN=JPEG_LRG'
317
 
                res = Resource(self.original_url[0], 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
320
                if self.store.proxy == False:
 
321
                    res = Resource(self.original_url[0], 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
322
                else:
 
323
                    res = Resource(self.url+'?attachment=original', 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
324
                    self.item.attachments['original'] = ProxyImage(self.original_url[0])
318
325
                res.resolution = self.original_url[1]
319
326
                self.item.res.append(res)
320
327
            elif hasattr(self,'large_url'):
321
328
                dlna_pn = 'DLNA.ORG_PN=JPEG_LRG'
322
 
                res = Resource(self.large_url[0], 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
329
                if self.store.proxy == False:
 
330
                    res = Resource(self.large_url[0], 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
331
                else:
 
332
                    res = Resource(self.url+'?attachment=large', 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
333
                    self.item.attachments['large'] = ProxyImage(self.large_url[0])
323
334
                res.resolution = self.large_url[1]
324
335
                self.item.res.append(res)
325
336
            if hasattr(self,'medium_url'):
326
337
                dlna_pn = 'DLNA.ORG_PN=JPEG_MED'
327
 
                res = Resource(self.medium_url[0], 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
338
                if self.store.proxy == False:
 
339
                    res = Resource(self.medium_url[0], 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
340
                else:
 
341
                    res = Resource(self.url+'?attachment=medium', 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
342
                    self.item.attachments['medium'] = ProxyImage(self.medium_url[0])
328
343
                res.resolution = self.medium_url[1]
329
344
                self.item.res.append(res)
330
345
            if hasattr(self,'small_url'):
331
346
                dlna_pn = 'DLNA.ORG_PN=JPEG_SM'
332
 
                res = Resource(self.small_url[0], 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
347
                if self.store.proxy == False:
 
348
                    res = Resource(self.small_url[0], 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
349
                else:
 
350
                    res = Resource(self.url+'?attachment=small', 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
351
                    self.item.attachments['small'] = ProxyImage(self.small_url[0])
333
352
                res.resolution = self.small_url[1]
334
353
                self.item.res.append(res)
335
354
            if hasattr(self,'thumb_url'):
336
355
                dlna_pn = 'DLNA.ORG_PN=JPEG_TN'
337
 
                res = Resource(self.thumb_url[0], 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
356
                if self.store.proxy == False:
 
357
                    res = Resource(self.thumb_url[0], 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
358
                else:
 
359
                    res = Resource(self.url+'?attachment=thumb', 'http-get:*:%s:%s' % (self.mimetype,';'.join([dlna_pn]+dlna_tags)))
 
360
                    self.item.attachments['thumb'] = ProxyImage(self.thumb_url[0])
338
361
                res.resolution = self.thumb_url[1]
339
362
                self.item.res.append(res)
340
363
 
402
425
           self.server.coherence.writeable_config() == True):
403
426
            if not None in (self.flickr_userid,self.flickr_password):
404
427
                d = self.flickr_authenticate_app()
405
 
                d.addBoth(lambda x: louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self))
406
 
        else:
407
 
            louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
 
428
                d.addBoth(lambda x: self.init_completed())
 
429
                return
 
430
            
 
431
        self.init_completed()
408
432
 
409
433
    def __repr__(self):
410
434
        return str(self.__class__).split('.')[-1]
749
773
        return d
750
774
 
751
775
    def flickr_photos_getSizes(self, photo_id=None):
752
 
        d = self.flickr_call('flickr.photos.getSizes', photo_id=photo_id)
 
776
        if self.flickr_authtoken != None:
 
777
            api_sig = self.flickr_create_api_signature(auth_token=self.flickr_authtoken,method='flickr.photos.getSizes', photo_id=photo_id)
 
778
            d = self.flickr_call('flickr.photos.getSizes', auth_token=self.flickr_authtoken, photo_id=photo_id,api_sig=api_sig)
 
779
        else:
 
780
            api_sig = self.flickr_create_api_signature(method='flickr.photos.getSizes', photo_id=photo_id)
 
781
            d = self.flickr_call('flickr.photos.getSizes',photo_id=photo_id,api_sig=api_sig)
753
782
        return d
754
783
 
755
 
 
756
784
    def flickr_interestingness(self, date=None, per_page=100):
757
785
        if date == None:
758
786
            date = time.strftime( "%Y-%m-%d", time.localtime(time.time()-86400))