HawkeyeHS commited on
Commit
8ace90a
·
verified ·
1 Parent(s): 0dda484

Upload 3 files

Browse files
Files changed (3) hide show
  1. DockerFile +17 -0
  2. app.py +46 -0
  3. requirements.txt +2 -0
DockerFile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python base image
2
+ FROM python:3.9
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Copy current files into container
8
+ COPY . /app
9
+
10
+ # Install Flask
11
+ RUN pip install flask gunicorn
12
+
13
+ # Expose default port
14
+ EXPOSE 7860
15
+
16
+ # Run with Gunicorn
17
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pytubefix import YouTube
2
+ from urllib.parse import quote
3
+ from flask import Flask, request, jsonify
4
+
5
+ app = Flask(__name__)
6
+
7
+ @app.route('/')
8
+ def hello_world():
9
+ return "Hello World!"
10
+
11
+ @app.route('/audio_url')
12
+ def get_audio_url():
13
+ video_url = request.args.get("url")
14
+
15
+ if not video_url:
16
+ return jsonify({"error": "Missing 'url' query parameter"}), 400
17
+
18
+ try:
19
+ yt = YouTube(video_url)
20
+
21
+ # Get best audio-only stream
22
+ audio_stream = (
23
+ yt.streams
24
+ .filter(only_audio=True)
25
+ .order_by("abr")
26
+ .desc()
27
+ .first()
28
+ )
29
+
30
+ if not audio_stream:
31
+ return jsonify({"error": "No audio stream found"}), 404
32
+
33
+ audio_url = audio_stream.url
34
+ encoded_audio_url = quote(audio_url, safe="")
35
+
36
+ return jsonify({
37
+ "raw_audio_url": audio_url,
38
+ "encoded_audio_url": encoded_audio_url
39
+ })
40
+
41
+ except Exception as e:
42
+ return jsonify({"error": str(e)}), 500
43
+
44
+
45
+ if __name__ == "__main__":
46
+ app.run(debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ flask
2
+ pytubefix