auto index playlists when adding to download

This commit is contained in:
simon 2021-11-29 15:49:45 +07:00
parent b8359a4249
commit 7e97284374
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 28 additions and 17 deletions

View File

@ -21,7 +21,9 @@ The **Add to Download Queue** icon <img src="assets/icon-add.png?raw=true" alt="
- Add a link to a YouTube video by providing the shortened URL, for example *https://youtu.be/2tdiKTSdE9Y*. - Add a link to a YouTube video by providing the shortened URL, for example *https://youtu.be/2tdiKTSdE9Y*.
- Add a Channel ID or Channel URL to add every available video to the download queue. This will ignore the channel page size as described before and is meant for an initial download of the whole channel. You can still ignore selected videos before starting the download. - Add a Channel ID or Channel URL to add every available video to the download queue. This will ignore the channel page size as described before and is meant for an initial download of the whole channel. You can still ignore selected videos before starting the download.
- Add a channel name like for example *https://www.youtube.com/c/TomScottGo*. - Add a channel name like for example *https://www.youtube.com/c/TomScottGo*.
- Add a playlist ID or URL to add every available video in the list to the download queue, for example *https://www.youtube.com/playlist?list=PL96C35uN7xGLLeET0dOWaKHkAlPsrkcha* or *PL96C35uN7xGLLeET0dOWaKHkAlPsrkcha*. Note that when you add a link to a video in a playlist, Tube Archivist assumes you want to download only the specific video and not the whole playlist, for example *https://www.youtube.com/watch?v=CINVwWHlzTY&list=PL96C35uN7xGLLeET0dOWaKHkAlPsrkcha* will only add one video *CINVwWHlzTY* to the queue. - Add a playlist ID or URL to add every available video in the list to the download queue, for example *https://www.youtube.com/playlist?list=PL96C35uN7xGLLeET0dOWaKHkAlPsrkcha* or *PL96C35uN7xGLLeET0dOWaKHkAlPsrkcha*.
- Note: When adding a playlist to the queue, this playlist will automatically get [indexed](Playlists#playlist-detail).
- Note: When you add a link to a video in a playlist, Tube Archivist assumes you want to download only the specific video and not the whole playlist, for example *https://www.youtube.com/watch?v=CINVwWHlzTY&list=PL96C35uN7xGLLeET0dOWaKHkAlPsrkcha* will only add one video *CINVwWHlzTY* to the queue.
- Add one link per line. - Add one link per line.
## The Download Queue ## The Download Queue

View File

@ -40,9 +40,9 @@ class PendingList:
def __init__(self): def __init__(self):
self.all_channel_ids = False self.all_channel_ids = False
self.all_downloaded = False self.all_downloaded = False
self.missing_from_playlists = []
@staticmethod def parse_url_list(self, youtube_ids):
def parse_url_list(youtube_ids):
"""extract youtube ids from list""" """extract youtube ids from list"""
missing_videos = [] missing_videos = []
for entry in youtube_ids: for entry in youtube_ids:
@ -66,6 +66,7 @@ class PendingList:
youtube_ids = [i[0] for i in video_results] youtube_ids = [i[0] for i in video_results]
missing_videos = missing_videos + youtube_ids missing_videos = missing_videos + youtube_ids
elif url_type == "playlist": elif url_type == "playlist":
self.missing_from_playlists.append(entry)
video_results = YoutubePlaylist(url).get_entries() video_results = YoutubePlaylist(url).get_entries()
youtube_ids = [i["youtube_id"] for i in video_results] youtube_ids = [i["youtube_id"] for i in video_results]
missing_videos = missing_videos + youtube_ids missing_videos = missing_videos + youtube_ids
@ -395,7 +396,7 @@ class PlaylistSubscription:
return all_playlists return all_playlists
def process_url_str(self, new_playlists): def process_url_str(self, new_playlists, subscribed=True):
"""process playlist subscribe form url_str""" """process playlist subscribe form url_str"""
all_indexed = PendingList().get_all_indexed() all_indexed = PendingList().get_all_indexed()
all_youtube_ids = [i["youtube_id"] for i in all_indexed] all_youtube_ids = [i["youtube_id"] for i in all_indexed]
@ -409,17 +410,17 @@ class PlaylistSubscription:
print(f"{playlist_id} not a playlist, skipping...") print(f"{playlist_id} not a playlist, skipping...")
continue continue
playlist_handler = YoutubePlaylist( playlisr = YoutubePlaylist(
playlist_id, all_youtube_ids=all_youtube_ids playlist_id, all_youtube_ids=all_youtube_ids
) )
if not playlist_handler.get_es_playlist(): if not playlisr.get_es_playlist():
playlist_handler.get_playlist_dict() playlisr.get_playlist_dict()
playlist_handler.playlist_dict["playlist_subscribed"] = True playlisr.playlist_dict["playlist_subscribed"] = subscribed
playlist_handler.upload_to_es() playlisr.upload_to_es()
playlist_handler.add_vids_to_playlist() playlisr.add_vids_to_playlist()
thumb = playlist_handler.playlist_dict["playlist_thumbnail"] thumb = playlisr.playlist_dict["playlist_thumbnail"]
new_thumbs.append((playlist_id, thumb)) new_thumbs.append((playlist_id, thumb))
self.channel_validate(playlist_handler) self.channel_validate(playlisr)
else: else:
self.change_subscribe(playlist_id, subscribe_status=True) self.change_subscribe(playlist_id, subscribe_status=True)

View File

@ -2,6 +2,8 @@
Functionality: Functionality:
- initiate celery app - initiate celery app
- collect tasks - collect tasks
- user config changes won't get applied here
because tasks are initiated at application start
""" """
import os import os
@ -26,10 +28,7 @@ from home.src.thumbnails import ThumbManager, validate_thumbnails
CONFIG = AppConfig().config CONFIG = AppConfig().config
REDIS_HOST = os.environ.get("REDIS_HOST") REDIS_HOST = os.environ.get("REDIS_HOST")
REDIS_PORT = os.environ.get("REDIS_PORT") REDIS_PORT = os.environ.get("REDIS_PORT") or 6379
if not REDIS_PORT:
REDIS_PORT = 6379
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "home.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "home.settings")
app = Celery("tasks", broker=f"redis://{REDIS_HOST}:{REDIS_PORT}") app = Celery("tasks", broker=f"redis://{REDIS_HOST}:{REDIS_PORT}")
@ -109,7 +108,16 @@ def extrac_dl(youtube_ids):
pending_handler = PendingList() pending_handler = PendingList()
missing_videos = pending_handler.parse_url_list(youtube_ids) missing_videos = pending_handler.parse_url_list(youtube_ids)
all_videos_added = pending_handler.add_to_pending(missing_videos) all_videos_added = pending_handler.add_to_pending(missing_videos)
ThumbManager().download_vid(all_videos_added) missing_playlists = pending_handler.missing_from_playlists
thumb_handler = ThumbManager()
if missing_playlists:
new_thumbs = PlaylistSubscription().process_url_str(
missing_playlists, subscribed=False
)
thumb_handler.download_playlist(new_thumbs)
thumb_handler.download_vid(all_videos_added)
@shared_task @shared_task