LoremPizza commited on
Commit
12966ea
·
verified ·
1 Parent(s): 300b9de

Update test.py

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