Spaces:
Running
Running
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, render_template
|
| 2 |
+
import requests
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
@app.route("/", methods=["GET", "POST"])
|
| 8 |
+
def index():
|
| 9 |
+
messages = []
|
| 10 |
+
mp3_url = ""
|
| 11 |
+
if request.method == "POST":
|
| 12 |
+
song_url = request.form.get("udio_url")
|
| 13 |
+
if song_url:
|
| 14 |
+
messages.append(f"Fetching song page: {song_url}")
|
| 15 |
+
|
| 16 |
+
# Fetch the song page
|
| 17 |
+
r = requests.get(song_url)
|
| 18 |
+
html = r.text
|
| 19 |
+
|
| 20 |
+
# Extract embed URL
|
| 21 |
+
embed_match = re.search(r'https://www\.udio\.com/embed/[a-zA-Z0-9]+', html)
|
| 22 |
+
if embed_match:
|
| 23 |
+
embed_url = embed_match.group(0)
|
| 24 |
+
messages.append(f"Found embed URL: {embed_url}")
|
| 25 |
+
|
| 26 |
+
# Fetch embed page
|
| 27 |
+
r2 = requests.get(embed_url)
|
| 28 |
+
embed_html = r2.text
|
| 29 |
+
|
| 30 |
+
# Extract MP3 URL
|
| 31 |
+
mp3_match = re.search(r'https://storage\.googleapis\.com/.*?\.mp3', embed_html)
|
| 32 |
+
if mp3_match:
|
| 33 |
+
mp3_url = mp3_match.group(0)
|
| 34 |
+
messages.append(f"Found MP3 URL: {mp3_url}")
|
| 35 |
+
else:
|
| 36 |
+
messages.append("MP3 URL not found in embed page.")
|
| 37 |
+
else:
|
| 38 |
+
messages.append("Embed URL not found.")
|
| 39 |
+
|
| 40 |
+
return render_template("index_feedback.html", messages=messages, mp3_url=mp3_url)
|