Spaces:
Runtime error
Runtime error
| from pytubefix import YouTube | |
| from urllib.parse import quote | |
| from flask import Flask, request, jsonify | |
| app = Flask(__name__) | |
| def hello_world(): | |
| return "Hello World!" | |
| def get_audio_url(): | |
| video_url = request.args.get("url") | |
| if not video_url: | |
| return jsonify({"error": "Missing 'url' query parameter"}), 400 | |
| try: | |
| proxies={ | |
| 'http':'http://lfvqisry-rotate:an43nwquy0o9@p.webshare.io:80', | |
| 'https':'http://lfvqisry-rotate:an43nwquy0o9@p.webshare.io:80' | |
| } | |
| yt = YouTube(video_url, proxies=proxies) | |
| # Get best audio-only stream | |
| audio_stream = ( | |
| yt.streams | |
| .filter(only_audio=True) | |
| .order_by("abr") | |
| .desc() | |
| .first() | |
| ) | |
| if not audio_stream: | |
| return jsonify({"error": "No audio stream found"}), 404 | |
| audio_url = audio_stream.url | |
| encoded_audio_url = quote(audio_url, safe="") | |
| return jsonify({ | |
| "raw_audio_url": audio_url, | |
| "encoded_audio_url": encoded_audio_url | |
| }) | |
| except Exception as e: | |
| return jsonify({"error": str(e)}), 500 | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=7860) |