LoremPizza commited on
Commit
300b9de
·
verified ·
1 Parent(s): 331094b

Update test.py

Browse files
Files changed (1) hide show
  1. test.py +9 -18
test.py CHANGED
@@ -2,7 +2,6 @@ from fastapi import FastAPI, HTTPException, Response
2
  import requests
3
 
4
  app = FastAPI()
5
- m3u8_url = "https://hfs302.serversicuro.cc/hls/,dnzpfec63dg4a3gyvapx72rcyqjwtaix6g6gsfexbdzt3uusvijhskjgwl5a,.urlset/master.m3u8"
6
 
7
  # Global variable to store M3U8 content
8
  m3u8_content = None
@@ -13,24 +12,16 @@ def fetch_m3u8(url):
13
  response.raise_for_status() # Raise an error for bad responses
14
  return response.text
15
 
16
- @app.get("/")
17
- async def startup_event():
18
- """Fetch the M3U8 file on application startup."""
19
- global m3u8_content
20
- try:
21
- global m3u8_content
22
- m3u8_content = fetch_m3u8(m3u8_url)
23
- except requests.RequestException as e:
24
- print(f"Failed to fetch M3U8 file: {e}")
25
-
26
- @app.get("/video-path/myvideo.m3u8")
27
- async def serve_m3u8():
28
- """Serve the in-memory M3U8 content."""
29
- if m3u8_content is None:
30
- raise HTTPException(status_code=404, detail="M3U8 content not found")
31
-
32
- return Response(content=m3u8_content, media_type='application/vnd.apple.mpegurl')
33
 
 
 
 
 
 
 
 
 
 
34
  if __name__ == "__main__":
35
  import uvicorn
36
  uvicorn.run(app, host="0.0.0.0", port=8000)
 
2
  import requests
3
 
4
  app = FastAPI()
 
5
 
6
  # Global variable to store M3U8 content
7
  m3u8_content = None
 
12
  response.raise_for_status() # Raise an error for bad responses
13
  return response.text
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ @app.get("/clone/manifest.m3u8")
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)