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 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 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.
## The Download Queue

View File

@ -40,9 +40,9 @@ class PendingList:
def __init__(self):
self.all_channel_ids = False
self.all_downloaded = False
self.missing_from_playlists = []
@staticmethod
def parse_url_list(youtube_ids):
def parse_url_list(self, youtube_ids):
"""extract youtube ids from list"""
missing_videos = []
for entry in youtube_ids:
@ -66,6 +66,7 @@ class PendingList:
youtube_ids = [i[0] for i in video_results]
missing_videos = missing_videos + youtube_ids
elif url_type == "playlist":
self.missing_from_playlists.append(entry)
video_results = YoutubePlaylist(url).get_entries()
youtube_ids = [i["youtube_id"] for i in video_results]
missing_videos = missing_videos + youtube_ids
@ -395,7 +396,7 @@ class PlaylistSubscription:
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"""
all_indexed = PendingList().get_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...")
continue
playlist_handler = YoutubePlaylist(
playlisr = YoutubePlaylist(
playlist_id, all_youtube_ids=all_youtube_ids
)
if not playlist_handler.get_es_playlist():
playlist_handler.get_playlist_dict()
playlist_handler.playlist_dict["playlist_subscribed"] = True
playlist_handler.upload_to_es()
playlist_handler.add_vids_to_playlist()
thumb = playlist_handler.playlist_dict["playlist_thumbnail"]
if not playlisr.get_es_playlist():
playlisr.get_playlist_dict()
playlisr.playlist_dict["playlist_subscribed"] = subscribed
playlisr.upload_to_es()
playlisr.add_vids_to_playlist()
thumb = playlisr.playlist_dict["playlist_thumbnail"]
new_thumbs.append((playlist_id, thumb))
self.channel_validate(playlist_handler)
self.channel_validate(playlisr)
else:
self.change_subscribe(playlist_id, subscribe_status=True)

View File

@ -2,6 +2,8 @@
Functionality:
- initiate celery app
- collect tasks
- user config changes won't get applied here
because tasks are initiated at application start
"""
import os
@ -26,10 +28,7 @@ from home.src.thumbnails import ThumbManager, validate_thumbnails
CONFIG = AppConfig().config
REDIS_HOST = os.environ.get("REDIS_HOST")
REDIS_PORT = os.environ.get("REDIS_PORT")
if not REDIS_PORT:
REDIS_PORT = 6379
REDIS_PORT = os.environ.get("REDIS_PORT") or 6379
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "home.settings")
app = Celery("tasks", broker=f"redis://{REDIS_HOST}:{REDIS_PORT}")
@ -109,7 +108,16 @@ def extrac_dl(youtube_ids):
pending_handler = PendingList()
missing_videos = pending_handler.parse_url_list(youtube_ids)
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