diff --git a/tubearchivist/home/src/index/generic.py b/tubearchivist/home/src/index/generic.py index 0940258..06a2806 100644 --- a/tubearchivist/home/src/index/generic.py +++ b/tubearchivist/home/src/index/generic.py @@ -5,8 +5,8 @@ functionality: import math -import yt_dlp from home.src.download.yt_cookie import CookieHandler +from home.src.download.yt_dlp_base import YtWrap from home.src.es.connect import ElasticWrap from home.src.ta.config import AppConfig from home.src.ta.ta_redis import RedisArchivist @@ -19,11 +19,7 @@ class YouTubeItem: index_name = False yt_base = False yt_obs = { - "quiet": True, - "default_search": "ytsearch", "skip_download": True, - "check_formats": "selected", - "socket_timeout": 3, "noplaylist": True, } @@ -46,15 +42,7 @@ class YouTubeItem: def get_from_youtube(self): """use yt-dlp to get meta data from youtube""" print(f"{self.youtube_id}: get metadata from youtube") - try: - yt_item = yt_dlp.YoutubeDL(self.yt_obs) - response = yt_item.extract_info(self.yt_base + self.youtube_id) - except ( - yt_dlp.utils.ExtractorError, - yt_dlp.utils.DownloadError, - ): - print(f"{self.youtube_id}: failed to get info from youtube") - response = False + response = YtWrap(self.yt_obs).extract(self.yt_base + self.youtube_id) self.youtube_meta = response diff --git a/tubearchivist/home/src/index/playlist.py b/tubearchivist/home/src/index/playlist.py index fce019d..69dc5db 100644 --- a/tubearchivist/home/src/index/playlist.py +++ b/tubearchivist/home/src/index/playlist.py @@ -18,12 +18,7 @@ class YoutubePlaylist(YouTubeItem): es_path = False index_name = "ta_playlist" - yt_obs = { - "default_search": "ytsearch", - "quiet": True, - "skip_download": True, - "extract_flat": True, - } + yt_obs = {"extract_flat": True} yt_base = "https://www.youtube.com/playlist?list=" def __init__(self, youtube_id): diff --git a/tubearchivist/home/src/ta/helper.py b/tubearchivist/home/src/ta/helper.py index 5731115..3a7164d 100644 --- a/tubearchivist/home/src/ta/helper.py +++ b/tubearchivist/home/src/ta/helper.py @@ -11,7 +11,7 @@ import unicodedata from datetime import datetime from urllib.parse import parse_qs, urlparse -import yt_dlp +from home.src.download.yt_dlp_base import YtWrap def clean_string(file_name): @@ -184,14 +184,12 @@ class UrlListParser: @staticmethod def extract_channel_name(url): """find channel id from channel name with yt-dlp help""" - obs = { - "default_search": "ytsearch", - "quiet": True, + obs_request = { "skip_download": True, "extract_flat": True, "playlistend": 0, } - url_info = yt_dlp.YoutubeDL(obs).extract_info(url, download=False) + url_info = YtWrap(obs_request).extract(url) try: channel_id = url_info["channel_id"] except KeyError as error: