Ejemplo n.º 1
0
def getAlbumArt(service, AlbumArtURI):

#TODO: display a "getting album art" graphic until art is updated

#    log.debug('#### GETALBUMART service: %s' % service)
#    log.debug('#### GETALBUMART AlbumArtURI: %s' % AlbumArtURI)

    if AlbumArtURI == '' or AlbumArtURI == None:
        return (None, "No albumart to display")
    else:
        url_info = parse_url(service.url_base)
#        log.debug('#### GETALBUMART url_info: %s' % str(url_info))
        aa_url = "%s://%s%s" % (url_info[0], url_info[1], AlbumArtURI)
#        log.debug('#### GETALBUMART control_url: %s' % aa_url)
        try:
            fd = url_fetch(aa_url)
#        except HTTPError as detail:
        except HTTPError:
            return (None, HTTPError)

        try:
            data = fd.read()
        except:
            log.debug("#### GETALBUMART fd is invalid")
            return (None, "Error getting albumArt")

        pbl = gtk.gdk.PixbufLoader()
        pbl.write(data)
        pbuf = pbl.get_pixbuf()
#        print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
#        print pbl.get_format()
#        print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
        pbl.close()

        return (pbuf, '')
Ejemplo n.º 2
0
 def _build_sync(self):
     """ Builds the Service synchronously.
     """
     if is_relative(self.scpd_url, self.url_base):
         url = '%s%s' % (self.url_base, self.scpd_url)
     else:
         url = self.scpd_url
     fd = url_fetch(url)
     if not fd:
         log.debug('Could not fetch SCPD URL %s' % self.scpd_url)
         raise RuntimeError('Could not build Service %s', self)
     ServiceBuilder(self, fd).build()
Ejemplo n.º 3
0
 def _build_sync(self):
     """ Builds the Service synchronously.
     """
     if is_relative(self.scpd_url, self.url_base):
         url = '%s%s' % (self.url_base, self.scpd_url)
     else:
         url = self.scpd_url
     fd = url_fetch(url)
     if not fd:
         log.debug('Could not fetch SCPD URL %s' % self.scpd_url)
         raise RuntimeError('Could not build Service %s', self)
     ServiceBuilder(self, fd).build()
Ejemplo n.º 4
0
    def mount_device(self):
        if self.filename is None:
            filecontent = url_fetch(self.location)
            if not filecontent:
                return
            data = filecontent.read()
            data = data[data.find("<"):data.rfind(">")+1]
            tree = ElementTree(data).getroot()
        else:
            from xml.etree.ElementTree import parse
            tree = parse(self.filename)

        DeviceBuilder(self.device, self.location, tree).cleanup()
        return self.device
Ejemplo n.º 5
0
    def mount_device(self):
        if self.filename is None:
            filecontent = url_fetch(self.location)
            if not filecontent:
                return
            data = filecontent.read()
            data = data[data.find("<"):data.rfind(">") + 1]
            tree = ElementTree(data).getroot()
        else:
            from xml.etree.ElementTree import parse
            tree = parse(self.filename)

        DeviceBuilder(self.device, self.location, tree).cleanup()
        return self.device
Ejemplo n.º 6
0
 def _build_sync(self):
     """ Builds the Service synchronously.
     """
     if is_file(self.scpd_url):
         fd = open(self.scpd_url[8:], "r")
     else:
         if is_relative(self.scpd_url, self.url_base):
             url = "%s%s" % (self.url_base, self.scpd_url)
         else:
             url = self.scpd_url
         fd = url_fetch(url)
     if not fd:
         log.debug("Could not fetch SCPD URL %s" % self.scpd_url)
         raise RuntimeError("Could not build Service %s", self)
     ServiceBuilder(self, fd).build()
Ejemplo n.º 7
0
    def _build_sync(self):
        """ Builds the Service synchronously.
        """
        #        print "_build_sync scpd_url: " + str(self.scpd_url)
        #        print "_build_sync url_base: " + str(self.url_base)
        if is_file(self.scpd_url):
            fd = open(self.scpd_url[8:], 'r')
        else:
            if is_relative(self.scpd_url, self.url_base):
                url = '%s%s' % (self.url_base, self.scpd_url)
            else:
                url = self.scpd_url
#            print "_build_sync url: " + str(url)
            fd = url_fetch(url)
        if not fd:
            log.debug('Could not fetch SCPD URL %s' % self.scpd_url)
            raise RuntimeError('Could not build Service %s', self)
        ServiceBuilder(self, fd).build()
Ejemplo n.º 8
0
    def _build_sync(self):
        """ Builds the Service synchronously.
        """
#        print "_build_sync scpd_url: " + str(self.scpd_url)
#        print "_build_sync url_base: " + str(self.url_base)
        if is_file(self.scpd_url):
            fd = open(self.scpd_url[8:], 'r')
        else:
            if is_relative(self.scpd_url, self.url_base):
                url = '%s%s' % (self.url_base, self.scpd_url)
            else:
                url = self.scpd_url
#            print "_build_sync url: " + str(url)
            fd = url_fetch(url)
        if not fd:
            log.debug('Could not fetch SCPD URL %s' % self.scpd_url)
            raise RuntimeError('Could not build Service %s', self)
        ServiceBuilder(self, fd).build()
Ejemplo n.º 9
0
    def getscpdurl(self, location):
        '''
        Gets the scpd url from a url specifying the device xml location
        '''
        addr = parse_url(location)
        base_url = '%s://%s' % (addr.scheme, addr.netloc)
#        print "---> base_url: " + str(base_url)
        filecontent = url_fetch(location)
        if not filecontent:
            return None
        tree = ElementTree(file=filecontent).getroot()
        for device in tree.findall('{urn:schemas-upnp-org:device-1-0}device'):
            for xml_service_element in device.findall('.//{urn:schemas-upnp-org:device-1-0}service'):
                service_type = xml_service_element.findtext('{urn:schemas-upnp-org:device-1-0}serviceType')
                if service_type == 'urn:schemas-upnp-org:service:ContentDirectory:1':
                    scpd_url = xml_service_element.findtext('{urn:schemas-upnp-org:device-1-0}SCPDURL')
                    if not scpd_url.startswith('/'):
                        scpd_url = '/' + scpd_url
                    scpd_url = base_url + scpd_url
                    return scpd_url
        return None        
Ejemplo n.º 10
0
def getAlbumArtFile(service, AlbumArtURI, filename):

    #    log.debug('#### GETALBUMART service: %s' % service)
    #    log.debug('#### GETALBUMART AlbumArtURI: %s' % AlbumArtURI)

    if AlbumArtURI == '' or AlbumArtURI == None:
        return False
    else:
        url_info = parse_url(service.url_base)
        aa_url = "%s://%s%s" % (url_info[0], url_info[1], AlbumArtURI)
        #        log.debug('#### GETALBUMART control_url: %s' % aa_url)
        fd = url_fetch(aa_url)
        try:
            data = fd.read()
        except:
            log.debug("#### GETALBUMART fd is invalid")
            data = ''

    fdout = open(filename, "w")
    fdout.write(data)
    fdout.close()

    return True
Ejemplo n.º 11
0
def getAlbumArtFile(service, AlbumArtURI, filename):

#    log.debug('#### GETALBUMART service: %s' % service)
#    log.debug('#### GETALBUMART AlbumArtURI: %s' % AlbumArtURI)

    if AlbumArtURI == '' or AlbumArtURI == None:
        return False
    else:
        url_info = parse_url(service.url_base)
        aa_url = "%s://%s%s" % (url_info[0], url_info[1], AlbumArtURI)
#        log.debug('#### GETALBUMART control_url: %s' % aa_url)
        fd = url_fetch(aa_url)
        try:
            data = fd.read()
        except:
            log.debug("#### GETALBUMART fd is invalid")
            data = ''

    fdout = open(filename,"w")
    fdout.write(data)
    fdout.close()

    return True