DmitrMakeev commited on
Commit
37ed8b5
·
verified ·
1 Parent(s): 6d83c51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -72,32 +72,39 @@ def up_fa():
72
 
73
 
74
 
 
 
 
 
 
75
  def get_video_url(video_url):
76
  ydl_opts = {
77
  'format': 'best', # Выбирает лучшее качество
78
  'quiet': True, # Не выводить информацию в консоль
79
  }
80
 
81
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
82
- info_dict = ydl.extract_info(video_url, download=False)
83
- video_url = info_dict.get('url', None)
 
 
 
84
 
85
  return video_url
86
 
87
  @app.route('/tutub')
88
- def index_tutub():
89
  return render_template('tutub.html')
90
 
91
  @app.route('/play', methods=['POST'])
92
  def play():
93
  video_url = request.form['video_url']
94
  stream_url = get_video_url(video_url)
95
- return render_template('player.html', stream_url=stream_url)
96
-
97
-
98
-
99
 
 
 
100
 
 
101
 
102
 
103
 
 
72
 
73
 
74
 
75
+
76
+
77
+
78
+
79
+
80
  def get_video_url(video_url):
81
  ydl_opts = {
82
  'format': 'best', # Выбирает лучшее качество
83
  'quiet': True, # Не выводить информацию в консоль
84
  }
85
 
86
+ try:
87
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
88
+ info_dict = ydl.extract_info(video_url, download=False)
89
+ video_url = info_dict.get('url', None)
90
+ except yt_dlp.utils.DownloadError as e:
91
+ return str(e)
92
 
93
  return video_url
94
 
95
  @app.route('/tutub')
96
+ def indextutub():
97
  return render_template('tutub.html')
98
 
99
  @app.route('/play', methods=['POST'])
100
  def play():
101
  video_url = request.form['video_url']
102
  stream_url = get_video_url(video_url)
 
 
 
 
103
 
104
+ if "Unsupported URL" in stream_url:
105
+ return jsonify({"error": "Unsupported URL"}), 400
106
 
107
+ return render_template('player.html', stream_url=stream_url)
108
 
109
 
110