Ben 11 ay önce
işleme
c9b89dbed7
5 değiştirilmiş dosya ile 87 ekleme ve 0 silme
  1. 8 0
      .idea/.gitignore
  2. BIN
      __pycache__/app.cpython-311.pyc
  3. 69 0
      app.py
  4. 5 0
      requirements.txt
  5. 5 0
      run.sh

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

BIN
__pycache__/app.cpython-311.pyc


+ 69 - 0
app.py

@@ -0,0 +1,69 @@
+import logging
+
+import yt_dlp
+from flask import Flask, request
+
+app = Flask(__name__)
+
+
+@app.route("/extract", methods=["GET", "POST"])
+def extract():
+    url = request.json.get("url")
+    logging.info(f"url: ${url}")
+    with yt_dlp.YoutubeDL({"flat-playlist": True, "extract_flat": "flat-playlist"}) as ydl:
+        info = ydl.extract_info(url, download=False)
+        thumbnails = []
+        for item in info.get("thumbnails", []):
+            if item.get("width"):
+                thumbnails.append({
+                    "url": item.get("url", ""),
+                    "width": item.get("width", 0),
+                    "height": item.get("height", 0),
+                })
+        formats = []
+        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": item.get("width", 0),
+                    "height": 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")
+                })
+        return {
+            "code": 200,
+            "msg": "",
+            "data": {
+                "videoDetails": {
+                    "isLiveContent": info.get("is_live", False),
+                    "title": info.get("title", ""),
+                    "thumbnails": thumbnails,
+                    "description": info.get("description", ""),
+                    "lengthSeconds": int(info.get("duration", 0) / 100),
+                    "viewCount": info.get("view_count", 0),
+                    "keywords": [],
+                    "author": info.get("uploader", info.get("channel", "")),
+                    "channelID": info.get("channel_id", ""),
+                    "recommendInfo": [],
+                    "channelURL": info.get("channel_url", ""),
+                    "videoId": info.get("display_id", "")
+                },
+                "streamingData": {
+                    "formats": formats
+                }
+            }
+        }
+
+
+if __name__ == '__main__':
+    app.run(host='0.0.0.0', port=80, debug=True)

+ 5 - 0
requirements.txt

@@ -0,0 +1,5 @@
+beautifulsoup4==4.12.2
+Flask==2.3.2
+Flask_Cors==3.0.10
+Requests==2.31.0
+yt_dlp==2024.4.9

+ 5 - 0
run.sh

@@ -0,0 +1,5 @@
+git pull origin main --rebase
+pip3 install -r ./requirements.txt
+lsof -i:80 | awk '{print "kill -9 " $2}' | sudo sh -x
+nohup python3 ./app.py
+tail -f nohup.out