|
@@ -2,13 +2,21 @@ import logging
|
|
|
|
|
|
import yt_dlp
|
|
|
from flask import Flask, request
|
|
|
+from tinydb import TinyDB
|
|
|
+from tinydb.table import Document
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
+db = TinyDB('data.json')
|
|
|
+
|
|
|
|
|
|
@app.route("/extract", methods=["GET", "POST"])
|
|
|
def extract():
|
|
|
url = request.json.get("url")
|
|
|
+ result = db.get(doc_id=url)
|
|
|
+ if result:
|
|
|
+ logging.info("find from data.json, so return")
|
|
|
+ return result
|
|
|
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)
|
|
@@ -40,7 +48,7 @@ def extract():
|
|
|
"abr": 0,
|
|
|
"container": item.get("container")
|
|
|
})
|
|
|
- return {
|
|
|
+ result = {
|
|
|
"code": 200,
|
|
|
"msg": "",
|
|
|
"data": {
|
|
@@ -63,6 +71,8 @@ def extract():
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ db.upsert(Document(value=result, doc_id=url))
|
|
|
+ return result
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|