def process_song_data(self, ydl, url, entry):
"""
Just packing some code into a function to make fetch_song_data more readable
:param ydl: youtube_dl object
:param url: original url of the request
:param entry: request data
:return: dictionary of parameters
"""
t_dict = DotDict({})
self.logger.info(f'processing URL {entry["title"]}')
if self.plugin_config["download_songs"]:
filename = ydl.prepare_filename(entry)
self.storage["stored_songs"][filename] = time.time()
else:
filename = entry['url']
# t_source = PCMVolumeTransformer(FFmpegPCMAudio(filename, **kwargs)) # out, out, damn spot!
t_dict['download_url'] = filename
t_dict['url'] = entry.get('webpage_url')
t_dict['yt'] = ydl
t_dict['is_live'] = bool(entry.get('is_live'))
t_dict['duration'] = ceil(entry.get('duration', 0))
is_twitch = 'twitch' in url
if is_twitch:
# twitch has 'title' and 'description' sort of mixed up.
t_dict['title'] = entry.get('description')
t_dict['description'] = None
else:
t_dict['title'] = entry.get('title')
t_dict['description'] = entry.get('description')
# upload date handling
date = entry.get('upload_date')
if date:
try:
date = datetime.datetime.strptime(date, '%Y%M%d').date()
except ValueError:
date = None
t_dict['upload_date'] = date
return t_dict
评论列表
文章目录