Esempio n. 1
0
    def __init__(self, parent_id, id, title, url):
        BackendItem.__init__(self)
        self.parentid = parent_id  # used to be able to 'go back'

        self.update_id = 0

        self.id = id  # each item has its own and unique id

        self.location = url  # the url of the picture

        self.name = title  # the title of the picture. Inside
        # coherence this is called 'name'

        # Item.item is a special thing. This is used to explain the client what
        # kind of data this is. For e.g. A VideoItem or a MusicTrack. In our
        # case, we have an image.
        self.item = DIDLLite.ImageItem(id, parent_id, self.name)

        # each Item.item has to have one or more Resource objects
        # these hold detailed information about the media data
        # and can represent variants of it (different sizes, transcoded formats)
        res = DIDLLite.Resource(self.location, 'http-get:*:image/jpeg:*')
        res.size = None  # FIXME: we should have a size here
        #       and a resolution entry would be nice too
        self.item.res.append(res)
Esempio n. 2
0
	def __init__(self, parent, id, title, pid):
		self.parentid = parent.id	   # used to be able to 'go back'
		self.parent = parent

		top_parent = parent
		while not isinstance(top_parent, BackendStore):
			top_parent = top_parent.parent
		
		self.store = top_parent
		self.update_id = 0

		self.id = id					# each item has its own and unique id

		self.url = self.store.urlbase + pid
		self.location = TestVideoProxy(self, self.url, pid,
								self.store.cache_directory, self.store.cache_maxsize,self.store.buffer_size)

		self.name = unicode(title,"utf8","ignore")   # the title of the picture. Inside
										# coherence this is called 'name'


		# Item.item is a special thing. This is used to explain the client what
		# kind of data this is. For e.g. A VideoItem or a MusicTrack.
		self.item = DIDLLite.VideoItem(id, parent.id, self.name)

		# each Item.item has to have one or more Resource objects
		# these hold detailed information about the media data
		# and can represent variants of it (different sizes, transcoded formats)
		res = DIDLLite.Resource(self.url, 'http-get:*:video/quicktime:*')
		res.size = None #FIXME: we should have a size here
						#	   and a resolution entry would be nice too
		self.item.res.append(res)
Esempio n. 3
0
    def get_item(self):
        if self.item is None:
            upnp_id = self.get_id()
            upnp_parent_id = self.parent.get_id()
            self.item = DIDLLite.Movie(upnp_id, upnp_parent_id,
                                       self.upnp_title)
            self.item.album = None
            self.item.albumArtURI = self.posterURL
            self.item.artist = None
            self.item.creator = self.director
            self.item.date = self.year
            self.item.description = self.plot
            self.item.director = self.director
            self.item.longDescription = self.outline
            self.item.originalTrackNumber = None
            self.item.restricted = None
            self.item.title = self.upnp_title
            self.item.writeStatus = 'PROTECTED'
            self.item.icon = self.thumbnailURL
            self.item.genre = None
            self.item.genres = self.str_genres
            self.item.language = self.language
            self.item.actors = self.str_actors

            res = DIDLLite.Resource(self.movie_url,
                                    f'http-get:*:{self.mimetype}:*')
            res.duration = self.duration
            res.size = self.size
            res.nrAudioChannels = self.audioChannels
            res.resolution = self.resolution
            self.item.res.append(res)
        return self.item
Esempio n. 4
0
    def get_item(self, parent_id=None):

        self.debug(f'Recording get_item {self.id} @ {self.parent_id}')

        # create item
        item = DIDLLite.VideoBroadcast(self.id, self.parent_id)
        item.date = self.date
        item.title = self.title

        # add http resource
        res = DIDLLite.Resource(self.url, f'http-get:*:{self.mimetype}:*')
        if self.size > 0:
            res.size = self.size
        if self.duration > 0:
            res.duration = str(self.duration)
        if self.bitrate > 0:
            res.bitrate = str(self.bitrate)
        item.res.append(res)

        # add internal resource
        res = DIDLLite.Resource(
            'file://' + urllib.parse.quote(self.get_path()),
            f'internal:{self.store.server.coherence.hostname}:'
            f'{self.mimetype}:*',
        )
        if self.size > 0:
            res.size = self.size
        if self.duration > 0:
            res.duration = str(self.duration)
        if self.bitrate > 0:
            res.bitrate = str(self.bitrate)
        item.res.append(res)

        return item
Esempio n. 5
0
 def get_item(self, parent_id=None):
     self.debug("Channel get_item %r @ %r" %(self.id,self.parent_id))
     item = DIDLLite.VideoBroadcast(self.id,self.parent_id)
     item.title = self.name
     res = DIDLLite.Resource(self.stream_url, 'rtsp-rtp-udp:*:%s:*' % self.mimetype)
     item.res.append(res)
     return item
Esempio n. 6
0
    def get_item(self, parent_id=None):

        self.debug("Track get_item %r @ %r", self.id, self.parent_id)

        # create item
        item = DIDLLite.MusicTrack(self.id, self.parent_id)
        item.album = self.album

        item.artist = self.artist
        #item.date =
        item.genre = self.genre
        item.originalTrackNumber = self.track_nr
        item.title = self.title

        item.albumArtURI = self.cover

        # add http resource
        res = DIDLLite.Resource(self.get_url(),
                                'http-get:*:%s:*' % self.mimetype)
        if self.size > 0:
            res.size = self.size
        if self.duration > 0:
            res.duration = str(self.duration)
        if self.bitrate > 0:
            res.bitrate = str(bitrate)
        item.res.append(res)

        return item
Esempio n. 7
0
 def get_item(self):
     item = DIDLLite.PlaylistContainer(self.id, AUDIO_PLAYLIST_CONTAINER_ID, self.title)
     if __version_info__ >= (0,6,4):
         if self.get_child_count() > 0:
             res = DIDLLite.PlayContainerResource(self.store.server.uuid,cid=self.get_id(),fid=str(TRACK_COUNT+int(self.get_children()[0].get_id())))
             item.res.append(res)
     return item
Esempio n. 8
0
    def __init__(self, store, parent, id, title, enclosure):
        BackendItem.__init__(self)
        self.store = store
        self.parent = parent
        self.external_id = id
        self.name = title
        self.location = RedirectingReverseProxyUriResource(
            enclosure.url.encode('latin-1'))

        # doing this because some (Fraunhofer Podcast) feeds say there mime type is audio/x-mpeg
        # which at least my XBOX doesn't like
        ext = enclosure.url.rsplit('.', 1)[0]
        if ext in MIME_TYPES_EXTENTION_MAPPING:
            mime_type = MIME_TYPES_EXTENTION_MAPPING[ext]
        else:
            mime_type = enclosure.type
        if (enclosure.type.startswith('audio')):
            self.item = DIDLLite.AudioItem(id, parent, self.name)
        elif (enclosure.type.startswith('video')):
            self.item = DIDLLite.VideoItem(id, parent, self.name)
        elif (enclosure.type.startswith('image')):
            self.item = DIDLLite.ImageItem(id, parent, self.name)

        res = DIDLLite.Resource("%s%d" % (store.urlbase, id),
                                'http-get:*:%s:*' % mime_type)

        self.item.res.append(res)
Esempio n. 9
0
    def get_item(self, parent_id=None):

        self.debug("Recording get_item %r @ %r" %(self.id,self.parent_id))

        # create item
        item = DIDLLite.VideoBroadcast(self.id,self.parent_id)
        item.date = self.date
        item.title = self.title

        # add http resource
        res = DIDLLite.Resource(self.url, 'http-get:*:%s:*' % self.mimetype)
        if self.size > 0:
            res.size = self.size
        if self.duration > 0:
            res.duration = str(self.duration)
        if self.bitrate > 0:
            res.bitrate = str(bitrate)
        item.res.append(res)

        # add internal resource
        res = DIDLLite.Resource('file://'+ urllib.quote(self.get_path()), 'internal:%s:%s:*' % (self.store.server.coherence.hostname,self.mimetype))
        if self.size > 0:
            res.size = self.size
        if self.duration > 0:
            res.duration = str(self.duration)
        if self.bitrate > 0:
            res.bitrate = str(bitrate)
        item.res.append(res)

        return item
Esempio n. 10
0
 def get_item(self):
     item = DIDLLite.Container(self.id, self.parent_id, self.name)
     item.childCount = self.get_child_count()
     if self.store and self.play_container == True:
         if item.childCount > 0:
             res = DIDLLite.PlayContainerResource(self.store.server.uuid, cid=self.get_id(), fid=self.get_children()[0].get_id())
             item.res.append(res)
     return item
Esempio n. 11
0
    def get_item(self, parent_id = AUDIO_ALBUM_CONTAINER_ID):
        item = DIDLLite.MusicAlbum(self.id, parent_id, self.title)

        if __version_info__ >= (0,6,4):
            if self.get_child_count() > 0:
                res = DIDLLite.PlayContainerResource(self.store.server.uuid,cid=self.get_id(),fid=str(TRACK_COUNT+int(self.get_children()[0].get_id())))
                item.res.append(res)
        return item
Esempio n. 12
0
 def get_item(self, parent_id=None):
     self.debug(f'Channel get_item {self.id} @ {self.parent_id}')
     item = DIDLLite.VideoBroadcast(self.id, self.parent_id)
     item.title = self.name
     res = DIDLLite.Resource(self.stream_url,
                             f'rtsp-rtp-udp:*:{self.mimetype}:*')
     item.res.append(res)
     return item
Esempio n. 13
0
 def get_item(self):
     if self.item is None:
         upnp_id = self.get_id()
         upnp_parent_id = self.parent.get_id()
         self.item = DIDLLite.Photo(upnp_id, upnp_parent_id, self.name)
         res = DIDLLite.Resource(self.url, f'http-get:*:{self.mimetype}:*')
         self.item.res.append(res)
     self.item.childCount = 0
     return self.item
Esempio n. 14
0
    def get_item(self):
        if self.item == None:
            self.item = DIDLLite.AudioItem(self.id, self.parent_id, self.name)
            self.item.description = self.description

            res = DIDLLite.Resource(self.location, 'http-get:*:%s:*' % self.mimetype)
            res.duration = self.duration
            res.size = self.size
            self.item.res.append(res)
        return self.item
Esempio n. 15
0
 def get_item(self):
     if self.item is None:
         self.item = DIDLLite.VideoItem(self.id, self.parent.id, self.name)
         self.item.description = self.description
         self.item.date = self.date
         res = DIDLLite.Resource(self.url, f'http-get:*:{self.mimetype}:*')
         res.duration = self.duration
         # res.size = 0 #None
         self.item.res.append(res)
     return self.item
Esempio n. 16
0
    def get_item(self, parent_id=None):

        self.debug(f'Track get_item {self.id} @ {self.parent_id}')

        # create item
        item = DIDLLite.MusicTrack(self.id, self.parent_id)
        item.album = self.album

        item.artist = self.artist
        # item.date =
        item.genre = self.genre
        item.originalTrackNumber = self.track_nr
        item.title = self.title

        item.albumArtURI = self.cover

        # add http resource
        res = DIDLLite.Resource(self.url, f'http-get:*:{self.mimetype}:*')
        if self.size > 0:
            res.size = self.size
        if self.duration > 0:
            res.duration = str(self.duration)
        if self.bitrate > 0:
            res.bitrate = str(self.bitrate)
        item.res.append(res)
        # if self.store.server.coherence.config.get(
        #        'transcoding', 'no') == 'yes':
        #     if self.mimetype in ('audio/mpeg',
        #                          'application/ogg','audio/ogg',
        #                          'audio/x-m4a',
        #                          'application/x-flac'):
        #         dlna_pn = 'DLNA.ORG_PN=LPCM'
        #         dlna_tags = DIDLLite.simple_dlna_tags[:]
        #         dlna_tags[1] = 'DLNA.ORG_CI=1'
        #         #dlna_tags[2] = 'DLNA.ORG_OP=00'
        #         new_res = DIDLLite.Resource(self.url+'?transcoded=lpcm',
        #             'http-get:*:%s:%s' % (
        #                'audio/L16;rate=44100;channels=2', ';'.join(
        #                    [dlna_pn]+dlna_tags)))
        #         new_res.size = None
        #         if self.duration > 0:
        #             new_res.duration = str(self.duration)
        #         item.res.append(new_res)
        #
        #         if self.mimetype != 'audio/mpeg':
        #             new_res = DIDLLite.Resource(
        #                 self.url+'?transcoded=mp3',
        #                 f'http-get:*:{"audio/mpeg"}:*')
        #             new_res.size = None
        #             if self.duration > 0:
        #                 new_res.duration = str(self.duration)
        #             item.res.append(new_res)

        return item
Esempio n. 17
0
    def get_item(self):
        item = DIDLLite.MusicAlbum(self.storeID + 1000, AUDIO_ALBUM_CONTAINER_ID, self.title)
        item.artist = self.artist.name
        item.childCount = self.get_child_count()
        if len(self.cover) > 0:
            _, ext = os.path.splitext(self.cover)
            item.albumArtURI = ''.join((self.store.urlbase, str(self.get_id()), '?cover', ext))

        if self.get_child_count() > 0:
            res = DIDLLite.PlayContainerResource(self.store.server.uuid, cid=self.get_id(), fid=self.get_children()[0].get_id())
            item.res.append(res)
        return item
Esempio n. 18
0
    def get_item(self):
        if self.item == None:
            upnp_id = self.storage_id
            upnp_parent_id = self.parent.get_id()
            url = self.store.urlbase + str(self.storage_id)
            self.item = DIDLLite.MusicTrack(upnp_id, upnp_parent_id, self.title)

            res = DIDLLite.Resource(url, 'http-get:*:%s:%s' % (self.mimetype, self.fourth_field))
            #res.duration = self.duration
            #res.size = self.get_size()
            self.item.res.append(res)
        return self.item
Esempio n. 19
0
    def get_item(self):
        if self.item == None:
            upnp_id = self.storage_id
            upnp_parent_id = self.parent.get_id()
            url = self.store.urlbase + str(self.storage_id)
            self.item = DIDLLite.MusicTrack(upnp_id, upnp_parent_id, self.name)

            res = DIDLLite.Resource(url, 'http-get:*:%s:*' % (self.mimetype))
            self.item.res.append(res)
            self.item.artist = self.track[u'artist'][0]
            self.item.album = self.track[u'album'][0]
            self.item.originalTrackNumber = self.track[u'tracknumber'][0]
        return self.item
Esempio n. 20
0
  def get_item(self):
    if self.item is None:
      upnp_id = self.get_id()
      upnp_parent_id = self.parent.get_id()

      self.item = DIDLLite.VideoItem(upnp_id, upnp_parent_id, self.name)
      self.item.description = self.status
      self.item.longDescription = self.status
      self.item.date = self.created_at
      self.item.albumArtURI = self.preview_url

      res = DIDLLite.Resource(self.url, 'http-get:*:%s:#' % MPEG_MIME)
      self.item.res.append(res)
    return self.item
Esempio n. 21
0
    def get_item(self):
        if self.item == None:
            self.item = DIDLLite.AudioItem(self.id, self.parent.id, self.name)
            self.item.description = self.description
            self.item.date = self.date

            if hasattr(self.parent, 'cover'):
                self.item.albumArtURI = self.parent.cover

            res = DIDLLite.Resource(self.location, 'http-get:*:%s:*' % self.mimetype)
            res.duration = self.duration
            res.size = self.size
            self.item.res.append(res)
        return self.item
Esempio n. 22
0
 def get_item(self):
     if self.item == None:
         self.item = DIDLLite.VideoBroadcast(self.get_id(),
                                             self.parent.get_id(),
                                             self.name,
                                             restricted=True)
         self._set_item_defaults(searchClass="object.item.videoItem")
         mimetype = "video/mpeg"
         additional_info = DLNA.getParams(mimetype)
         res = DIDLLite.Resource(
             self.get_path(),
             'http-get:*:%s:%s' % (mimetype, additional_info))
         res.size = None
         self.item.res.append(res)
     return self.item
Esempio n. 23
0
    def get_item(self, parent_id=None):
        self.debug(f'Image get_item {self.id} @ {self.parent_id}')

        # create item
        item = DIDLLite.ImageItem(self.id, self.parent_id)
        # item.date =
        item.title = self.title

        # add http resource
        res = DIDLLite.Resource(self.url, f'http-get:*:{self.mimetype}:*')
        if self.size > 0:
            res.size = self.size
        item.res.append(res)

        return item
Esempio n. 24
0
 def get_item(self):
     if self.item == None:
         upnp_id = self.get_id()
         upnp_parent_id = self.parent.get_id()
         self.item = DIDLLite.VideoItem(upnp_id, upnp_parent_id, self.name)
         self.item.description = self.description
         self.item.date = self.date
         if self.thumbnail_url is not None:
             self.item.icon = self.thumbnail_url
             self.item.albumArtURI = self.thumbnail_url
         res = DIDLLite.Resource(self.url, 'http-get:*:%s:*' % self.mimetype)
         res.duration = self.duration
         res.size = self.size
         self.item.res.append(res)
     return self.item
Esempio n. 25
0
    def update(self, message=None):
        current = self.player.getState()
        self.debug("update current %r", current)
        connection_manager = self.server.connection_manager_server
        av_transport = self.server.av_transport_server
        conn_id = connection_manager.lookup_avt_id(self.current_connection_id)

        if current in (self.STATE_PLAYING, self.STATE_PAUSED):
            self._update_transport_state(current)
        elif self.playcontainer != None and message == self.MESSAGE_EOF and \
         self.playcontainer[0] + 1 < len(self.playcontainer[2]):

            self._transition()
            next_track = ()
            item = self.playcontainer[2][self.playcontainer[0] + 1]
            infos = connection_manager.get_variable('SinkProtocolInfo')
            local_protocol_infos = infos.value.split(',')
            res = item.res.get_matching(local_protocol_infos)
            if len(res) > 0:
                res = res[0]
                infos = res.protocolInfo.split(':')
                remote_protocol, remote_network, remote_content_format, _ = infos
                didl = DIDLLite.DIDLElement()
                didl.addItem(item)
                next_track = (res.data, didl.toString(), remote_content_format)
                self.playcontainer[0] = self.playcontainer[0] + 1

            self.info("update: next=%s" % next_track)
            if len(next_track) == 3:
                av_transport.set_variable(conn_id, 'CurrentTrack',
                                          self.playcontainer[0] + 1)
                self.load(next_track[0], next_track[1], next_track[2])
                self.play()

            else:
                self._update_transport_state(self.STATE_IDLE)
        elif message == self.MESSAGE_EOF and \
         len(av_transport.get_variable('NextAVTransportURI').value) > 0:
            self._transition()

            CurrentURI = av_transport.get_variable('NextAVTransportURI').value
            metadata = av_transport.get_variable('NextAVTransportURIMetaData')
            CurrentURIMetaData = metadata.value
            av_transport.set_variable(conn_id, 'NextAVTransportURI', '')
            av_transport.set_variable(conn_id, 'NextAVTransportURIMetaData',
                                      '')
            r = self.upnp_SetAVTransportURI(
                self,
                InstanceID=0,
                CurrentURI=CurrentURI,
                CurrentURIMetaData=CurrentURIMetaData)
            self.info("update: r=%s" % r)
            if r == {}:
                self.play()
            else:
                self._update_transport_state(self.STATE_IDLE)
        else:
            self._update_transport_state(self.STATE_IDLE)

        self._update_transport_position()
Esempio n. 26
0
 def reply(data, name, connection):
     if hasattr(connection, '_tube') == True:
         if name == 'Browse':
             didl = DIDLLite.DIDLElement.fromString(data['Result'])
             changed = False
             for item in didl.getItems():
                 new_res = DIDLLite.Resources()
                 for res in item.res:
                     remote_protocol, remote_network, remote_content_format, _ = res.protocolInfo.split(
                         ':')
                     if remote_protocol == 'http-get' and remote_network == '*':
                         quoted_url = 'mirabeau' + '/' + urllib.quote_plus(
                             res.data)
                         print "modifying", res.data
                         host_port = ':'.join(
                             (self.service.device.client.coherence.
                              mirabeau._external_address,
                              str(self.service.device.client.coherence.
                                  mirabeau._external_port)))
                         res.data = urlparse.urlunsplit(
                             ('http', host_port, quoted_url, "", ""))
                         print "--->", res.data
                         new_res.append(res)
                         changed = True
                 item.res = new_res
             if changed == True:
                 didl.rebuild()
                 ### FIXME this is not the proper way to do it
                 data['Result'] = didl.toString().replace(
                     '<ns0:', '<').replace('</ns0:', '</')
     dbus_async_cb(
         dbus.Dictionary(data, signature='sv', variant_level=4))
Esempio n. 27
0
    def get_item(self, parent_id=None):

        self.debug("Image get_item %r @ %r", self.id, self.parent_id)

        # create item
        item = DIDLLite.ImageItem(self.id, self.parent_id)
        #item.date =
        item.title = self.title

        # add http resource
        res = DIDLLite.Resource(self.url, 'http-get:*:%s:*' % self.mimetype)
        if self.size > 0:
            res.size = self.size
        item.res.append(res)

        return item
Esempio n. 28
0
    def get_item(self):
        item = DIDLLite.MusicTrack(self.get_id(), self.album.itemID,
                                   self.title)
        item.artist = self.album.artist.name
        item.album = self.album.title
        item.playlist = self.playlist

        if self.album.cover != '':
            _, ext = os.path.splitext(self.album.cover)
            """ add the cover image extension to help clients not reacting on
                the mimetype """
            item.albumArtURI = ''.join(
                (self._db.urlbase, self.get_id(), '?cover', ext))
        item.originalTrackNumber = self.track_nr
        item.server_uuid = str(self._db.server.uuid)[5:]

        statinfo, resources = self.get_resources()
        item.res.extend(resources)

        try:
            # FIXME: getmtime is deprecated in Twisted 2.6
            item.date = datetime.fromtimestamp(statinfo.st_mtime)
        except:
            item.date = None

        return item
Esempio n. 29
0
    def __init__(self, parent_id, item_id, urlbase, **kwargs):
        super(LolCatsImage, self).__init__(parent_id, item_id, urlbase,
                                           **kwargs)

        res = DIDLLite.Resource(self.location, f'http-get:*:{self.mimetype}:*')
        res.size = None  # FIXME: we should have a size here
        self.item.res.append(res)
Esempio n. 30
0
    def __init__(self, parent_id, id):
        BackendItem.__init__(self)
        # the ids as above
        self.parent_id = parent_id
        self.id = id

        # we never have a different name anyway
        self.name = 'LOLCats'

        # but we need to set it to a certain mimetype to explain it, that we
        # contain 'children'.
        self.mimetype = 'directory'

        # As we are updating our data periodically, we increase this value so
        # that our clients can check easier if something has changed since their
        # last request.
        self.update_id = 0

        # that is where we hold the children
        self.children = []

        # and we need to give a DIDLLite again. This time we want to be
        # understood as 'Container'.
        self.item = DIDLLite.Container(id, parent_id, self.name)

        self.item.childCount = None  # will be set as soon as we have images
Esempio n. 31
0
        def reply(r):
            #print "browse_reply - %s of %s returned" % (r['NumberReturned'],r['TotalMatches'])
            from coherence.upnp.core import DIDLLite
            from coherence.extern.et import ET

            child = self.store.iter_children(iter)
            if child:
                upnp_class, = self.store.get(child,UPNP_CLASS_COLUMN)
                if upnp_class == 'placeholder':
                    self.store.remove(child)

            title, = self.store.get(iter,NAME_COLUMN)
            try:
                title = title[:title.rindex('(')]
                self.store.set_value(iter,NAME_COLUMN, "%s(%d)" % (title,int(r['TotalMatches'])))
            except ValueError:
                pass
            elt = parse_xml(r['Result'], 'utf-8')
            elt = elt.getroot()
            for child in elt:
                #stored_didl_string = DIDLLite.element_to_didl(child)
                stored_didl_string = DIDLLite.element_to_didl(ET.tostring(child))
                didl = DIDLLite.DIDLElement.fromString(stored_didl_string)
                item = didl.getItems()[0]
                #print item.title, item.id, item.upnp_class
                if item.upnp_class.startswith('object.container'):
                    icon = self.folder_icon
                    service, = self.store.get(iter,SERVICE_COLUMN)
                    child_count = item.childCount
                    try:
                        title = "%s (%d)" % (item.title,item.childCount)
                    except TypeError:
                        title = "%s (n/a)" % item.title
                        child_count = -1
                else:
                    icon=None
                    service = ''

                    child_count = -1
                    title = item.title
                    if item.upnp_class.startswith('object.item.audioItem'):
                        icon = self.audio_icon
                    elif item.upnp_class.startswith('object.item.videoItem'):
                        icon = self.video_icon
                    elif item.upnp_class.startswith('object.item.imageItem'):
                        icon = self.image_icon

                    res = item.res.get_matching(['*:*:*:*'], protocol_type='http-get')
                    if len(res) > 0:
                        res = res[0]
                        service = res.data

                new_iter = self.store.append(iter, (title,item.id,item.upnp_class,child_count,'',service,icon,stored_didl_string,None))
                if item.upnp_class.startswith('object.container'):
                    self.store.append(new_iter, ('...loading...','','placeholder',-1,'','',None,'',None))


            if((int(r['TotalMatches']) > 0 and force==False) or
                expand==True):
                view.expand_row(row_path, False)

            if(requested_count != int(r['NumberReturned']) and
               int(r['NumberReturned']) < (int(r['TotalMatches'])-starting_index)):
                print "seems we have been returned only a part of the result"
                print "requested %d, starting at %d" % (requested_count,starting_index)
                print "got %d out of %d" % (int(r['NumberReturned']), int(r['TotalMatches']))
                print "requesting more starting now at %d" % (starting_index+int(r['NumberReturned']))

                self.browse(view,row_path,column,
                            starting_index=starting_index+int(r['NumberReturned']),
                            force=True)
Esempio n. 32
0
        def reply(r,service):
            if iter:
                child = model.iter_children(iter)
                if child:
                    upnp_class = model.get(child, self.MS_UPNP_CLASS_COLUMN)[0]
                    if upnp_class == 'placeholder':
                        model.remove(child)

                title = model.get(iter, self.MS_NAME_COLUMN)[0]
                if title:
                    try:
                        title = title[:title.rindex('(')]
                        model.set_value(iter, self.MS_NAME_COLUMN,
                                        "%s(%d)" % (title, int(r['TotalMatches'])))
                    except ValueError:
                        pass
            elt = parse_xml(r['Result'], 'utf-8')
            elt = elt.getroot()
            for child in elt:
                stored_didl_string = DIDLLite.element_to_didl(ET.tostring(child))
                didl = DIDLLite.DIDLElement.fromString(stored_didl_string)
                item = didl.getItems()[0]
                if item.upnp_class.startswith('object.container'):
                    icon = self.folder_icon
                    #service = model.get(iter, self.MS_SERVICE_PATH_COLUMN)[0]
                    child_count = item.childCount
                    try:
                        title = "%s (%d)" % (item.title, item.childCount)
                    except TypeError:
                        title = "%s (n/a)" % item.title
                        child_count = -1
                else:
                    icon = None
                    service = ''

                    child_count = -1
                    title = item.title
                    if item.upnp_class.startswith('object.item.audioItem'):
                        icon = self.audio_icon
                    elif item.upnp_class.startswith('object.item.videoItem'):
                        icon = self.video_icon
                    elif item.upnp_class.startswith('object.item.imageItem'):
                        icon = self.image_icon

                    res = item.res.get_matching(['*:*:*:*'], protocol_type='http-get')
                    if len(res) > 0:
                        res = res[0]
                        service = res.data

                new_iter = model.append(iter, (title, item.id, item.upnp_class, child_count,
                                               '',service,icon,stored_didl_string,None))
                if item.upnp_class.startswith('object.container'):
                    model.append(new_iter, ('...loading...',
                                            '', 'placeholder', -1, '', '',
                                            None, '', None))


            if ((int(r['TotalMatches']) > 0 and force==False) or \
                expand==True):
                if view:
                    view.expand_row(row_path, False)

            if(requested_count != int(r['NumberReturned']) and \
               int(r['NumberReturned']) < (int(r['TotalMatches'])-starting_index)):
                self.browse(view, row_path, column,
                            starting_index=starting_index+int(r['NumberReturned']),
                            force=True)