Skip to content
This repository was archived by the owner on Jan 3, 2026. It is now read-only.

Commit 2bcf31c

Browse files
authored
Create redgifs.py
1 parent ffe38af commit 2bcf31c

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import re
2+
from processing.wrappers import http_downloader
3+
4+
tag = 'redgifs'
5+
order = 1
6+
7+
"""
8+
This Handler attempts to convert Gyfcat links into direct video links.
9+
"""
10+
11+
format_opts = ["webmUrl", "mp4Url", "gifUrl"]
12+
13+
14+
def handle(task, progress):
15+
url = task.url
16+
try:
17+
redgif_id = re.match(r'.*/(.*?)/?$', url).group(1)
18+
except AttributeError:
19+
return False
20+
21+
headers = {
22+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
23+
'Chrome/90.0.4430.93 Safari/537.36',}
24+
25+
content = Redgifs.retrieve_url(f'https://api.redgifs.com/v2/gfycats/{redgif_id}', headers=headers)
26+
27+
if content is None:
28+
return False
29+
30+
try:
31+
out = json.loads(content.text)['gif']['urls']["gif"]
32+
except (KeyError, AttributeError):
33+
return False
34+
except json.JSONDecodeError as e:
35+
return False
36+
progress.set_status("Downloading from redgifs..." % opt)
37+
return http_downloader.download_binary(out, task.file, prog=progress, handler_id=tag)

0 commit comments

Comments
 (0)