-
Notifications
You must be signed in to change notification settings - Fork 183
/
app.py
173 lines (150 loc) · 4.52 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from flask import Flask, request, redirect, jsonify, json
import time
import jiosaavn
import os
from traceback import print_exc
from flask_cors import CORS
app = Flask(__name__)
app.secret_key = os.environ.get("SECRET", 'thankyoutonystark#weloveyou3000')
CORS(app)
@app.route('/')
def home():
return redirect("https://cyberboysumanjay.github.io/JioSaavnAPI/")
@app.route('/song/')
def search():
lyrics = False
songdata = True
query = request.args.get('query')
lyrics_ = request.args.get('lyrics')
songdata_ = request.args.get('songdata')
if lyrics_ and lyrics_.lower() != 'false':
lyrics = True
if songdata_ and songdata_.lower() != 'true':
songdata = False
if query:
return jsonify(jiosaavn.search_for_song(query, lyrics, songdata))
else:
error = {
"status": False,
"error": 'Query is required to search songs!'
}
return jsonify(error)
@app.route('/song/get/')
def get_song():
lyrics = False
id = request.args.get('id')
lyrics_ = request.args.get('lyrics')
if lyrics_ and lyrics_.lower() != 'false':
lyrics = True
if id:
resp = jiosaavn.get_song(id, lyrics)
if not resp:
error = {
"status": False,
"error": 'Invalid Song ID received!'
}
return jsonify(error)
else:
return jsonify(resp)
else:
error = {
"status": False,
"error": 'Song ID is required to get a song!'
}
return jsonify(error)
@app.route('/playlist/')
def playlist():
lyrics = False
query = request.args.get('query')
lyrics_ = request.args.get('lyrics')
if lyrics_ and lyrics_.lower() != 'false':
lyrics = True
if query:
id = jiosaavn.get_playlist_id(query)
songs = jiosaavn.get_playlist(id, lyrics)
return jsonify(songs)
else:
error = {
"status": False,
"error": 'Query is required to search playlists!'
}
return jsonify(error)
@app.route('/album/')
def album():
lyrics = False
query = request.args.get('query')
lyrics_ = request.args.get('lyrics')
if lyrics_ and lyrics_.lower() != 'false':
lyrics = True
if query:
id = jiosaavn.get_album_id(query)
songs = jiosaavn.get_album(id, lyrics)
return jsonify(songs)
else:
error = {
"status": False,
"error": 'Query is required to search albums!'
}
return jsonify(error)
@app.route('/lyrics/')
def lyrics():
query = request.args.get('query')
if query:
try:
if 'http' in query and 'saavn' in query:
id = jiosaavn.get_song_id(query)
lyrics = jiosaavn.get_lyrics(id)
else:
lyrics = jiosaavn.get_lyrics(query)
response = {}
response['status'] = True
response['lyrics'] = lyrics
return jsonify(response)
except Exception as e:
error = {
"status": False,
"error": str(e)
}
return jsonify(error)
else:
error = {
"status": False,
"error": 'Query containing song link or id is required to fetch lyrics!'
}
return jsonify(error)
@app.route('/result/')
def result():
lyrics = False
query = request.args.get('query')
lyrics_ = request.args.get('lyrics')
if lyrics_ and lyrics_.lower() != 'false':
lyrics = True
if 'saavn' not in query:
return jsonify(jiosaavn.search_for_song(query, lyrics, True))
try:
if '/song/' in query:
print("Song")
song_id = jiosaavn.get_song_id(query)
song = jiosaavn.get_song(song_id, lyrics)
return jsonify(song)
elif '/album/' in query:
print("Album")
id = jiosaavn.get_album_id(query)
songs = jiosaavn.get_album(id, lyrics)
return jsonify(songs)
elif '/playlist/' or '/featured/' in query:
print("Playlist")
id = jiosaavn.get_playlist_id(query)
songs = jiosaavn.get_playlist(id, lyrics)
return jsonify(songs)
except Exception as e:
print_exc()
error = {
"status": True,
"error": str(e)
}
return jsonify(error)
return None
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=5100, use_reloader=True, threaded=True)