xhamster init

This commit is contained in:
Danilo Reyes 2024-10-12 23:29:27 -06:00
parent 29dfbd41ad
commit 83d21bdc6e

36
xhamster.py Executable file
View File

@ -0,0 +1,36 @@
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 python3Packages.requests python3Packages.beautifulsoup4 python3Packages.yt-dlp
import requests
import yt_dlp
from bs4 import BeautifulSoup
def fetch_page(url):
response = requests.get(url)
if response.status_code != 200:
print(f"Failed to retrieve the page. Status code: {response.status_code}")
return None
return response.text
def extract_video_links(html):
soup = BeautifulSoup(html, "html.parser")
video_links = soup.find_all("a", class_="video-thumb__image-container")
return map(lambda link: link.get("href"), video_links)
def download_video(link):
ydl_opts = {"format": "best", "outtmpl": "%(title)s.%(ext)s"}
yt_dlp.YoutubeDL(ydl_opts).download([link])
if __name__ == "__main__":
url = "https://es.xhamsterporno.mx/gay/creators/nipple-pump-pig/exclusive"
html_content = fetch_page(url)
if not html_content:
quit()
for video in extract_video_links(html_content):
download_video(video)