implement new YtBase class for index classes
This commit is contained in:
parent
4e699621a0
commit
a7d9b4584b
|
@ -5,8 +5,8 @@ functionality:
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
import yt_dlp
|
|
||||||
from home.src.download.yt_cookie import CookieHandler
|
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.es.connect import ElasticWrap
|
||||||
from home.src.ta.config import AppConfig
|
from home.src.ta.config import AppConfig
|
||||||
from home.src.ta.ta_redis import RedisArchivist
|
from home.src.ta.ta_redis import RedisArchivist
|
||||||
|
@ -19,11 +19,7 @@ class YouTubeItem:
|
||||||
index_name = False
|
index_name = False
|
||||||
yt_base = False
|
yt_base = False
|
||||||
yt_obs = {
|
yt_obs = {
|
||||||
"quiet": True,
|
|
||||||
"default_search": "ytsearch",
|
|
||||||
"skip_download": True,
|
"skip_download": True,
|
||||||
"check_formats": "selected",
|
|
||||||
"socket_timeout": 3,
|
|
||||||
"noplaylist": True,
|
"noplaylist": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,15 +42,7 @@ class YouTubeItem:
|
||||||
def get_from_youtube(self):
|
def get_from_youtube(self):
|
||||||
"""use yt-dlp to get meta data from youtube"""
|
"""use yt-dlp to get meta data from youtube"""
|
||||||
print(f"{self.youtube_id}: get metadata from youtube")
|
print(f"{self.youtube_id}: get metadata from youtube")
|
||||||
try:
|
response = YtWrap(self.yt_obs).extract(self.yt_base + self.youtube_id)
|
||||||
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
|
|
||||||
|
|
||||||
self.youtube_meta = response
|
self.youtube_meta = response
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,7 @@ class YoutubePlaylist(YouTubeItem):
|
||||||
|
|
||||||
es_path = False
|
es_path = False
|
||||||
index_name = "ta_playlist"
|
index_name = "ta_playlist"
|
||||||
yt_obs = {
|
yt_obs = {"extract_flat": True}
|
||||||
"default_search": "ytsearch",
|
|
||||||
"quiet": True,
|
|
||||||
"skip_download": True,
|
|
||||||
"extract_flat": True,
|
|
||||||
}
|
|
||||||
yt_base = "https://www.youtube.com/playlist?list="
|
yt_base = "https://www.youtube.com/playlist?list="
|
||||||
|
|
||||||
def __init__(self, youtube_id):
|
def __init__(self, youtube_id):
|
||||||
|
|
|
@ -11,7 +11,7 @@ import unicodedata
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from urllib.parse import parse_qs, urlparse
|
from urllib.parse import parse_qs, urlparse
|
||||||
|
|
||||||
import yt_dlp
|
from home.src.download.yt_dlp_base import YtWrap
|
||||||
|
|
||||||
|
|
||||||
def clean_string(file_name):
|
def clean_string(file_name):
|
||||||
|
@ -184,14 +184,12 @@ class UrlListParser:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def extract_channel_name(url):
|
def extract_channel_name(url):
|
||||||
"""find channel id from channel name with yt-dlp help"""
|
"""find channel id from channel name with yt-dlp help"""
|
||||||
obs = {
|
obs_request = {
|
||||||
"default_search": "ytsearch",
|
|
||||||
"quiet": True,
|
|
||||||
"skip_download": True,
|
"skip_download": True,
|
||||||
"extract_flat": True,
|
"extract_flat": True,
|
||||||
"playlistend": 0,
|
"playlistend": 0,
|
||||||
}
|
}
|
||||||
url_info = yt_dlp.YoutubeDL(obs).extract_info(url, download=False)
|
url_info = YtWrap(obs_request).extract(url)
|
||||||
try:
|
try:
|
||||||
channel_id = url_info["channel_id"]
|
channel_id = url_info["channel_id"]
|
||||||
except KeyError as error:
|
except KeyError as error:
|
||||||
|
|
Loading…
Reference in New Issue