coollsd commited on
Commit
b9fb12f
·
verified ·
1 Parent(s): 9f76556

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -881,6 +881,22 @@ async def handle_video_stream(path: str, request: Request):
881
 
882
  return StreamingResponse(generate(), status_code=response.status_code, headers=headers)
883
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
884
  @app.get("/embed")
885
  async def embed_video(url: str, thumbnail: str):
886
  html = f'''
@@ -922,17 +938,6 @@ async def embed_video(url: str, thumbnail: str):
922
  '''
923
  return HTMLResponse(content=html)
924
 
925
- @app.get("/decrypt")
926
- async def decrypt_url(data: str, request: Request):
927
- try:
928
- browser_info = request.headers.get('User-Agent', '') + request.headers.get('Accept-Language', '') + str(request.client.host)
929
- key = hashlib.sha256(browser_info.encode()).hexdigest()
930
- fernet = Fernet(base64.urlsafe_b64encode(key[:32].encode()))
931
- decrypted_url = fernet.decrypt(data.encode()).decode()
932
- return RedirectResponse(url=decrypted_url)
933
- except Exception as e:
934
- raise HTTPException(status_code=400, detail="Invalid or expired link")
935
-
936
  async def get_cookies() -> Dict[str, str]:
937
  try:
938
  response = requests.get('https://replicate.com/levelsio/neon-tokyo', headers={
@@ -984,7 +989,7 @@ async def retry_upload(upload_url: str, file_content: bytes, content_type: str,
984
  print(f"Error during upload: {e}")
985
 
986
  await asyncio.sleep(delay)
987
- delay = min(delay * 2, 60)
988
 
989
  return False
990
 
 
881
 
882
  return StreamingResponse(generate(), status_code=response.status_code, headers=headers)
883
 
884
+ @app.get("/encrypted/{encrypted_data}")
885
+ async def handle_encrypted_stream(encrypted_data: str, request: Request):
886
+ try:
887
+ browser_info = request.headers.get('User-Agent', '') + request.headers.get('Accept-Language', '') + str(request.client.host)
888
+ key = hashlib.sha256(browser_info.encode()).hexdigest()[:32].encode()
889
+ fernet = Fernet(base64.urlsafe_b64encode(key))
890
+ decrypted_url = fernet.decrypt(base64.urlsafe_b64decode(encrypted_data)).decode()
891
+
892
+ if not decrypted_url.startswith('/rbxg/'):
893
+ raise ValueError("Invalid decrypted URL")
894
+
895
+ path = decrypted_url.split('/rbxg/')[1]
896
+ return await handle_video_stream(path, request)
897
+ except Exception as e:
898
+ raise HTTPException(status_code=400, detail="Invalid or expired link")
899
+
900
  @app.get("/embed")
901
  async def embed_video(url: str, thumbnail: str):
902
  html = f'''
 
938
  '''
939
  return HTMLResponse(content=html)
940
 
 
 
 
 
 
 
 
 
 
 
 
941
  async def get_cookies() -> Dict[str, str]:
942
  try:
943
  response = requests.get('https://replicate.com/levelsio/neon-tokyo', headers={
 
989
  print(f"Error during upload: {e}")
990
 
991
  await asyncio.sleep(delay)
992
+ delay = min(delay * 2, 60)
993
 
994
  return False
995