Spaces:
Paused
Paused
File size: 8,520 Bytes
62cfa2a 50cfda3 df2483b 12966ea df2483b 12966ea df2483b 331094b 97e509e df2483b 331094b f506922 062a52e 409e836 062a52e b00d818 2fa8c6b b00d818 062a52e 7a41ed2 300b9de aee3c4a 300b9de 1616859 300b9de 26c3cc8 300b9de 12966ea 7a41ed2 9ef9eb1 7a41ed2 9ef9eb1 7a41ed2 c9ca35f e66ea71 7a41ed2 97e509e 7a41ed2 12966ea 85af56d 12966ea 1af4c59 12966ea 111b123 12966ea 1267140 12966ea 0f3019c 12966ea c3db731 d246316 12966ea de458c1 12966ea d85fcb6 a9e66a8 d85fcb6 a9e66a8 d85fcb6 a9e66a8 d85fcb6 a9e66a8 d85fcb6 df2483b |
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
from fastapi import FastAPI, HTTPException, Response, Request
from fastapi.responses import StreamingResponse
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse, parse_qs,unquote,quote
import re
app = FastAPI()
User_Agent= "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 OPR/111.0.0.0"
# Global variable to store M3U8 content
m3u8_content = None
def fetch_m3u8(url):
"""Fetch the M3U8 file from the URL and store it in memory."""
response = requests.get("http://elmythus.serv00.net:2020/" + url,headers = {"User-Agent": User_Agent, "user-agent": User_Agent})
response.raise_for_status() # Raise an error for bad responses
return response.text
#This is just for testing, ignore that endpoint and the func
@app.get("/vixcloud/manifest.m3u8")
async def clone2_m3u8(d:str,token:str,expires:str,h:str = None, b:str = None, request: Request = None):
try:
m3u8 = f'{d}?token={token}&expires={expires}'
if h:
m3u8 = m3u8 + f'&h={h}'
if b:
m3u8 = m3u8 + f'&b={b}'
forwarded_proto = request.headers.get("x-forwarded-proto")
scheme = forwarded_proto if forwarded_proto else request.url.scheme
instance_url = f"{scheme}://{request.url.netloc}"
m3u8_content = fetch_m3u8(m3u8)
modified_playlist = m3u8_content.replace("https://vixcloud.co/playlist/", f"{instance_url}/clony/")
return Response(content=modified_playlist, media_type='application/vnd.apple.mpegurl')
except Exception as e:
print(f"Failed to fetch M3U8 file: {e}")
raise HTTPException(status_code=404, detail="M3U8 content not found")
'''
@app.get("/clone/manifest.m3u8")
async def clone_m3u8(d: str = None):
if d:
try:
if "%3D" in d:
d = unquote(d)
m3u8_content = fetch_m3u8(d)
return StreamingResponse(content=m3u8_content, media_type='application/vnd.apple.mpegurl')
except requests.RequestException as e:
print(f"Failed to fetch M3U8 file: {e}")
raise HTTPException(status_code=404, detail="M3U8 content not found")
'''
@app.get("/vixcloud/manifest.m3u8")
async def clone2_m3u8(d:str,token:str,expires:str,h:str = None, b:str = None, request: Request = None):
try:
m3u8 = f'{d}?token={token}&expires={expires}'
if h:
m3u8 = m3u8 + f'&h={h}'
if b:
m3u8 = m3u8 + f'&b={b}'
forwarded_proto = request.headers.get("x-forwarded-proto")
scheme = forwarded_proto if forwarded_proto else request.url.scheme
instance_url = f"{scheme}://{request.url.netloc}"
m3u8_content = fetch_m3u8(m3u8)
modified_playlist = m3u8_content.replace("https://vixcloud.co/playlist/", f"{instance_url}/clony/")
return Response(content=modified_playlist, media_type='application/vnd.apple.mpegurl')
except Exception as e:
print(f"Failed to fetch M3U8 file: {e}")
raise HTTPException(status_code=404, detail="M3U8 content not found")
@app.get("/clony/{segment:path}")
async def clony_m3u8(segment: str, request: Request):
base_url = "https://vixcloud.co/playlist/"
full_url = f"{base_url}{segment}?{request.query_params}"
m3u8_content = fetch_m3u8(full_url)
m3u8_content = re.sub(r"https://sc-b1-([0-2][0-9]|30).scws-content.net", "https://sc-u9-01.scws-content.net", m3u8_content)
return Response(content=m3u8_content, media_type='application/vnd.apple.mpegurl')
@app.get('/storage/enc.key')
async def get_key():
response = requests.get("http://elmythus.serv00.net:2020/" + 'https://vixcloud.co/storage/enc.key', headers = {"User-Agent": User_Agent, "user-agent": User_Agent})
response_headers = {
'date': response.headers['date'],
'content-length': response.headers['content-length'],
'content-type': 'application/octet-stream',
'access-control-allow-origin': '*'
}
return Response(
response.content,
response.status_code,
response_headers
)
async def get_version():
#Extract the version from the main page of the site
try:
import json
proxies = {}
SC_DOMAIN = "prof"
random_headers = {}
random_headers['Referer'] = f"https://streamingcommunity.{SC_DOMAIN}/"
random_headers['Origin'] = f"https://streamingcommunity.{SC_DOMAIN}"
random_headers['User-Agent'] = User_Agent
random_headers['user-agent'] = User_Agent
base_url = f'https://streamingcommunity.{SC_DOMAIN}/richiedi-un-titolo'
response = requests.get(base_url, headers=random_headers, allow_redirects = True, proxies = proxies)
print(response)
#Soup the response
soup = BeautifulSoup(response.text, "lxml")
# Extract version
version = json.loads(soup.find("div", {"id": "app"}).get("data-page"))['version']
return version
except Exception as e:
print("Couldn't find the version",e)
version = "65e52dcf34d64173542cd2dc6b8bb75b"
return version
@app.get("/")
async def get_film():
tid ="9997"
proxies = {}
version = await get_version()
SC_DOMAIN = "prof"
random_headers = {}
random_headers['Referer'] = "https://streamingcommunity.buzz/"
random_headers['Origin'] = "https://streamingcommunity.buzz"
random_headers['x-inertia'] = "true"
random_headers['x-inertia-version'] = version
random_headers['User-Agent'] = User_Agent
random_headers['user-agent'] = User_Agent
#Access the iframe
url = f'https://streamingcommunity.{SC_DOMAIN}/iframe/{tid}'
response = requests.get(url, headers=random_headers, allow_redirects=True, proxies = proxies)
iframe = BeautifulSoup(response.text, 'lxml')
#Get the link of iframe
iframe = iframe.find('iframe').get("src")
#Get the ID containted in the src of iframe
vixid = iframe.split("/embed/")[1].split("?")[0]
parsed_url = urlparse(iframe)
query_params = parse_qs(parsed_url.query)
random_headers['Referer'] = f"https://streamingcommunity.{SC_DOMAIN}/"
random_headers['Origin'] = f"https://streamingcommunity.{SC_DOMAIN}"
random_headers['x-inertia'] = "true"
random_headers['x-inertia-version'] = version
random_headers['User-Agent'] = User_Agent
random_headers['user-agent'] = User_Agent
#Get real token and expires by looking at the page in the iframe, vixcloud/embed
resp = requests.get("http://elmythus.serv00.net:2020/" + iframe, headers = random_headers, allow_redirects=True, proxies = proxies)
print(resp)
print(resp.text)
soup= BeautifulSoup(resp.text, "lxml")
script = soup.find("body").find("script").text
token = re.search(r"'token':\s*'(\w+)'", script).group(1)
expires = re.search(r"'expires':\s*'(\d+)'", script).group(1)
quality = re.search(r'"quality":(\d+)', script).group(1)
#Example url https://vixcloud.co/playlist/231315?b=1&token=bce060eec3dc9d1965a5d258dc78c964&expires=1728995040&rendition=1080p
url = f'https://vixcloud.co/playlist/{vixid}.m3u8?token={token}&expires={expires}'
if 'canPlayFHD' in query_params:
canPlayFHD = 'h=1'
url += "&h=1"
if 'b' in query_params:
b = 'b=1'
url += "&b=1"
'''
if quality == "1080":
if "&h" in url:
url = url
elif "&b" in url and quality == "1080":
url = url.replace("&b=1","&h=1")
elif quality == "1080" and "&b" and "&h" not in url:
url = url + "&h=1"
else:
url = url + f"&token={token}"
'''
url720 = f'https://vixcloud.co/playlist/{vixid}.m3u8'
url1 = quote(url)
return url,url1
@app.get("/proxy/{segment:path}")
async def proxy_m3u8(segment: str, request: Request):
# Base URL of the original M3U8
base_url = "https://vixcloud.co/playlist/"
# Append requested segment
full_url = f"{base_url}{segment}?{request.query_params}"
# Fetch the requested content
headers = {'User-Agent': 'Mozilla/5.0'} # Add headers if required
resp = requests.get(full_url, headers=headers)
# Return the content with the correct content type
return Response(content=resp.content, media_type=resp.headers.get('Content-Type', 'application/vnd.apple.mpegurl'))
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000) |