main.py 文件源码

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

项目:plugin.audio.bytefm 作者: kopf 项目源码 文件源码
def _download_show(title, moderators, show_slug, broadcast_date, image_url, show_path):
    plugin.log_notice("Downloading show {} to {}".format(show_slug, show_path))
    broadcast_data = _get_broadcast_recording_playlist(show_slug, broadcast_date)
    recordings = broadcast_data['recordings']
    list_items = []
    if not os.path.exists(show_path):
        os.makedirs(show_path)
    thumbnail_path = _save_thumbnail(image_url, show_path)
    for rec_idx, url in enumerate(recordings):
        mp3_filename = url.replace('/', '_').replace(' ', '_').lower()
        label = 'Part {}'.format(rec_idx+1)
        show_part_path = os.path.join(show_path, label)
        list_items.append({'url': show_part_path, 'label': label})
        if not os.path.exists(show_part_path):
            os.makedirs(show_part_path)
        shutil.copy(thumbnail_path, show_part_path)
        mp3_path = os.path.join(show_part_path, mp3_filename)
        cue_path = mp3_path + '.cue'
        _save_cuefile(broadcast_data['playlist'][url], cue_path, mp3_path, moderators, title)
        if not os.path.isfile(mp3_path):
            plugin.log_notice('{} does not exist, downloading...'.format(mp3_path))
            resp = _http_get(ARCHIVE_BASE_URL + url, stream=True)
            progress_bar = xbmcgui.DialogProgress()
            progress_bar.create(_('Downloading...'))
            i = 0.0
            file_size = int(resp.headers['Content-Length'])
            extra_info = _('File {} of {}').format(rec_idx + 1, len(recordings))
            with open(mp3_path, 'wb') as f:
                for block in resp.iter_content(CHUNK_SIZE):
                    f.write(block)
                    i += 1
                    percent_done = int(((CHUNK_SIZE * i) / file_size) * 100)
                    progress_bar.update(percent_done, _('Please wait'), extra_info)

    return list_items
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号