From 80a651cb744068dbc9aaa2ae075d2e4071a631c5 Mon Sep 17 00:00:00 2001 From: Le-Stagiaire Date: Thu, 4 Jul 2024 18:35:33 +0200 Subject: [PATCH] make it work again --- half_past_five/half_past_five.py | 20 +++++++++++++++++--- static/js/main.js | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/half_past_five/half_past_five.py b/half_past_five/half_past_five.py index 2378d2c..1cda84b 100755 --- a/half_past_five/half_past_five.py +++ b/half_past_five/half_past_five.py @@ -38,10 +38,24 @@ def __call__(self, cls): cls.__name__ + self.suffix)),) ) return cls + + +class BaseHandler(tornado.web.RequestHandler): + + def set_default_headers(self): + self.set_header("Access-Control-Allow-Origin", "*") + self.set_header("Access-Control-Allow-Headers", "x-requested-with") + self.set_header('Access-Control-Allow-Methods', ' PUT, DELETE, OPTIONS') + + def options(self): + # no body + self.set_status(204) + self.finish() @url(r'/') -class MainHandler(RequestHandler): +class MainHandler(BaseHandler): + def get(self): self.render("index.html") @@ -58,7 +72,7 @@ def post(self): download_path = os.path.join( server.settings['static_path'], 'downloads', '%(title)s.%(ext)s') out = subprocess.run( - ['youtube-dl', url, '-f', '140', '-o', download_path, + ['yt-dlp', url, '-f', '140', '-o', download_path, '--print-json'], stdout=subprocess.PIPE) out = json.loads(out.stdout.decode('utf-8')) self.write(out) @@ -66,7 +80,7 @@ def post(self): @url(r'/crop_and_download') -class CropHandler(RequestHandler): +class CropHandler(BaseHandler): def post(self): # Extract start and end from form params diff --git a/static/js/main.js b/static/js/main.js index 9864ae2..8ccaffb 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -153,7 +153,8 @@ function init() { xhttp.onreadystatechange = () => { if (xhttp.readyState == 4 && xhttp.status == 200) { const response = JSON.parse(xhttp.response); - wavesurfer.load("/" + response._filename); + console.log(response._filename); + wavesurfer.load(response._filename.split("..").at(-1)); document.getElementById("loading").className = "hidden"; document.getElementById("video-title").textContent = response.title; document.getElementById("crop-title").value = `${response.title}_cut`;