Advertisement
DeaD_EyE

gehtslos.py

Jan 29th, 2025
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import datetime
  3. import subprocess
  4. import time
  5. from urllib.request import Request, urljoin, urlopen
  6.  
  7. from bs4 import BeautifulSoup
  8.  
  9. CSS_SELECTOR = "div.thumbnail__thumb.thumbnail__thumb--live > a.videostream__link.link"
  10.  
  11.  
  12. def get_latest():
  13.     base_url = "https://rumble.com"
  14.     channel = "c/SC360Media/livestreams"
  15.     browser = "Mozilla/5.0 (X11; Linux x86_64; rv:126.0) Gecko/20100101 Firefox/126.0"
  16.     headers = {"User-Agent": browser}
  17.  
  18.     url = urljoin(base_url, channel)
  19.     request = Request(url, headers=headers)
  20.  
  21.     while True:
  22.         content = urlopen(request).read()
  23.         doc = BeautifulSoup(content, "html.parser")
  24.  
  25.         try:
  26.             live = doc.select_one(CSS_SELECTOR)["href"]
  27.         except TypeError as e:
  28.             now = datetime.datetime.now().replace(microsecond=0)
  29.             print(f"[{now}]: Bitte warten, Sendung ist noch nicht live")
  30.             time.sleep(10)
  31.             continue
  32.         else:
  33.             return urljoin(base_url, live)
  34.  
  35.  
  36. if __name__ == "__main__":
  37.     # get url, blocks until it selects a live-stream
  38.     url = get_latest()
  39.  
  40.     # start firefox or open a new tab if a firefox process is active
  41.     proc = subprocess.Popen(
  42.         ["firefox", url], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
  43.     )
  44.  
  45.  
  46.  
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement