lastFM_AlbumArtGrabber.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:Webradio_v2 作者: Acer54 项目源码 文件源码
def search_for_image(self):
        """ Use LastFM's API to obtain a URL for the album cover art """

        response = urllib.urlopen(self.url).read() # Send HTTP request to LastFM
        #Due to a change in the API, Namespace prefix is not defined an causes Errors! 
        #Hotfix: Use "lxml" instead of "xml"
        parser = ETree.XMLParser(recover=True)
        xml_data = ETree.fromstring(response, parser)  # Read in XML data


        for element in xml_data.getiterator("album"):
            if (element.find('artist').text.lower() == self.artist_name.lower().encode("utf-8")):
                for elmnt in element.findall('image'):
                    if (elmnt.attrib['size'] == 'extralarge'):
                        url = elmnt.text
                        if url:
                            return url
                        else:
                            return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号