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
评论列表
文章目录