Skip to content

Commit

Permalink
Handle downloading URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
flagarby committed Sep 3, 2024
1 parent ed7fdc8 commit 6f9b888
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions redgifs/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
r'https://thumbs\d+?\.redgifs\.com/(?P<id>\w+)(?P<type>-\w+)?\.(?P<ext>\w+)(\?.+(\d|\w))?'
)

REDGIFS_FILES_RE = re.compile(
r'https://files\.redgifs\.com/(?P<id>\w+)\.(?P<ext>\w+)'
)

REDGIFS_ID_RE = re.compile(
r'https://(thumbs(\d+)|api)\.redgifs\.com/(?P<id>[a-zA-Z]+)'
)
Expand Down
9 changes: 8 additions & 1 deletion redgifs/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',)
Expand Down Expand Up @@ -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/')
Expand Down

0 comments on commit 6f9b888

Please sign in to comment.