From 6f9b888833683161c14b688a4d73ad84c6b7f82f Mon Sep 17 00:00:00 2001 From: flagarby <180238523+flagarby@users.noreply.github.com> Date: Mon, 2 Sep 2024 20:52:43 -0500 Subject: [PATCH] Handle downloading URLs --- redgifs/const.py | 4 ++++ redgifs/http.py | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/redgifs/const.py b/redgifs/const.py index 52255e2..dadb748 100644 --- a/redgifs/const.py +++ b/redgifs/const.py @@ -28,6 +28,10 @@ r'https://thumbs\d+?\.redgifs\.com/(?P\w+)(?P-\w+)?\.(?P\w+)(\?.+(\d|\w))?' ) +REDGIFS_FILES_RE = re.compile( + r'https://files\.redgifs\.com/(?P\w+)\.(?P\w+)' +) + REDGIFS_ID_RE = re.compile( r'https://(thumbs(\d+)|api)\.redgifs\.com/(?P[a-zA-Z]+)' ) diff --git a/redgifs/http.py b/redgifs/http.py index 9f02f67..eb983e5 100644 --- a/redgifs/http.py +++ b/redgifs/http.py @@ -39,7 +39,7 @@ from . import __version__ from .errors import HTTPException from .enums import Order, Type -from .const import REDGIFS_THUMBS_RE +from .const import REDGIFS_FILES_RE, REDGIFS_THUMBS_RE from .utils import strip_ip __all__ = ('ProxyAuth',) @@ -255,6 +255,13 @@ def dl(url: str) -> int: return (dl(str_url)) raise TypeError(f'"{strip_ip(str_url)}" is an invalid RedGifs URL.') + # If it's a 'files' URL + if all([x in str(yarl_url.host) for x in ['files', 'redgifs']]): + match = re.match(REDGIFS_FILES_RE, str_url) + if match: + return (dl(str_url)) + raise TypeError(f'"{strip_ip(str_url)}" is an invalid RedGifs URL.') + # If it's a 'watch' URL if 'watch' in yarl_url.path: id = yarl_url.path.strip('/watch/')