-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsongManager.py
More file actions
166 lines (114 loc) · 5.16 KB
/
Copy pathsongManager.py
File metadata and controls
166 lines (114 loc) · 5.16 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
import spotifyAPI
import imageManager
import reccomendationEngine
import PySimpleGUI as sg
import webbrowser
class SongManager:
def __init__(self) -> None:
pass
global songDict
global songTable
global songHeaders
songDict = { }
songHeaders = ["ID", "Name", "Artist", "Genre"]
songTable = [[]]
# add table to data
def open_song_like_window(a_id, a_name, cur, conn):
#Get the url of the song's spotify link and album cover
songUrl = spotifyAPI.spotify.get_Song(a_name)
imageUrl = spotifyAPI.spotify.get_image(a_name)
img_box = imageManager.ImageManager.create_image(imageUrl, False)
layout = [
[img_box],
[sg.Button("Play Song", key="Url")],
[sg.Button('Like'), sg.Button('Dislike')]]
window = sg.Window(str(a_id), layout, modal=True)
choice = None
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED:
break
elif event == "Url":
webbrowser.open(songUrl)
if event == "Like":
reccomendationEngine.ReccomendationEngine.update_likes(cur, conn, a_id, False)
if event == "Dislike":
reccomendationEngine.ReccomendationEngine.update_dislikes(cur, conn, a_id, True)
window.close()
def open_song_table(cur, conn):
# Create table of songs
cur.execute('SELECT a_id from "Song" ORDER BY a_id')
counter = 0
for a in cur:
song = []
songTable.append(song)
songTable[counter].append(a)
# Create a mapping of the row number and song ID: Allows us to know which song the user selected when interacting with table element
# Counter will serve as the row number in our table, from which we can find the audio ID
songDict[counter] = a[0]
counter = counter + 1
cur.execute('SELECT a_name from "Song" ORDER BY a_id')
counter = 0
for a in cur:
songTable[counter].append(a)
#b = 'SELECT cr.c_name FROM "Creator" cr, "CreatedBy" cb, "Song" s WHERE cb.c_id = cr.c_id AND s.a_id= cb.a_id AND s.a_id='
#b = b + str(counter)
#cur1.execute(b)
#for b in cur1:
# songTable[counter].append(b)
counter = counter + 1
cur.execute('SELECT cr.c_name FROM "Creator" cr, "CreatedBy" cb, "Song" s WHERE cb.c_id = cr.c_id AND s.a_id= cb.a_id ORDER BY s.a_id')
counter = 0
for a in cur:
songTable[counter].append(a)
counter = counter + 1
cur.execute('SELECT s_genre from "Song" ORDER BY a_id')
counter = 0
for a in cur:
songTable[counter].append(a)
counter = counter + 1
data = songTable
headings = songHeaders
# ------ Window Layout ------
layout = [
#[sg.Text("Filter By Genre"), sg.Text(" Filter by Artist")],
#[sg.Listbox(values = genres, size = (25,6)),
#sg.Listbox(values = artists, size = (25,6))],
[sg.Table(values=data[0:][:], headings=headings, max_col_width=25,
auto_size_columns=True,
display_row_numbers=False,
justification='right',
num_rows=len(songTable)/2,
alternating_row_color='lightyellow',
key='-TABLE-',
selected_row_colors='red on yellow',
enable_events=True,
expand_x=True,
expand_y=True,
enable_click_events=True)],
#[sg.Button('Read'), sg.Button('Double'), sg.Button('Change Colors')],
[sg.Text('Cell clicked:'), sg.T(k='-CLICKED-')],
]
# ------ Create Window ------
window = sg.Window('Song List', layout,
ttk_theme='clam',
resizable=True)
# ------ Event Loop ------
while True:
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED:
break
if isinstance(event, tuple):
# TABLE CLICKED Event has value in format ('-TABLE=', '+CLICKED+', (row,col))
if event[0] == '-TABLE-':
row_num_clicked = event[2][0]
window['-CLICKED-'].update(f'{event[2][0]},{event[2][1]}')
audio_id = songDict.get(event[2][0])
update_string = 'SELECT a_name FROM "Song" WHERE a_id='
update_string = update_string + str(audio_id)
cur.execute(update_string)
name_tuple = cur.fetchone()
audio_name = name_tuple[0]
SongManager.open_song_like_window(audio_id, audio_name, cur, conn)
window.close()