Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,29 @@ def get_info():
return jsonify({"error": str(e)}), 400


@app.route("/api/playlist", methods=["POST"])
def get_playlist_info():
data = request.json
url = data.get("url", "").strip()
if not url:
return jsonify({"error": "No URL provided"}), 400

cmd = ["yt-dlp", "--flat-playlist", "-J", url]
try:
result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
if result.returncode != 0:
return jsonify({"error": result.stderr.strip().split("\n")[-1]}), 400

info = json.loads(result.stdout)
entries = info.get("entries", [])
urls = [entry.get("url") for entry in entries if entry.get("url")]
return jsonify({"urls": urls})
except subprocess.TimeoutExpired:
return jsonify({"error": "Timed out fetching playlist info"}), 400
except Exception as e:
return jsonify({"error": str(e)}), 400


@app.route("/api/download", methods=["POST"])
def start_download():
data = request.json
Expand Down
16 changes: 16 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,22 @@ <h1>Re<em>Clip</em></h1>
container.innerHTML = '';
cardData = [];

// Check if youtube playlist URL
for (let i = 0; i < urls.length; i++) {
if (urls[i].includes('list=')) {
const res = await fetch('/api/playlist', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: urls[i] }),
});
const data = await res.json();
if (data.urls) {
// replace playlist URL with individual video URLs
urls.splice(i, 1, ...data.urls);
}
}
}

for (let i = 0; i < urls.length; i++) {
const url = urls[i];
const idx = cardData.length;
Expand Down