-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
177 lines (125 loc) · 4.09 KB
/
app.py
File metadata and controls
177 lines (125 loc) · 4.09 KB
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
174
175
176
177
#!env/bin/python3
import json
import forms
import spotipy_utils
from flask import Flask, flash, redirect, render_template, request, session
from track_queue import *
from spotifyClient import *
app = Flask(__name__)
app.secret_key = 'ghghghtuy567iuyuyhnuybgt87frsw3'
global_results = []
home_tracks = []
spotify_playlist_id = credentials.spotify['playlist_id']
playlist_id = credentials.spotify['playlist_id']
song_queue = Track_Queue(playlist_id)
home_tracks = read_playlist(playlist_id)
newTime = play_track(song_queue.queue[0].getId(), song_queue)
currently_playing = None
@app.route('/')
def red_to_index():
return redirect('/index')
@app.route('/index', methods=['GET', 'POST'])
def home():
global home_tracks
global song_queue
global currently_playing
global newTime
if newTime<= time.time():
newTime = play_track(song_queue.get_most_wanted().getId(), song_queue)
# remove_current(playlist_id)
if not session:
return redirect("/login")
if request.method == 'POST':
like = request.form.get('like')
dislike = request.form.get('dislike')
add_track = request.form.get('search')
if add_track:
return redirect('/search')
if like and like != song_queue.queue[0].getId():
#6Bjtr3tPdto5nyuLYf61sN
# todo call like method for the track_id (like)
# for x in song_queue:
# print(x.get_votes)
(i,track) = song_queue.pop(like)
track.up_vote()
song_queue.push(track, i)
print("like")
print(like)
# home_tracks = read_playlist(playlist_id)
# song_queue.export_to_spotify()
print(dislike)
print(song_queue.queue[0].getId())
if dislike and dislike != song_queue.queue[0].getId():
# todo call the dislike method for the track_id (dislike)
(i,track) = song_queue.pop(dislike)
track.down_vote()
song_queue.push(track, i)
print("dislike")
print(dislike)
# home_tracks = read_playlist(playlist_id)
# song_queue.export_to_spotify()
return redirect('/')
new_playing = get_current()
if new_playing != currently_playing and len(song_queue.queue)>0 and currently_playing != None:
song_queue.pop(currently_playing)
remove_from_playlist(currently_playing, playlist_id)
currently_playing = new_playing
home_tracks = read_playlist(playlist_id)
for track in song_queue.queue:
print(track.track_name + " " + str(track.get_votes()))
return render_template("index.html", name=session['name'], tracks=home_tracks)
# Prompts user for a name
@app.route('/login', methods=['GET', 'POST'])
def login():
if session and session['name']:
return redirect('/index')
name_form = forms.NameForm(request.form)
if request.method == "POST":
if name_form.data['name'] != "":
session['name'] = name_form.data['name']
return redirect("/")
else:
return render_template("login.html", form=name_form, error="Name cannot be empty!")
return render_template('login.html', form=name_form)
@app.route('/search', methods=['GET', 'POST'])
def search():
if not session['name']:
return redirect("/login")
search = forms.MusicSearchForm(request.form)
if request.method == 'POST':
return search_results(search.data['search'])
return render_template('search.html', form=search)
@app.route('/results', methods=['GET', 'POST'])
def results():
global home_tracks
global song_queue
if request.method == 'POST':
# print(request.form.get('add'))
track_id = request.form.get('add')
if track_id:
spotipy_utils.add_to_playlist(track_id, spotify_playlist_id)
home_tracks = read_playlist(playlist_id)
i = 0
for track in home_tracks:
if track.track_id == track_id:
song_queue.push(track, i)
print(type(track))
print('+++++++++++++++++++++++++++++++++++++++++++++')
i=i+1
return redirect('/index')
return render_template('results.html', results=global_results)
@app.route('/results')
def search_results(search_string):
global global_results
results = []
if search_string == '':
return redirect('/search')
results = search_track(search_string)
global_results = results
if not results:
return render_template('results.html')
else:
# display results
return redirect('results')
def getTracks():
return home_tracks