Skip to content

Commit 0454c5a

Browse files
committed
implemented gui
1 parent 9ee0290 commit 0454c5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+9511
-0
lines changed

GUI/.spotify_data.secret

122 Bytes
Binary file not shown.

GUI/backend.py

Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
from flask import Flask, render_template, request
2+
from random import shuffle
3+
import json
4+
import spotify
5+
import lastfm
6+
import genius
7+
8+
import subprocess, os, sys
9+
from os.path import expanduser
10+
11+
12+
app = Flask(__name__)
13+
user = spotify.Spotify.User()
14+
lastfm = lastfm.LastFM()
15+
16+
17+
@app.route("/home", methods=["GET"])
18+
def index():
19+
20+
sp_user_t_a = user.getTopArtists()
21+
sp_user_s_alb = user.getNewReleases()
22+
sp_user_t_t = user.getTopTracks()
23+
sp_user_s_art = user.getUserArtistsPrev()
24+
sp_user_s_pls = user.getUserPlaylistPrev()
25+
sp_user_f_pls = user.getUserFeaturedPlaylistPrev()
26+
27+
shuffle(sp_user_t_a)
28+
shuffle(sp_user_s_alb)
29+
shuffle(sp_user_s_art)
30+
shuffle(sp_user_s_pls)
31+
shuffle(sp_user_f_pls)
32+
33+
return render_template(
34+
'home.html',
35+
user_top_artists=sp_user_t_a,
36+
user_saved_albums=sp_user_s_alb,
37+
user_top_tracks=sp_user_t_t,
38+
user_saved_artists=sp_user_s_art,
39+
user_saved_playlists=sp_user_s_pls,
40+
user_featured_playlists=sp_user_f_pls
41+
)
42+
43+
@app.route("/artist/<uri>", methods=["GET"])
44+
def artist(uri):
45+
46+
sp_artist_info = user.getArtistsInfo(uri)
47+
sp_artist_t_t = user.getArtistsTopTracks(uri)
48+
sp_artist_alb = user.getArtistsAlbums(uri)
49+
sp_artist_r_a = user.getArtistsRelatedArtists(uri)
50+
sp_artist_a_o = user.getArtistsAppearsOn(uri)
51+
sp_artist_alb_full = user.getArtistsAlbumsSortedByDate(uri)
52+
53+
lf_artist_info = lastfm.getArtistsInfo(sp_artist_info['name'])
54+
55+
print(len(sp_artist_alb))
56+
print(len(sp_artist_alb_full))
57+
58+
#creating tags
59+
name = str(sp_artist_info['name']).replace(' ','')
60+
61+
smd_artists_tags = [name]
62+
63+
return render_template(
64+
'artist.html',
65+
artists_info=sp_artist_info,
66+
artists_top_tracks=sp_artist_t_t,
67+
artists_albums=sp_artist_alb,
68+
artists_related=sp_artist_r_a,
69+
artists_appears_on=sp_artist_a_o,
70+
artists_albums_full = sp_artist_alb_full,
71+
artists_info_lf = lf_artist_info,
72+
artists_tags = smd_artists_tags
73+
)
74+
75+
@app.route("/artists", methods=["GET"])
76+
def artists():
77+
78+
sp_user_s_art = user.getUserArtistsPrev()
79+
80+
return render_template(
81+
'artists.html',
82+
user_saved_artists=sp_user_s_art
83+
)
84+
85+
@app.route("/albums", methods=["GET"])
86+
def albums():
87+
88+
sp_user_alb = user.getUserSavedAlbumPrev()
89+
90+
return render_template(
91+
'albums.html',
92+
user_saved_albums=sp_user_alb
93+
)
94+
95+
@app.route("/playlists", methods=["GET"])
96+
def playlists():
97+
98+
sp_user_s_art = user.getUserPlaylistPrev()
99+
100+
return render_template(
101+
'playlists.html',
102+
user_saved_albums=sp_user_s_art
103+
)
104+
105+
@app.route("/category", methods=["GET"])
106+
def category():
107+
108+
uri = request.args.get('uri', None) # use default value repalce 'None'
109+
name = request.args.get('name', None)
110+
image = request.args.get('image', None)
111+
112+
113+
sp_user_s_art = user.getCategoryPlaylists(uri)
114+
115+
return render_template(
116+
'category.html',
117+
user_saved_albums=sp_user_s_art,
118+
category_image=image,
119+
category_name=name
120+
)
121+
122+
@app.route("/categories", methods=["GET"])
123+
def categories():
124+
125+
sp_user_s_art = user.getCategories()
126+
127+
return render_template(
128+
'categories.html',
129+
user_saved_albums=sp_user_s_art
130+
)
131+
132+
@app.route("/saved", methods=["GET"])
133+
def saved():
134+
135+
sp_user_s_art = user.getUserTracks()
136+
137+
return render_template(
138+
'saved.html',
139+
artists_top_tracks=sp_user_s_art
140+
)
141+
142+
@app.route("/playlists/<uri>:<us>", methods=["GET"])
143+
def playlist(uri,us):
144+
145+
playlist = user.getPlaylist(id=us, uri=uri)
146+
147+
return render_template(
148+
'playlist.html',
149+
info=playlist,
150+
artists_top_tracks=playlist['tracks']
151+
)
152+
153+
@app.route("/global_top", methods=["GET"])
154+
def global_top():
155+
156+
playlist = user.getPlaylist(id='spotify', uri='37i9dQZEVXbMDoHDwVN2tF')
157+
158+
return render_template(
159+
'playlist.html',
160+
info=playlist,
161+
artists_top_tracks=playlist['tracks']
162+
)
163+
164+
@app.route("/last", methods=["GET"])
165+
def last():
166+
167+
last = user.getRecentlyPlayed()
168+
169+
return render_template(
170+
'last_played.html',
171+
artists_top_tracks=last
172+
)
173+
174+
@app.route("/search/<q>", methods=["GET"])
175+
def search(q):
176+
177+
query = ' '.join(str(q).split('+'))
178+
179+
print(query)
180+
181+
results = user.search(query)
182+
183+
tracks_res = results['tracks']
184+
albums_res = results['albums']
185+
artists_res = results['artists']
186+
playlists_res = results['playlists']
187+
188+
189+
return render_template(
190+
'search.html',
191+
q=query,
192+
tracks=tracks_res,
193+
albums=albums_res,
194+
artists=artists_res,
195+
playlists=playlists_res
196+
)
197+
198+
@app.route("/song/<uri>", methods=['GET'])
199+
def song(uri):
200+
201+
sp_song_data = user.getSongInfo(uri)
202+
sp_artist_alb = user.getArtistsAlbums(sp_song_data['art_id'])
203+
sp_artist_r_a = user.getArtistsRelatedArtists(sp_song_data['art_id'])
204+
sp_artist_alb_full = user.getAlbumInfo(sp_song_data['alb_id'])
205+
206+
gn_song_lyrics = str(genius.getLyrics(
207+
artist=sp_song_data['art_name'],
208+
song=sp_song_data['trc_name']
209+
)).split('\n')
210+
211+
212+
return render_template(
213+
'song.html',
214+
info = sp_song_data,
215+
artists_albums=sp_artist_alb,
216+
artists_related=sp_artist_r_a,
217+
artists_albums_full = sp_artist_alb_full,
218+
lyrics=gn_song_lyrics
219+
)
220+
221+
@app.route("/album/<uri>", methods=['GET'])
222+
def album(uri):
223+
224+
sp_album_data = user.getAlbumInfo(uri)[0]
225+
print(sp_album_data['art_id'])
226+
sp_artist_alb = user.getArtistsAlbums(sp_album_data['art_id'])
227+
sp_artist_r_a = user.getArtistsRelatedArtists(sp_album_data['art_id'])
228+
229+
230+
return render_template(
231+
'album.html',
232+
info = sp_album_data,
233+
artists_albums=sp_artist_alb,
234+
artists_related=sp_artist_r_a
235+
)
236+
@app.route("/new_releases", methods=['GET'])
237+
def new_releases():
238+
239+
rel = user.getNewReleases()
240+
241+
return render_template(
242+
'new_releases.html',
243+
new=rel
244+
)
245+
246+
@app.route("/for_you", methods=['GET'])
247+
def for_you():
248+
249+
rel = user.getNewReleases()
250+
sp_user_f_pls = user.getUserFeaturedPlaylistPrev()
251+
recom = user.getUserRecommendationArtists()
252+
recom_t_a = user.getUserRecommendationTopArtists()
253+
recom_t_t = user.getUserRecommendationTopTracks()
254+
recom_t_l = user.getUserRecommendationSavedTracks()
255+
256+
return render_template(
257+
'for_you.html',
258+
new=rel,
259+
rec=recom,
260+
rec_t_a=recom_t_a,
261+
rec_t_t=recom_t_t,
262+
rec_t_l=recom_t_l,
263+
user_featured_playlists=sp_user_f_pls
264+
)
265+
266+
@app.route("/downloadSingleSong/<uri>", methods=['GET','POST'])
267+
def downloadSingleSong(uri):
268+
269+
if request.method == 'POST':
270+
271+
272+
music = expanduser("~") + '/Music'
273+
274+
subprocess.Popen(["python3", f"{os.getcwd()}/main.py", '-ss', f'https://open.spotify.com/track/{uri}','-p', music])
275+
276+
277+
return json.dumps(
278+
{
279+
'status': True
280+
}
281+
)
282+
283+
@app.route("/downloadAlbum/<uri>", methods=['GET','POST'])
284+
def downloadAlbum(uri):
285+
286+
if request.method == 'POST':
287+
288+
music = expanduser("~") + '/Music'
289+
290+
subprocess.Popen(["python3", f"{os.getcwd()}/main.py", '-sa', f'https://open.spotify.com/album/{uri}', '-p', music])
291+
292+
return json.dumps(
293+
{
294+
'status': True
295+
}
296+
)
297+
298+
@app.route('/login', methods=['GET','POST'])
299+
def login():
300+
301+
return render_template(
302+
'login.html'
303+
)
304+
305+
@app.route('/shutdown', methods=['GET','POST'])
306+
def shutdown():
307+
308+
func = request.environ.get('werkzeug.server.shutdown')
309+
if func is None:
310+
raise RuntimeError('Not running with the Werkzeug Server')
311+
func()
312+
313+
314+
if __name__ == "__main__":
315+
app.run(debug=True, host='0.0.0.0', port=8050)

GUI/genius.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import lyricsgenius
2+
import pickle
3+
4+
5+
def getLyrics(artist, song):
6+
7+
def function():
8+
9+
try:
10+
11+
with open('.genius', 'rb') as f:
12+
data = pickle.load(f)
13+
14+
return data['token']
15+
16+
except:
17+
18+
return None
19+
20+
try:
21+
22+
genius = lyricsgenius.Genius(function())
23+
genius.verbose, genius.remove_section_headers = False, True
24+
song = genius.search_song(song, artist)
25+
26+
return song.lyrics
27+
28+
except:return None
29+
30+
if __name__ == '__main__':
31+
print(getLyrics('Cage The Elephant', 'Ready To Let Go'))

GUI/icon.png

271 KB
Loading

0 commit comments

Comments
 (0)