From eeb2054606b3956cc032c1d6ecc1e7f6fe18ec7b Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Sat, 2 Oct 2021 12:23:13 +1000 Subject: [PATCH] Switch to yt-dlp --- bdfr/site_downloaders/youtube.py | 8 ++++---- requirements.txt | 2 +- tests/site_downloaders/test_pornhub.py | 2 +- tests/site_downloaders/test_youtube.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bdfr/site_downloaders/youtube.py b/bdfr/site_downloaders/youtube.py index a870c2e..ba82007 100644 --- a/bdfr/site_downloaders/youtube.py +++ b/bdfr/site_downloaders/youtube.py @@ -5,7 +5,7 @@ import tempfile from pathlib import Path from typing import Callable, Optional -import youtube_dl +import yt_dlp from praw.models import Submission from bdfr.exceptions import NotADownloadableLinkError, SiteDownloaderError @@ -45,9 +45,9 @@ class Youtube(BaseDownloader): download_path = Path(temp_dir).resolve() ytdl_options['outtmpl'] = str(download_path) + '/' + 'test.%(ext)s' try: - with youtube_dl.YoutubeDL(ytdl_options) as ydl: + with yt_dlp.YoutubeDL(ytdl_options) as ydl: ydl.download([self.post.url]) - except youtube_dl.DownloadError as e: + except yt_dlp.DownloadError as e: raise SiteDownloaderError(f'Youtube download failed: {e}') downloaded_files = list(download_path.iterdir()) @@ -64,7 +64,7 @@ class Youtube(BaseDownloader): def get_video_attributes(url: str) -> dict: yt_logger = logging.getLogger('youtube-dl') yt_logger.setLevel(logging.CRITICAL) - with youtube_dl.YoutubeDL({'logger': yt_logger, }) as ydl: + with yt_dlp.YoutubeDL({'logger': yt_logger, }) as ydl: try: result = ydl.extract_info(url, download=False) return result diff --git a/requirements.txt b/requirements.txt index e7b5ff1..8ceffdb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ ffmpeg-python>=0.2.0 praw>=7.2.0 pyyaml>=5.4.1 requests>=2.25.1 -youtube-dl>=2021.3.14 +yt-dlp>=2021.9.25 \ No newline at end of file diff --git a/tests/site_downloaders/test_pornhub.py b/tests/site_downloaders/test_pornhub.py index e07da45..5c220cc 100644 --- a/tests/site_downloaders/test_pornhub.py +++ b/tests/site_downloaders/test_pornhub.py @@ -12,7 +12,7 @@ from bdfr.site_downloaders.pornhub import PornHub @pytest.mark.online @pytest.mark.slow @pytest.mark.parametrize(('test_url', 'expected_hash'), ( - ('https://www.pornhub.com/view_video.php?viewkey=ph5a2ee0461a8d0', '5f5294b9b97dbb7cb9cf8df278515621'), + ('https://www.pornhub.com/view_video.php?viewkey=ph6074c59798497', 'd9b99e4ebecf2d8d67efe5e70d2acf8a'), )) def test_find_resources_good(test_url: str, expected_hash: str): test_submission = MagicMock() diff --git a/tests/site_downloaders/test_youtube.py b/tests/site_downloaders/test_youtube.py index 1f6b81a..14c6648 100644 --- a/tests/site_downloaders/test_youtube.py +++ b/tests/site_downloaders/test_youtube.py @@ -13,8 +13,8 @@ from bdfr.site_downloaders.youtube import Youtube @pytest.mark.online @pytest.mark.slow @pytest.mark.parametrize(('test_url', 'expected_hash'), ( - ('https://www.youtube.com/watch?v=uSm2VDgRIUs', 'f70b704b4b78b9bb5cd032bfc26e4971'), - ('https://www.youtube.com/watch?v=GcI7nxQj7HA', '2bfdbf434ed284623e46f3bf52c36166'), + ('https://www.youtube.com/watch?v=uSm2VDgRIUs', '2d60b54582df5b95ec72bb00b580d2ff'), + ('https://www.youtube.com/watch?v=GcI7nxQj7HA', '5db0fc92a0a7fb9ac91e63505eea9cf0'), )) def test_find_resources_good(test_url: str, expected_hash: str): test_submission = MagicMock()