scrazzz / redgifs

Simple Python API wrapper for the RedGIFs API
https://redgifs.rtfd.io
MIT License
91 stars 12 forks source link

HTTP 403 forbidden #7

Closed AaronHuston closed 2 years ago

AaronHuston commented 2 years ago

Hello, scrazzz! Video stopped downloading a couple of days ago. Clicking on the download link reports an "HTTP 403 forbidden" error, the website denied the request to display the web page. The problem is on both version 1.2 and 1.3. How can I fix this? :(

For example: https://thumbs4.redgifs.com/PleasedCookedWarthog.mp4?expires=1662030000&signature=222b285c4ad1217b9472e45eb8430b5bfcf028d5fe4b868fa600d51fa2a1f1dc&for=my_ip

scrazzz commented 2 years ago

Ok, redgifs now does a validation on the ip-address and the user-agent to access direct medias (.mp4, .jpeg, etc..). I assume you used this library to get the link and then you opened that link in your own browser. This caused the 403 error.

To get around this headache, I will have to allow users to pass their own user-agent in the API() method. This will allow users to access the media links from their own browser. Hence, bypassing 403 error.

# Example illustration on how it would be used
from redgifs import API

api = API(user_agent="my_unique_user_agent")
api.search(...)

But the above solution will only work if: 1) The ip address you used to search for the media (API.search()) and to get the media (say for example, opening the media link in a browser) should be the same. 2) The user agent passed to API() should be the same as the one your browser/application uses.

scrazzz commented 2 years ago

Or I can make a new download() method that downloads the media using the user agent which is already provided by the library. This will make downloading the media easier since you won't have to open the link in your own browser.

I need to discuss this issue with someone to find a suitable method.

If anyone has any opinions or questions please let me know below.

scrazzz commented 2 years ago

I'll leave this for reference: https://github.com/Redgifs/api/wiki/Requesting-media-links

Krafting commented 2 years ago

Replacing thumbs4 with thumbs3 in the URL seems to work as a workaround for now:

https://thumbs3.redgifs.com/PleasedCookedWarthog.mp4

Might break in the future, but in the meantime, I hope this can help some people!

anytarseir67 commented 2 years ago

Or I can make a new download() method that downloads the media using the user agent which is already provided by the library. This will make downloading the media easier since you won't have to open the link in your own browser.

I need to discuss this issue with someone to find a suitable method.

If anyone has any opinions or questions please let me know below.

this seems like the most sensible solution.

if i were you i'd model it after discord.py's discord.Asset.save

scrazzz commented 2 years ago

I had thought about that, but it would require me to implement both synchronous and asynchronous methods on the URL class method which isn't a great solution. (Network request to get the file is different and the "save" method should be named differently).

So I have to make the download function on the API class which takes a url as the main parameter. This would make it possible to implement the function both synchronous and asynchronous-ly in a clean way.

This is how it would be used mainly:

from redgifs import API

api = API()
result = api.search('hitomi tanaka')
hd_url = result.gifs[0].urls.hd

# Optionally, allow a path to save the file to or create a downloads
# directory in the current path and place the downloaded file there.
api.download(hd_url)

This is the same for asynchronous code, by adding await.

anytarseir67 commented 2 years ago

i was talking more about how it handles where to save the file

scrazzz commented 2 years ago

I've pushed a new update, it should help you in downloading the media for you.

Sucks that redgifs had to do something like this.

anytarseir67 commented 2 years ago

image tf is this all about? if you don't want suggestions maybe don't add the help wanted label.

scrazzz commented 2 years ago

Those are unnecessary/invalid comments about using a "cursed" code to implement this feature. I thought of cleaning the comments section so others don't have to go through that.

If you are traumatized by me removing your comments on a small GitHub repository, then I suggest you to see a therapist.

And the 'help wanted' label, it's going to stay even if this issue has been solved. Cope.