-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
42 lines (36 loc) · 1.33 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from flask import Flask, request, render_template, flash
import os
import yt_dlp
app = Flask(__name__)
app.config["SECRET_KEY"] = os.getenv("SECRET_KEY")
@app.route("/")
def index():
url = request.args.get('url', type = str)
if not url:
return render_template("index.html")
extractors = yt_dlp.extractor.gen_extractors()
for e in extractors:
if e.suitable(url) and ('youtube' not in e.IE_NAME) and (e.IE_NAME != 'generic'):
flash(f"Unsupported URL: {url}", category="post-info")
return render_template("index.html")
ydl_opts = {
'playlist_items': '0',
'print': 'channel_url'
}
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
except yt_dlp.utils.DownloadError as e:
if "Unsupported URL" in str(e):
flash(f"Unsupported URL: {url}", category="post-info")
else:
print(e, url)
flash(f"Download Error: {url}", category="post-info")
return render_template("index.html")
channel_id = info.get("channel_id")
data = {
"channel_id": channel_id,
"feed_url": f"https://www.youtube.com/feeds/videos.xml?channel_id={channel_id}",
"webpage_url": info.get("webpage_url")
}
return render_template("index.html", data=data)