Flask: download YouTube, TikTok and Instagram videos
Many "YouTube downloader in Flask" tutorials embed pytube and break within weeks. Swapping the extraction for one CrawlFetch call keeps the Flask app tiny and stable.
How it fits together
A single route takes the URL from a form, resolves it server-side and renders a download link. No media is processed inside the Flask process.
Flask example
import osimport requestsfrom flask import Flask, render_template_string, requestapp = Flask(__name__)PAGE = """<form method=post><input name=url placeholder="Video URL"><button>Resolve</button></form>{% if video %}<p>{{ video.title }}</p><a href="{{ video.downloadUrl }}">Download</a>{% endif %}{% if error %}<p>{{ error }}</p>{% endif %}"""@app.route("/", methods=["GET", "POST"])def index():if request.method == "GET":return render_template_string(PAGE)r = requests.get("https://api.crawlfetch.com/v1/resolve",params={"url": request.form["url"]},headers={"Authorization": f"Bearer {os.environ['CRAWLFETCH_KEY']}"},timeout=15,)if not r.ok:return render_template_string(PAGE, error=f"Could not resolve ({r.status_code})")return render_template_string(PAGE, video=r.json())
Notes for Flask
- Add Flask-Limiter to stop abuse of a public form.
- Use
render_templatewith a real template file in production.
FAQ
Is this better than a pytube Flask app?
It removes the part that breaks. See pytube alternative.
Related
Last updated 2026-10-25