From b851e0bc04f061df091f08f63b06148d8ca716e5 Mon Sep 17 00:00:00 2001 From: Kyle Date: Fri, 4 Nov 2022 08:06:50 -0500 Subject: [PATCH 1/4] Fix redgifs for a third time --- .../extractors/redgifs_extractor.py | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/DownloaderForReddit/extractors/redgifs_extractor.py b/DownloaderForReddit/extractors/redgifs_extractor.py index 95df96e..fc7c58d 100644 --- a/DownloaderForReddit/extractors/redgifs_extractor.py +++ b/DownloaderForReddit/extractors/redgifs_extractor.py @@ -1,4 +1,4 @@ -from yt_dlp import YoutubeDL +import redgifs from .base_extractor import BaseExtractor from ..core.errors import Error @@ -48,10 +48,36 @@ def __init__(self, post, **kwargs): def extract_content(self): try: - with YoutubeDL({'format': 'mp4'}) as ydl: - result = ydl.extract_info(self.url, download=False) - content = self.make_content(result['url'], 'mp4') - HEADERS[content.id] = result['http_headers'] + api = redgifs.API() + api.login() + response = api.get_gif(self.get_gif_id()) + url = self.get_download_url(response) + content = self.make_content(url, 'mp4') + HEADERS[content.id] = api.http.headers except: - message = 'Failed to locate content' - self.handle_failed_extract(error=Error.FAILED_TO_LOCATE, message=message, extractor_error_message=message) + message = 'Failed to extract content from redgifs' + self.handle_failed_extract(error=Error.FAILED_TO_LOCATE, message=message, exetractor_error_message=message) + + def get_gif_id(self): + return self.url.rsplit('/', 1)[-1] + + @staticmethod + def get_download_url(data): + try: + return data.urls.hd + except KeyError: + return data.urls.sd + + # def extract_with_yt_dlp(self): + # """ + # This method is out of date at the moment. But with the way redgifs is changing their api, it could very well + # be relevant again soon. So this is staying here, just in case. + # """ + # try: + # with YoutubeDL({'format': 'mp4'}) as ydl: + # result = ydl.extract_info(self.url, download=False) + # content = self.make_content(result['url'], 'mp4') + # HEADERS[content.id] = result['http_headers'] + # except: + # message = 'Failed to locate content' + # self.handle_failed_extract(error=Error.FAILED_TO_LOCATE, message=message, extractor_error_message=message) From 1ff6dd9d232686f4de79b9b69a8671b867f1e2aa Mon Sep 17 00:00:00 2001 From: Kyle Date: Fri, 4 Nov 2022 08:09:30 -0500 Subject: [PATCH 2/4] Update requirements --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7880194..1fe9c85 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,10 +4,10 @@ pyqt5==5.15.4 PyQtNetworkAuth==5.15.4 python-json-logger==0.1.9 requests==2.20.0 -yt-dlp==2022.10.4 SQLAlchemy==1.3.13 toml==0.10.0 alembic==1.4.2 schedule==1.1.0 pyqtspinner==0.1.1 -cryptography==3.4.7 \ No newline at end of file +cryptography==3.4.7 +redgifs==1.4.0 \ No newline at end of file From 45474991f89f07ee36410c7197bec3f35a093d43 Mon Sep 17 00:00:00 2001 From: Kyle Date: Fri, 4 Nov 2022 09:22:57 -0500 Subject: [PATCH 3/4] Update requests version requirement --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1fe9c85..fcc5728 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ praw==7.5.0 pyqt5==5.15.4 PyQtNetworkAuth==5.15.4 python-json-logger==0.1.9 -requests==2.20.0 +requests==2.25.0 SQLAlchemy==1.3.13 toml==0.10.0 alembic==1.4.2 From f59f7fa17191f5b9b4bc8d817302b92bb6edbc66 Mon Sep 17 00:00:00 2001 From: Kyle Date: Fri, 4 Nov 2022 09:35:45 -0500 Subject: [PATCH 4/4] Add yt-dlp requirement back --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fcc5728..8d42285 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ alembic==1.4.2 schedule==1.1.0 pyqtspinner==0.1.1 cryptography==3.4.7 -redgifs==1.4.0 \ No newline at end of file +redgifs==1.4.0 +yt-dlp==2022.10.4 \ No newline at end of file