Ben 11 ay önce
ebeveyn
işleme
6f916bb1ac
1 değiştirilmiş dosya ile 34 ekleme ve 16 silme
  1. 34 16
      app.py

+ 34 - 16
app.py

@@ -1,6 +1,7 @@
 import logging
 
 import boto3
+import requests
 import yt_dlp
 from flask import Flask, request
 
@@ -24,6 +25,21 @@ def fetch_info(url):
         return info
 
 
+@app.route("/p", methods=["GET", "POST"])
+def p():
+    video_id = request.args.get("videoId")
+    format_id = request.args.get("formatId")
+    if video_id and format_id:
+        info = fetch_info(url=f"https://www.youtube.com/watch?v={video_id}")
+        if info:
+            for item in info.get("formats", []):
+                if item.get("format_id") == format_id:
+                    url = item.get("url")
+                    response = requests.get(url)
+                    return response.content, response.status_code, response.headers.items()
+    return {"status": 0}
+
+
 def convert_dto(info):
     thumbnails = []
     for item in info.get("thumbnails", []):
@@ -37,22 +53,24 @@ def convert_dto(info):
     for item in info.get("formats", []):
         if item.get("resolution") != "audio only" and item.get("url") and item.get("acodec") and item.get(
                 "acodec") != "none" and item.get("vcodec"):
-            formats.append({
-                "width": f"{item.get('width', 0)}",
-                "height": f"{item.get('height', 0)}",
-                "type": item.get("format", ""),
-                "quality": f'{item.get("format_note", "")}',
-                "itag": 0,
-                "fps": "0",
-                "bitrate": "0",
-                "url": item.get("url", ""),
-                "ext": item.get("ext"),
-                "vcodec": item.get("vcodec", ""),
-                "acodec": item.get("acodec", ""),
-                "vbr": "0",
-                "abr": "0",
-                "container": item.get("container")
-            })
+            format_id = item.get("format_id")
+            if format_id:
+                formats.append({
+                    "width": f"{item.get('width', 0)}",
+                    "height": f"{item.get('height', 0)}",
+                    "type": item.get("format", ""),
+                    "quality": f'{item.get("format_note", "")}',
+                    "itag": 0,
+                    "fps": "0",
+                    "bitrate": "0",
+                    "url": f"http://d2rueqse8qhuiu.cloudfront.net/p?videoId={info['display_id']}&formatId={format_id}",
+                    "ext": item.get("ext"),
+                    "vcodec": item.get("vcodec", ""),
+                    "acodec": item.get("acodec", ""),
+                    "vbr": "0",
+                    "abr": "0",
+                    "container": item.get("container")
+                })
     result = {
         "code": 200,
         "msg": "",