HawkeyeHS commited on
Commit
0625ee4
·
verified ·
1 Parent(s): c05bf5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  from pytubefix import YouTube
2
  from urllib.parse import quote
3
  from flask import Flask, request, jsonify
 
4
 
5
  app = Flask(__name__)
6
 
@@ -16,15 +17,16 @@ def get_audio_url():
16
  return jsonify({"error": "Missing 'url' query parameter"}), 400
17
 
18
  try:
19
- # Add use_oauth and allow_oauth_cache parameters
 
20
  yt = YouTube(
21
  video_url,
22
  use_oauth=False,
23
  allow_oauth_cache=False
24
  )
25
 
26
- # Force check availability
27
- yt.check_availability()
28
 
29
  # Get best audio-only stream
30
  audio_stream = (
@@ -38,6 +40,8 @@ def get_audio_url():
38
  if not audio_stream:
39
  return jsonify({"error": "No audio stream found"}), 404
40
 
 
 
41
  audio_url = audio_stream.url
42
  encoded_audio_url = quote(audio_url, safe="")
43
 
@@ -48,11 +52,13 @@ def get_audio_url():
48
  })
49
 
50
  except Exception as e:
 
 
51
  return jsonify({
52
  "error": str(e),
53
- "type": type(e).__name__
 
54
  }), 500
55
 
56
  if __name__ == "__main__":
57
- app.run(host="0.0.0.0", port=7860)
58
-
 
1
  from pytubefix import YouTube
2
  from urllib.parse import quote
3
  from flask import Flask, request, jsonify
4
+ import traceback
5
 
6
  app = Flask(__name__)
7
 
 
17
  return jsonify({"error": "Missing 'url' query parameter"}), 400
18
 
19
  try:
20
+ print(f"Attempting to fetch: {video_url}")
21
+
22
  yt = YouTube(
23
  video_url,
24
  use_oauth=False,
25
  allow_oauth_cache=False
26
  )
27
 
28
+ print(f"YouTube object created")
29
+ print(f"Video title: {yt.title}")
30
 
31
  # Get best audio-only stream
32
  audio_stream = (
 
40
  if not audio_stream:
41
  return jsonify({"error": "No audio stream found"}), 404
42
 
43
+ print(f"Audio stream found: {audio_stream}")
44
+
45
  audio_url = audio_stream.url
46
  encoded_audio_url = quote(audio_url, safe="")
47
 
 
52
  })
53
 
54
  except Exception as e:
55
+ error_trace = traceback.format_exc()
56
+ print(f"Error occurred: {error_trace}")
57
  return jsonify({
58
  "error": str(e),
59
+ "type": type(e).__name__,
60
+ "traceback": error_trace
61
  }), 500
62
 
63
  if __name__ == "__main__":
64
+ app.run(host="0.0.0.0", port=7860)