Ben 11 months ago
parent
commit
6faee61eb5
2 changed files with 4 additions and 5 deletions
  1. 4 5
      app.py
  2. 0 0
      data.json

+ 4 - 5
app.py

@@ -3,7 +3,6 @@ import logging
 import yt_dlp
 from flask import Flask, request
 from tinydb import TinyDB
-from tinydb.table import Document
 
 app = Flask(__name__)
 
@@ -13,10 +12,10 @@ db = TinyDB('data.json')
 @app.route("/extract", methods=["GET", "POST"])
 def extract():
     url = request.json.get("url")
-    result = db.get(doc_id=url)
+    result = db.search(lambda x: x["url"] == url)
     if result:
         logging.info("find from data.json, so return")
-        return result
+        return result[0]
     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)
@@ -70,9 +69,9 @@ def extract():
                     "formats": formats
                 }
             },
-            "debug": info
+            "id": "MusicDetailViewModel_detail_url"
         }
-        # db.upsert(Document(value=result, doc_id=url))
+        db.insert({"result": result, "url": url})
         return result
 
 

File diff suppressed because it is too large
+ 0 - 0
data.json


Some files were not shown because too many files changed in this diff