From fd334bcafe02d77099b265f4ddf6ef7c6161685b Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 2 Jan 2022 15:38:45 +0700 Subject: [PATCH] fix legacy import alias for yt-dlp --- tubearchivist/home/src/download.py | 16 ++++++++-------- tubearchivist/home/src/helper.py | 4 ++-- tubearchivist/home/src/index.py | 28 ++++++++++++---------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/tubearchivist/home/src/download.py b/tubearchivist/home/src/download.py index 8e7819d..c513fa6 100644 --- a/tubearchivist/home/src/download.py +++ b/tubearchivist/home/src/download.py @@ -13,7 +13,7 @@ from datetime import datetime from time import sleep import requests -import yt_dlp as youtube_dl +import yt_dlp from home.src.config import AppConfig from home.src.helper import ( DurationConverter, @@ -155,8 +155,8 @@ class PendingList: "simulate": True, } try: - vid = youtube_dl.YoutubeDL(obs).extract_info(youtube_id) - except youtube_dl.utils.DownloadError: + vid = yt_dlp.YoutubeDL(obs).extract_info(youtube_id) + except yt_dlp.utils.DownloadError: print("failed to extract info for: " + youtube_id) return False # stop if video is streaming live now @@ -309,7 +309,7 @@ class ChannelSubscription: } if limit: obs["playlistend"] = self.channel_size - chan = youtube_dl.YoutubeDL(obs).extract_info(url, download=False) + chan = yt_dlp.YoutubeDL(obs).extract_info(url, download=False) last_videos = [(i["id"], i["title"]) for i in chan["entries"]] return last_videos @@ -551,7 +551,7 @@ class VideoDownloader: try: self.dl_single_vid(youtube_id) - except youtube_dl.utils.DownloadError: + except yt_dlp.utils.DownloadError: print("failed to download " + youtube_id) continue vid_dict = index_new_video(youtube_id) @@ -593,7 +593,7 @@ class VideoDownloader: @staticmethod def progress_hook(response): - """process the progress_hooks from youtube_dl""" + """process the progress_hooks from yt_dlp""" # title path = os.path.split(response["filename"])[-1][12:] filename = os.path.splitext(os.path.splitext(path)[0])[0] @@ -683,10 +683,10 @@ class VideoDownloader: for file_name in all_cached: if youtube_id in file_name: obs["outtmpl"] = os.path.join(dl_cache, file_name) - with youtube_dl.YoutubeDL(obs) as ydl: + with yt_dlp.YoutubeDL(obs) as ydl: try: ydl.download([youtube_id]) - except youtube_dl.utils.DownloadError: + except yt_dlp.utils.DownloadError: print("retry failed download: " + youtube_id) sleep(10) ydl.download([youtube_id]) diff --git a/tubearchivist/home/src/helper.py b/tubearchivist/home/src/helper.py index 4e018c1..61f698e 100644 --- a/tubearchivist/home/src/helper.py +++ b/tubearchivist/home/src/helper.py @@ -13,7 +13,7 @@ from urllib.parse import parse_qs, urlparse import redis import requests -import yt_dlp as youtube_dl +import yt_dlp def get_total_hits(index, es_url, es_auth, match_field): @@ -139,7 +139,7 @@ class UrlListParser: "extract_flat": True, "playlistend": 0, } - url_info = youtube_dl.YoutubeDL(obs).extract_info(url, download=False) + url_info = yt_dlp.YoutubeDL(obs).extract_info(url, download=False) try: channel_id = url_info["channel_id"] except KeyError as error: diff --git a/tubearchivist/home/src/index.py b/tubearchivist/home/src/index.py index e28acf8..40b48b5 100644 --- a/tubearchivist/home/src/index.py +++ b/tubearchivist/home/src/index.py @@ -12,7 +12,7 @@ from datetime import datetime from time import sleep import requests -import yt_dlp as youtube_dl +import yt_dlp from bs4 import BeautifulSoup from home.src.config import AppConfig from home.src.helper import DurationConverter, UrlListParser, clean_string @@ -257,7 +257,7 @@ class YoutubeChannel: "skip_download": True, "extract_flat": True, } - playlists = youtube_dl.YoutubeDL(obs).extract_info(url) + playlists = yt_dlp.YoutubeDL(obs).extract_info(url) all_entries = [(i["id"], i["title"]) for i in playlists["entries"]] return all_entries @@ -289,7 +289,7 @@ class YoutubeVideo: self.vid_dict = None def get_vid_dict(self): - """wrapper to loop around youtube_dl to retry on failure""" + """wrapper to loop around yt_dlp to retry on failure""" print(f"get video data for {self.youtube_id}") vid_dict = False for i in range(3): @@ -315,10 +315,10 @@ class YoutubeVideo: "noplaylist": True, } try: - vid = youtube_dl.YoutubeDL(obs).extract_info(youtube_id) + vid = yt_dlp.YoutubeDL(obs).extract_info(youtube_id) except ( - youtube_dl.utils.ExtractorError, - youtube_dl.utils.DownloadError, + yt_dlp.utils.ExtractorError, + yt_dlp.utils.DownloadError, ): print("failed to get info for " + youtube_id) return False @@ -489,12 +489,10 @@ class YoutubePlaylist: "playlistend": 0, } try: - playlist = youtube_dl.YoutubeDL(obs).extract_info( - url, download=False - ) + playlist = yt_dlp.YoutubeDL(obs).extract_info(url, download=False) except ( - youtube_dl.utils.ExtractorError, - youtube_dl.utils.DownloadError, + yt_dlp.utils.ExtractorError, + yt_dlp.utils.DownloadError, ): print("failed to get info for " + self.playlist_id) return False @@ -535,12 +533,10 @@ class YoutubePlaylist: obs["playlistend"] = playlistend try: - playlist = youtube_dl.YoutubeDL(obs).extract_info( - url, download=False - ) + playlist = yt_dlp.YoutubeDL(obs).extract_info(url, download=False) except ( - youtube_dl.utils.ExtractorError, - youtube_dl.utils.DownloadError, + yt_dlp.utils.ExtractorError, + yt_dlp.utils.DownloadError, ): print("failed to get plealist entries for " + self.playlist_id) return False