allowing to add playlist to queue

This commit is contained in:
simon 2021-09-10 15:07:38 +07:00
parent 9070e04431
commit e3afe3947c
2 changed files with 24 additions and 1 deletions

View File

@ -41,6 +41,9 @@ class PendingList:
url, limit=False url, limit=False
) )
missing_videos = missing_videos + youtube_ids missing_videos = missing_videos + youtube_ids
elif url_type == 'playlist':
youtube_ids = playlist_extractor(url)
missing_videos = missing_videos + youtube_ids
return missing_videos return missing_videos
@ -366,6 +369,18 @@ class ChannelSubscription:
channel_handler.sync_to_videos() channel_handler.sync_to_videos()
def playlist_extractor(playlist_id):
""" return youtube_ids from a playlist_id """
url = 'https://www.youtube.com/playlist?list=' + playlist_id
obs = {
'default_search': 'ytsearch', 'quiet': True, 'ignoreerrors': True,
'skip_download': True, 'extract_flat': True
}
playlist = youtube_dl.YoutubeDL(obs).extract_info(url, download=False)
playlist_vids = [(i['id'], i['title']) for i in playlist['entries']]
return playlist_vids
class VideoDownloader: class VideoDownloader:
""" handle the video download functionality """ """ handle the video download functionality """

View File

@ -42,16 +42,24 @@ def clean_string(file_name):
def process_url_list(url_str): def process_url_list(url_str):
""" parse url_list to find valid youtube video or channel ids """ """ parse url_list to find valid youtube video or channel ids """
to_replace = ['watch?v=', 'playlist?list=']
url_list = re.split('\n+', url_str[0]) url_list = re.split('\n+', url_str[0])
youtube_ids = [] youtube_ids = []
for url in url_list: for url in url_list:
url_clean = url.strip().split('/')[-1].replace('watch?v=', '') url_clean = url.strip().split('/')[-1]
for i in to_replace:
url_clean = url_clean.replace(i, '')
url_no_param = url_clean.split('&')[0] url_no_param = url_clean.split('&')[0]
str_len = len(url_no_param) str_len = len(url_no_param)
if str_len == 11: if str_len == 11:
link_type = 'video' link_type = 'video'
elif str_len == 24: elif str_len == 24:
link_type = 'channel' link_type = 'channel'
elif str_len == 34:
link_type = 'playlist'
else:
# unable to parse
return False
youtube_ids.append({"url": url_no_param, "type": link_type}) youtube_ids.append({"url": url_no_param, "type": link_type})