forked from speutel/oyster
/
score.py
executable file
·135 lines (104 loc) · 4.16 KB
/
score.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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# oyster - a python-based jukebox and web-frontend
#
# Copyright (C) 2004 Benjamin Hanzelmann <ben@nabcos.de>,
# Stephan Windmüller <windy@white-hawk.de>,
# Stefan Naujokat <git@ethric.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import cgi
import config
import taginfo
import fifocontrol
import cgitb
import urllib
import os.path
cgitb.enable()
myconfig = config.get_config()
basedir = myconfig['basedir']
savedir = myconfig['savedir']
mediadir = myconfig['mediadir'][:-1]
form = cgi.FieldStorage()
playlist = config.get_playlist()
# Is oyster currently running?
if os.path.exists(myconfig['basedir']):
oysterruns = 1
else:
oysterruns = 0
if form.has_key('action'):
fifocontrol.do_action(form['action'].value, form['file'].value)
import common
common.navigation_header("Scoring")
score = {}
maxscore = 1
if os.path.exists(myconfig['savedir'] + "scores/" + playlist):
scorefile = open (myconfig['savedir'] + "scores/" + playlist)
scorefile.readline() # skip initial number
for line in scorefile.readlines():
line = line[:-1]
if score.has_key(line):
score[line] = score[line] + 1
if maxscore < score[line]:
maxscore = score[line]
else:
score[line] = 1
scorefile.close()
# Get Tags of all files
display = {}
for key in score.keys():
display[key] = taginfo.get_tag_light(key)
# Print all files
print "<table id='scoretable'>"
print "<tr><th>Song</th><th width='75'>Score</th></tr>"
cssclass = 'file2'
while maxscore > 0:
printed = 0
files = []
for key in score.keys():
if score[key] == maxscore:
files.append(key)
def filesort(a, b):
return cmp(display[a], display[b])
files.sort(filesort)
for curfile in files:
printed = 1
escapedfile = curfile.replace(mediadir, '', 1)
escapedfile = urllib.quote(escapedfile)
# cssclass changes to give each other file
# another color
if cssclass == 'file':
cssclass = 'file2'
else:
cssclass = 'file'
if oysterruns:
print "<tr><td><a href='home.py?action=enqueue&file=" + escapedfile + "'" + \
"title='Enqueue'><img src='themes/" + myconfig['theme'] + "/enqueue" + cssclass + ".png'" + \
"alt='Enqueue'/></a> <a class='" + cssclass + "' href='fileinfo.py?file=" + \
escapedfile + "'>" + display[curfile] + "</a></td>"
print "<td align='center'><a class= '" + cssclass + "' href='score.py?action=scoredown&file=" + escapedfile + "' " + \
"title='Score down'><img src='themes/" + myconfig['theme'] + "/scoredown" + cssclass + ".png' " + \
"alt='-'/></a> <span class='" + cssclass + "'><strong>" + str(score[curfile]) + "</strong></span>"
print " <a class='" + cssclass + "' href='score.py?action=scoreup&file=" + escapedfile + "' " + \
"title='Score up'><img src='themes/" + myconfig['theme'] + "/scoreup" + cssclass + ".png' alt='+'/></a></td></tr>"
else:
print "<tr><td><a class='" + cssclass + "' href='fileinfo.py?file=" + \
escapedfile + "'>" + display[curfile] + "</a></td>"
print "<td align='center'><span class='" + cssclass + "'><strong>" + str(score[curfile]) + "</strong></span></td></tr>"
maxscore = maxscore - 1
if printed:
print "<tr><td colspan='2'> </td></tr>"
print "</table>"
print "</body></html>"