EchterAlsFake / xvideos_api

a Python API for xvideos.com
GNU Lesser General Public License v3.0
16 stars 4 forks source link

Preview Thumb Video #8

Closed Brook-sys closed 1 week ago

Brook-sys commented 1 month ago

Hello, first of all I would like to congratulate you on the excellent work done in developing this script. I used it a little and really liked it.

I would just like to suggest one more feature that would be useful, which I noticed was missing, because when I get the video information, from any video, several pieces of information come up, but one that doesn't come up is the URL of the video preview thumbnail, the video that appears when you hover your mouse over the video. This would be very useful, and honestly in my case it is crucial. Would it be possible to add a feature like this?

I am a beginner in programming and I analyzed the HTML of the XVideos website, and from what it seems, this preview video only appears in the HTML of the page when the mouse is over the video thumbnail. I couldn't find it anywhere else in the HTML of the page, and when I try to capture the link it always appears, because it has moved from above the thumb. Is there any way to create a function to capture it?

Excuse me for any mistakes, I am using Google Translate.

EchterAlsFake commented 1 month ago

Hello, unfortunately it probably won't be possible to implement this feature, because when you hover over the video with the mouse a JavaScript script is ececuted in the background which plays this video. I can see if I find this script somehow in the HTML code and then extract the video source from the JS code, but this is very theoretical. I'll try to do it, but it will be like 20% chance that I have success.

The requests library which is being used by the API does not allow to manually trigger or inject mouse hover actions to load dynamic JS scripts. This would only be possible through Selenium, but this is out of scope for this project, because it requires a browser being installed and it works by opening the browser and simulating a manual user interaction.

EchterAlsFake commented 4 weeks ago

Update:

I found the source (probably), but I need to get around their detection system, because they try to block my request and I don't know why. There seems to be a token and authentication system, but I have no idea how to get past that yet, but at least I found the source.

Brook-sys commented 2 weeks ago

Hello, regarding this topic I believe I have found a way to solve it, I was analyzing the xvideos code in depth, and I found a way to get the video thumb through the thumb image link, just by changing it with regex, I created a mini script in python for this, I created it a few days ago, but testing it I saw that it did not work in 100% of the cases, then analyzing it better I saw that there were some rules that I would have to add to the regex to work better, in this case I have not added them yet, but the point is, I am new to this thing of contributing to other people's projects (I myself have never made a contribution), but I would like to help with this functionality.

Brook-sys commented 2 weeks ago

the mini script I made (it still needs some improvements because as I said before it doesn't work in 100% of cases): def convert_thumb_to_vid(self,url): base_url = re.sub(r'/thumbs(169)?(xnxx)?((l*)|(poster))/', '/videopreview/', url[:url.rfind("/")]) return re.sub(r'(-\d+)_([\d]+)', r'_\2\1', base_url) + "_169.mp4"

the url parameter is the url of the video's image thumb

EchterAlsFake commented 1 week ago

Okay that looks pretty interesting, so you give in a thumbnail URL you found inside the code and the function converts it, to a real thumbnail URL which we can access. Did I understand that right?

If yes, can you give me an example URL and tell me where you found the URL in the code?

(Sorry for the late Response, I actually wrote to you the same day, but my Internet connection suddenly closed and then it didn't get sent.)

Brook-sys commented 1 week ago

Hi, in fact, in the method's input URL, I'm using the ".thumbnail_url" attribute of your library's video class.

I'd like to explain how I discovered this. I got the URL of the thumb video and searched for parts of it in the JavaScript of the XVideos page. Then I found the method that creates the URL. From what I could tell, the video thumb URL is created using the URL of the thumb image. So I tried to unravel the code and created this function. I hope this helps in the development of the library. Good luck with the project. I really liked it.

(I'm using Google Translate, so please ignore any semantic errors.)