Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
MalloyDelacroix committed Nov 4, 2022
2 parents 8370444 + 71e4eed commit c6777f8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
40 changes: 33 additions & 7 deletions DownloaderForReddit/extractors/redgifs_extractor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from yt_dlp import YoutubeDL
import redgifs

from .base_extractor import BaseExtractor
from ..core.errors import Error
Expand Down Expand Up @@ -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)
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ praw==7.5.0
pyqt5==5.15.4
PyQtNetworkAuth==5.15.4
python-json-logger==0.1.9
requests==2.20.0
yt-dlp==2022.10.4
requests==2.25.0
SQLAlchemy==1.3.13
toml==0.10.0
alembic==1.4.2
schedule==1.1.0
pyqtspinner==0.1.1
cryptography==3.4.7
cryptography==3.4.7
redgifs==1.4.0
yt-dlp==2022.10.4

0 comments on commit c6777f8

Please sign in to comment.