Spaces:
Sleeping
Sleeping
File size: 3,210 Bytes
e37348d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import requests
import re
import urllib.parse as urlparse
from helpers.functions import Utils
class VidSrc:
def __init__(self):
self.base_url = "https://vidsrc.su"
self.headers = {
'Accept': '*/*',
}
self.video_data_list = []
self.utils = Utils()
def build_url(self, tmdb_id, media_type, season=None, episode=None):
if media_type == "movie":
return f"{self.base_url}/embed/movie/{tmdb_id}"
elif media_type == "tv":
return f"{self.base_url}/embed/tv/{tmdb_id}/{season}/{episode}"
else:
raise ValueError("Invalid media type. Must be 'movie' or 'tv'.")
def extract_urls(self, data):
return re.findall(r"url:\s*'(https?://[^\']+)'", data)
def sanitize_stream_url(self, raw_url):
try:
unquoted_url = urlparse.unquote(raw_url)
stream_part = unquoted_url.split("?url=")[-1].split(".m3u8")[0] + ".m3u8"
stream_url = urlparse.unquote(stream_part)
return stream_url
except Exception as e:
print(f"[sanitize_stream_url] Error: {e}")
return None
def get_stream(self, tmdb_id, imdb_id, media_type, title, year, season=None, episode=None):
self.video_data_list = []
final_url = self.build_url(tmdb_id, media_type, season, episode)
response = requests.get(final_url, headers=self.headers)
if response.status_code != 200:
print(f"[get_stream] Failed to fetch embed page. Status code: {response.status_code}")
return self.video_data_list
data = response.text
stream_urls = self.extract_urls(data)
for stream_url in stream_urls:
if stream_url.endswith(".m3u8") or stream_url.endswith(".mp4"):
headers = {
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
'Referer': 'https://vidsrc.su/',
'Origin': 'https://vidsrc.su/',
}
if self.utils.is_accessible(stream_url, headers=headers):
self.video_data_list.append({
"videoSource": f"VIDSRC_{len(self.video_data_list)+1}",
"videoUrl": stream_url,
"videoHeaders": {
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
'Referer': 'https://vidsrc.su/',
'Origin': 'https://vidsrc.su/',
},
})
else:
sanitized_url = self.sanitize_stream_url(stream_url)
if sanitized_url:
self.video_data_list.append({
"videoSource": f"VIDSRC_{len(self.video_data_list)+1}",
"videoUrl": sanitized_url,
"videoHeaders": {}
})
return self.video_data_list
|