-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
55 lines (40 loc) · 1.33 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from flask import Flask, request, jsonify
from flask_cors import CORS
from actual_hitokara import lyrics
from actual_hitokara.recomendations import Recomendations
from actual_hitokara import search
app = Flask(__name__)
CORS(app)
@app.route("/")
def index():
return "Hello, World!"
@app.route("/lyrics", methods=["POST"])
def get_lyrics():
data = request.get_json()
print(data)
artist_name = data["artist_name"]
song_name = data["song_name"]
if data["lang"] == "en":
return jsonify(lyrics.en_fetch_lyrics(artist_name, song_name))
else:
return jsonify(lyrics.hn_fetch_lyrics(artist_name, song_name))
@app.route("/recomendations/<genre>", methods=["GET"])
def get_recomendations(genre):
recomendations = Recomendations()
if genre == "pop":
return jsonify(recomendations.pop_hits())
elif genre == "hip_hop":
return jsonify(recomendations.hip_hop_hits())
elif genre == "indie":
return jsonify(recomendations.indie_hits())
elif genre == "rock":
return jsonify(recomendations.rock_hits())
else:
return jsonify({"Error": "Invalid genre"})
@app.route("/search", methods=["GET"])
def search_songs():
data = request.get_json()
query = data["query"]
return jsonify(search.search_song(query))
if __name__ == "__main__":
app.run(debug=True)