-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
60 lines (43 loc) · 1.24 KB
/
player.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
import pygame
import time
import sqlite3
import createSearchTree
currentSongPath = ""
def manager():
while(True):
getTopVotedSong()
if currentSongPath != "":
playSong()
else :
print "top 10 is empty! waiting for incoming votes"
time.sleep(5)
def playSong():
global currentSongPath
print "\nplaying song: " +str(currentSongPath)
pygame.mixer.init()
pygame.mixer.music.load(currentSongPath)
pygame.mixer.music.play()
#pygame.mixer.music.queue(nextSongPath)
while pygame.mixer.music.get_busy():
time.sleep(1)
currentSongPath = ""
print "song finshed"
# lookup the song with most votes in database
def getTopVotedSong():
global currentSongPath
# open sqlite db connection
connection = sqlite3.connect("mucke.db")
cursor = connection.cursor()
# get current top songs
cursor.execute("""SELECT path FROM musiclib WHERE votes > '0' ORDER BY votes DESC;""")
topvotesTuple = cursor.fetchall()
# set number of votes back to 0
if len(topvotesTuple) != 0:
t = (topvotesTuple[0])
cursor.execute("""UPDATE musiclib SET votes= 0 WHERE path==?;""", t )
connection.commit()
currentSongPath = str(topvotesTuple[0][0])
print currentSongPath
connection.close()
# update html top10 list
createSearchTree.buildHTML()