forked from Ethanscharlie/Happy-Ripper
Downloaded m4as
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
|||||||
|
.venv/
|
||||||
|
*.pyc
|
||||||
|
__pycache__/
|
||||||
|
instance/
|
||||||
|
.cache/
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
htmlcov/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
*.egg-info/
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*~
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
from flask import Flask, render_template, request, jsonify
|
||||||
|
from threading import Thread
|
||||||
|
import time
|
||||||
|
from yt_dlp import YoutubeDL
|
||||||
|
from yt_dlp.utils import DownloadError
|
||||||
|
import pathlib
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
|
def rip_worker(rip_queue: list[str]):
|
||||||
|
project_root_path = pathlib.Path(__file__).parent.resolve()
|
||||||
|
tmp_path = f"{project_root_path}/tmp"
|
||||||
|
|
||||||
|
while True:
|
||||||
|
queue_is_empty = len(rip_queue) == 0
|
||||||
|
if queue_is_empty:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Creates tmp directory, if it already exists, it clears it, and makes a new one.
|
||||||
|
if not os.path.isdir(tmp_path):
|
||||||
|
os.mkdir(tmp_path)
|
||||||
|
else:
|
||||||
|
shutil.rmtree(tmp_path)
|
||||||
|
os.mkdir(tmp_path)
|
||||||
|
|
||||||
|
current_url = rip_queue[0]
|
||||||
|
|
||||||
|
try:
|
||||||
|
with YoutubeDL(
|
||||||
|
{
|
||||||
|
"format": "m4a/bestaudio/best",
|
||||||
|
"postprocessors": [
|
||||||
|
{
|
||||||
|
"key": "FFmpegExtractAudio",
|
||||||
|
"preferredcodec": "m4a",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outtmpl": f"{tmp_path}/%(title)s.%(ext)s",
|
||||||
|
}
|
||||||
|
) as ydl:
|
||||||
|
error_code = ydl.download([current_url])
|
||||||
|
|
||||||
|
except DownloadError:
|
||||||
|
print("Download Error")
|
||||||
|
|
||||||
|
rip_queue.pop(0)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
rip_queue = []
|
||||||
|
ripping_thread = Thread(target=rip_worker, args=(rip_queue,), daemon=True).start()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def index():
|
||||||
|
return render_template("index.html")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/rip", methods=["POST"])
|
||||||
|
def rip():
|
||||||
|
url = request.form.get("url")
|
||||||
|
rip_queue.append(url)
|
||||||
|
return jsonify({"success": True, "message": f"Added, {url}!"})
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Happy Ripper</title>
|
||||||
|
<link
|
||||||
|
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css"
|
||||||
|
rel="stylesheet"
|
||||||
|
integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h2>Request</h2>
|
||||||
|
<form id="rip-form">
|
||||||
|
<div class="mb-3">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="url"
|
||||||
|
id="urlInput"
|
||||||
|
placeholder="https://music.youtube.com/..."
|
||||||
|
class="form-control"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Queue</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document
|
||||||
|
.getElementById("rip-form")
|
||||||
|
.addEventListener("submit", async function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const formData = new FormData(this);
|
||||||
|
|
||||||
|
const response = await fetch("/rip", {
|
||||||
|
method: "POST",
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<script
|
||||||
|
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"
|
||||||
|
integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user