utils.py 文件源码

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

项目:script.tvguide.fullscreen 作者: primaeval 项目源码 文件源码
def getLogo(title,ask=False,force=True):
    infile = xbmc.translatePath("special://profile/addon_data/script.tvguide.fullscreen/logos/temp.png")
    outfile = xbmc.translatePath("special://profile/addon_data/script.tvguide.fullscreen/logos/%s.png" % title)
    if not force and xbmcvfs.exists(outfile):
        return outfile
    xbmcvfs.mkdirs("special://profile/addon_data/script.tvguide.fullscreen/logos")
    db_url = "http://www.thelogodb.com/api/json/v1/4423/tvchannel.php?s=%s" % re.sub(' ','+',title)
    try: json = requests.get(db_url).json()
    except: pass
    if json and "channels" in json:
        channels = json["channels"]
        if channels:
            if ask:
                names = ["%s [%s]" % (c["strChannel"],c["strCountry"]) for c in channels]
                d = xbmcgui.Dialog()
                selected = d.select("Logo Source: %s" % title,names)
            else:
                selected = 0
            if selected > -1:
                logo = channels[selected]["strLogoWide"]

                if not logo:
                    return None
                logo = re.sub('^https','http',logo)
                data = requests.get(logo).content
                f = xbmcvfs.File("special://profile/addon_data/script.tvguide.fullscreen/logos/temp.png","wb")
                f.write(data)
                f.close()
                from PIL import Image, ImageOps
                image = Image.open(infile)
                border = 0
                image = autocrop_image(image, border)
                image.save(outfile)
                logo = outfile
                return logo
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号