Spaces:
Running
Running
| from flask import Flask, request, render_template | |
| import requests | |
| import re | |
| app = Flask(__name__) | |
| def index(): | |
| messages = [] | |
| mp3_url = "" | |
| if request.method == "POST": | |
| song_url = request.form.get("udio_url") | |
| if song_url: | |
| messages.append(f"Fetching song page: {song_url}") | |
| # Fetch the song page | |
| r = requests.get(song_url) | |
| html = r.text | |
| # Extract embed URL | |
| embed_match = re.search(r'https://www\.udio\.com/embed/[a-zA-Z0-9]+', html) | |
| if embed_match: | |
| embed_url = embed_match.group(0) | |
| messages.append(f"Found embed URL: {embed_url}") | |
| # Fetch embed page | |
| r2 = requests.get(embed_url) | |
| embed_html = r2.text | |
| # Extract MP3 URL | |
| mp3_match = re.search(r'https://storage\.googleapis\.com/.*?\.mp3', embed_html) | |
| if mp3_match: | |
| mp3_url = mp3_match.group(0) | |
| messages.append(f"Found MP3 URL: {mp3_url}") | |
| else: | |
| messages.append("MP3 URL not found in embed page.") | |
| else: | |
| messages.append("Embed URL not found.") | |
| return render_template("index_feedback.html", messages=messages, mp3_url=mp3_url) | |