From e40b893cf1321207f93f572fd2e1ca94277dc22e Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Mon, 15 Jul 2024 11:23:13 +0200 Subject: [PATCH] =?UTF-8?q?Pongo=20bot=C3=B3n=20de=20a=C3=B1adir=20=C3=A1l?= =?UTF-8?q?bum=20en=20lista=20de=20albumes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LyricsPy/K8S/Makefile | 2 +- .../servicios/lyrics/templates/albumes.html | 6 +- NavidromePy/app.py | 72 ++++++++----------- 3 files changed, 36 insertions(+), 44 deletions(-) diff --git a/LyricsPy/K8S/Makefile b/LyricsPy/K8S/Makefile index 062582a..7fc01d2 100644 --- a/LyricsPy/K8S/Makefile +++ b/LyricsPy/K8S/Makefile @@ -1,4 +1,4 @@ -export IMG_VERSION = 6.7 +export IMG_VERSION = 6.8 imagen: cd ../servicios; make diff --git a/LyricsPy/servicios/lyrics/templates/albumes.html b/LyricsPy/servicios/lyrics/templates/albumes.html index 2bb9bc4..150aa56 100644 --- a/LyricsPy/servicios/lyrics/templates/albumes.html +++ b/LyricsPy/servicios/lyrics/templates/albumes.html @@ -10,7 +10,11 @@
-
+
+ +
diff --git a/NavidromePy/app.py b/NavidromePy/app.py index ba8d249..e930d61 100644 --- a/NavidromePy/app.py +++ b/NavidromePy/app.py @@ -1,55 +1,46 @@ -from flask import Flask, request, jsonify, Response -import requests +from flask import Flask, request, jsonify, Response, render_template_string +import libsonic + app = Flask(__name__) # Configuración de la API de Subsonic -SUBSONIC_URL = 'http://navidrome.reymota.es/rest' +SUBSONIC_URL = 'https://navidrome.reymota.es/rest' USERNAME = 'creylopez' PASSWORD = 'Rey-1176' CLIENT_NAME = 'NavidromePy' # Nombre de la aplicación cliente VERSION = '1.16.1' # Versión de la API de Subsonic +client = libsonic.Connection(SUBSONIC_URL, USERNAME, PASSWORD, 443) + def get_song_stream(song_id): - url = f"{SUBSONIC_URL}/stream" - params = { - 'u': USERNAME, - 'p': PASSWORD, - 'v': VERSION, - 'c': CLIENT_NAME, - 'id': song_id, - 'f': 'json' - } - response = requests.get(url, params=params, stream=True) - return response + return client.stream(song_id) def search_song(title): - url = f"{SUBSONIC_URL}/search3" - params = { - 'u': USERNAME, - 'p': PASSWORD, - 'v': VERSION, - 'c': CLIENT_NAME, - 'query': title, -# 'songCount': 1, - 'f': 'json' - } - response = requests.get(url, params=params) - if response.status_code == 200: - result = response.json() - print(result) - songs = result['subsonic-response']['searchResult3']['song'] - if songs: - for cancion in songs: - print("Canción buscada: '",title,"' - encontrada: '", cancion['title'],"'") - if cancion['title'] == title: - return cancion['id'] - + result = client.search(title) + songs = result['song'] + # Filtrar canciones que coincidan exactamente con el título buscado + for song in songs: + if song['title'].lower() == title.lower(): + return song['id'] return None -@app.route('/play', methods=['GET']) +@app.route('/') +def index(): + return render_template_string(''' + + Buscar y reproducir canción +

Buscar y reproducir canción

+ + + + + + ''') + +@app.route('/play', methods=['POST']) def play_song(): - title = request.args.get('title') + title = request.form.get('title') if not title: return jsonify({'error': 'Se requiere el título de la canción'}), 400 @@ -58,10 +49,7 @@ def play_song(): return jsonify({'error': 'Canción no encontrada'}), 404 response = get_song_stream(song_id) - if response.status_code == 200: - return Response(response.iter_content(chunk_size=1024), content_type=response.headers['Content-Type']) - else: - return jsonify({'error': 'Error al reproducir la canción'}), response.status_code + return Response(response, content_type='audio/mpeg') if __name__ == '__main__': - app.run(debug=True) + app.run(debug=True) \ No newline at end of file