LoremPizza commited on
Commit
87b750e
·
verified ·
1 Parent(s): cf2e647

Update test.py

Browse files
Files changed (1) hide show
  1. test.py +16 -125
test.py CHANGED
@@ -1,131 +1,22 @@
1
- from fastapi import FastAPI, HTTPException, Response
2
- from fastapi.responses import StreamingResponse
3
  import requests
4
- from bs4 import BeautifulSoup
5
- from urllib.parse import urlparse, parse_qs,unquote,quote
6
- import re
7
- app = FastAPI()
8
- 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"
9
 
10
- # Global variable to store M3U8 content
11
- m3u8_content = None
12
 
13
- def fetch_m3u8(url):
14
- """Fetch the M3U8 file from the URL and store it in memory."""
15
- response = requests.get(url,headers = {"User-Agent": User_Agent, "user-agent": User_Agent})
16
- response.raise_for_status() # Raise an error for bad responses
17
- return response.text
18
 
19
- #This is just for testing, ignore that endpoint and the func
20
- @app.get("/vixcloud/manifest.m3u8")
21
- async def clone2_m3u8(d:str,token:str,expires:str,h:str):
22
- try:
23
- m3u8 = f'{d}?token={token}&expires={expires}&h={h}'
24
- print(m3u8)
25
- m3u8_content = fetch_m3u8(m3u8)
26
- return StreamingResponse(content=m3u8_content, media_type='application/vnd.apple.mpegurl')
27
- except requests.RequestException as e:
28
- print(f"Failed to fetch M3U8 file: {e}")
29
- raise HTTPException(status_code=404, detail="M3U8 content not found")
30
-
31
- @app.get("/clone/manifest.m3u8")
32
- async def clone_m3u8(d: str = None):
33
- if d:
34
- try:
35
- if "%3D" in d:
36
- d = unquote(d)
37
- m3u8_content = fetch_m3u8(d)
38
- return StreamingResponse(content=m3u8_content, media_type='application/vnd.apple.mpegurl')
39
- except requests.RequestException as e:
40
- print(f"Failed to fetch M3U8 file: {e}")
41
- raise HTTPException(status_code=404, detail="M3U8 content not found")
42
-
43
-
44
- async def get_version():
45
- #Extract the version from the main page of the site
46
-
47
-
48
- try:
49
- import json
50
- proxies = {}
51
- SC_DOMAIN = "prof"
52
- random_headers = {}
53
- random_headers['Referer'] = f"https://streamingcommunity.{SC_DOMAIN}/"
54
- random_headers['Origin'] = f"https://streamingcommunity.{SC_DOMAIN}"
55
- random_headers['User-Agent'] = User_Agent
56
- random_headers['user-agent'] = User_Agent
57
- base_url = f'https://streamingcommunity.{SC_DOMAIN}/richiedi-un-titolo'
58
- response = requests.get(base_url, headers=random_headers, allow_redirects = True, proxies = proxies)
59
- #Soup the response
60
- soup = BeautifulSoup(response.text, "lxml")
61
-
62
- # Extract version
63
- version = json.loads(soup.find("div", {"id": "app"}).get("data-page"))['version']
64
- return version
65
- except Exception as e:
66
- print("Couldn't find the version",e)
67
- version = "65e52dcf34d64173542cd2dc6b8bb75b"
68
- return version
69
 
70
- @app.get("/")
71
- async def get_film():
72
- tid ="9296"
73
- proxies = {}
74
- version = await get_version()
75
- SC_DOMAIN = "prof"
76
- random_headers = {}
77
- random_headers['Referer'] = "https://streamingcommunity.buzz/"
78
- random_headers['Origin'] = "https://streamingcommunity.buzz"
79
- random_headers['x-inertia'] = "true"
80
- random_headers['x-inertia-version'] = version
81
- random_headers['User-Agent'] = User_Agent
82
- random_headers['user-agent'] = User_Agent
83
- #Access the iframe
84
- url = f'https://streamingcommunity.{SC_DOMAIN}/iframe/{tid}'
85
- response = requests.get(url, headers=random_headers, allow_redirects=True, proxies = proxies)
86
- iframe = BeautifulSoup(response.text, 'lxml')
87
- #Get the link of iframe
88
- iframe = iframe.find('iframe').get("src")
89
- #Get the ID containted in the src of iframe
90
- vixid = iframe.split("/embed/")[1].split("?")[0]
91
- parsed_url = urlparse(iframe)
92
- query_params = parse_qs(parsed_url.query)
93
- random_headers['Referer'] = f"https://streamingcommunity.{SC_DOMAIN}/"
94
- random_headers['Origin'] = f"https://streamingcommunity.{SC_DOMAIN}"
95
- random_headers['x-inertia'] = "true"
96
- random_headers['x-inertia-version'] = version
97
- random_headers['User-Agent'] = User_Agent
98
- random_headers['user-agent'] = User_Agent
99
- #Get real token and expires by looking at the page in the iframe, vixcloud/embed
100
- resp = requests.get(iframe, headers = random_headers, allow_redirects=True, proxies = proxies)
101
- soup= BeautifulSoup(resp.text, "lxml")
102
- script = soup.find("body").find("script").text
103
- token = re.search(r"'token':\s*'(\w+)'", script).group(1)
104
- expires = re.search(r"'expires':\s*'(\d+)'", script).group(1)
105
- quality = re.search(r'"quality":(\d+)', script).group(1)
106
- #Example url https://vixcloud.co/playlist/231315?b=1&token=bce060eec3dc9d1965a5d258dc78c964&expires=1728995040&rendition=1080p
107
- url = f'https://vixcloud.co/playlist/{vixid}.m3u8?token={token}&expires={expires}'
108
- if 'canPlayFHD' in query_params:
109
- canPlayFHD = 'h=1'
110
- url += "&h=1"
111
- if 'b' in query_params:
112
- b = 'b=1'
113
- url += "&b=1"
114
- '''
115
- if quality == "1080":
116
- if "&h" in url:
117
- url = url
118
- elif "&b" in url and quality == "1080":
119
- url = url.replace("&b=1","&h=1")
120
- elif quality == "1080" and "&b" and "&h" not in url:
121
- url = url + "&h=1"
122
- else:
123
- url = url + f"&token={token}"
124
- '''
125
- url720 = f'https://vixcloud.co/playlist/{vixid}.m3u8'
126
- url1 = quote(url)
127
- return url,url1
128
 
129
- if __name__ == "__main__":
130
- import uvicorn
131
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
1
+ from flask import Flask, request, Response
 
2
  import requests
 
 
 
 
 
3
 
4
+ app = Flask(__name__)
 
5
 
6
+ @app.route('/proxy/<path:segment>', methods=['GET'])
7
+ def proxy_m3u8(segment):
8
+ # Base URL of the original M3U8
9
+ base_url = "https://vixcloud.co/playlist/"
 
10
 
11
+ # Append requested segment
12
+ full_url = f"{base_url}{segment}?{request.query_string.decode('utf-8')}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ # Fetch the requested content
15
+ headers = {'User-Agent': 'Mozilla/5.0'} # Add headers if required
16
+ resp = requests.get(full_url, headers=headers)
17
+
18
+ # Return the content with the correct content type
19
+ return Response(resp.content, content_type=resp.headers.get('Content-Type', 'application/vnd.apple.mpegurl'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ if __name__ == '__main__':
22
+ app.run(host='0.0.0.0', port=8000)