update_channels.py 文件源码

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

项目:plugin.video.streamondemand-pureita 作者: orione7 项目源码 文件源码
def update_channels():
    with open(os.path.join(local_folder, "channelslist.xml"), 'rb') as f:
        xml = f.read()
    local_dict = read_channels_list(xml)

    xml = scrapertools.cache_page(remote_url + "channelslist.xml")
    remote_dict = read_channels_list(xml)

    # ----------------------------
    import xbmcgui
    progress = xbmcgui.DialogProgressBG()
    progress.create("Update channels list")
    # ----------------------------

    for index, channel_id in enumerate(remote_dict.iterkeys()):
        # ----------------------------
        percentage = index * 100 / len(remote_dict)
        # ----------------------------
        if channel_id not in local_dict or remote_dict[channel_id][VERSION_IDX] > local_dict[channel_id][VERSION_IDX]:
            data = scrapertools.cache_page(remote_dict[channel_id][UPDATE_URL_IDX])

            with open(os.path.join(local_folder, channel_id + ".py"), 'wb') as f:
                f.write(data)
            # ----------------------------
            progress.update(percentage, ' Update channel: ' + channel_id)
            # ----------------------------

    for channel_id in set(local_dict.keys()) - set(remote_dict.keys()):
        os.remove(os.path.join(local_folder, channel_id + ".py"))

    with open(os.path.join(local_folder, "channelslist.xml"), 'wb') as f:
        f.write(xml)

    # ----------------------------
    progress.close()
    # ----------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号