untitled

Pasted Nov 30, 2026, 8:21 PM1 file33 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/zzgrs3v7whvm5vc6
untitled
import glob, re, shutil, subprocess, tempfile
from flask import Flask, abort, after_this_request, request, send_file, send_from_directory

app = Flask(__name__)

@app.route("/")
def home():
    return send_from_directory(".", "index.html")

@app.route("/api/fetch")
def fetch():
    url = request.args.get("url", "")
    if not re.match(r"^https?://([a-z0-9-]+\.)*tiktok\.com/", url):
        abort(400, "Only TikTok links are accepted.")
    d = tempfile.mkdtemp()

    @after_this_request
    def cleanup(resp):
        shutil.rmtree(d, ignore_errors=True)
        return resp

    r = subprocess.run(
        ["yt-dlp", "-x", "--audio-format", "mp3", "--no-playlist",
         "--max-filesize", "50M", "-o", d + "/a.%(ext)s", url],
        capture_output=True, timeout=90)
    files = glob.glob(d + "/a.*")
    if r.returncode or not files:
        abort(502, "Couldn't download that link.")
    return send_file(files[0], mimetype="audio/mpeg")

if __name__ == "__main__":
    app.run(port=5000)

1,000 chars · codepastes.com