|
|
from flask import Flask, request, jsonify |
|
|
import requests |
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
def AimusicLyrics(prompt): |
|
|
url = "https://aimusic.one/api/v3/lyrics/generator" |
|
|
headers = { |
|
|
"Content-Type": "application/json", |
|
|
"User-Agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Mobile Safari/537.36", |
|
|
"Referer": "https://aimusic.one/ai-lyrics-generator" |
|
|
} |
|
|
data = { |
|
|
"description": prompt, |
|
|
"style": "Auto", |
|
|
"topic": "Auto", |
|
|
"mood": "Auto", |
|
|
"lan": "auto", |
|
|
"isPublic": True |
|
|
} |
|
|
try: |
|
|
response = requests.post(url, json=data, headers=headers) |
|
|
response.raise_for_status() |
|
|
result = response.json() |
|
|
return result.get("lyrics") |
|
|
except requests.exceptions.RequestException as e: |
|
|
print(f"Error: {e}") |
|
|
return None |
|
|
|
|
|
@app.route("/lirik", methods=["GET"]) |
|
|
def get_lyrics(): |
|
|
prompt = request.args.get("q") |
|
|
if not prompt: |
|
|
return jsonify({"error": "Query parameter 'q' is required"}), 400 |
|
|
|
|
|
lyrics = AimusicLyrics(prompt) |
|
|
if lyrics: |
|
|
return jsonify({"lyrics": lyrics}), 200 |
|
|
else: |
|
|
return jsonify({"error": "Failed to generate lyrics"}), 500 |
|
|
|
|
|
if __name__ == "__main__": |
|
|
app.run(debug=True, host="0.0.0.0", port=8080) |
|
|
|