mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-12-22 18:00:17 +00:00
allowing to add playlist to queue
This commit is contained in:
parent
9070e04431
commit
e3afe3947c
@ -41,6 +41,9 @@ class PendingList:
|
||||
url, limit=False
|
||||
)
|
||||
missing_videos = missing_videos + youtube_ids
|
||||
elif url_type == 'playlist':
|
||||
youtube_ids = playlist_extractor(url)
|
||||
missing_videos = missing_videos + youtube_ids
|
||||
|
||||
return missing_videos
|
||||
|
||||
@ -366,6 +369,18 @@ class ChannelSubscription:
|
||||
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:
|
||||
""" handle the video download functionality """
|
||||
|
||||
|
@ -42,16 +42,24 @@ def clean_string(file_name):
|
||||
|
||||
def process_url_list(url_str):
|
||||
""" 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])
|
||||
youtube_ids = []
|
||||
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]
|
||||
str_len = len(url_no_param)
|
||||
if str_len == 11:
|
||||
link_type = 'video'
|
||||
elif str_len == 24:
|
||||
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})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user