def __display_votes(): global maxvotes, votes, votelist, votefile, vote, matcher, title, numvotes, filename, display, escapedtitle if os.path.exists(basedir + 'votes') and os.path.getsize(basedir + 'votes') > 0: maxvotes = 0 votes = {} votelist = [] votefile = open(basedir + 'votes') for vote in votefile.readlines(): matcher = re.match('\A(.*),([0-9]*)', vote) if matcher is not None: title = matcher.group(1) numvotes = int(matcher.group(2)) votes[title] = numvotes votelist.append(title) if numvotes > maxvotes: maxvotes = numvotes votefile.close() print "<tr><td width='70%' align='left'><strong>" + _('Voted') + "</strong></td><td></td></tr>" while maxvotes > 0: for filename in votelist: if votes[filename] == maxvotes: display = taginfo.get_tag_light(filename) title = re.sub('\A' + mediadir, '', filename) escapedtitle = urllib.quote(title) print "<tr><td>" print "<a class='file' href='fileinfo.py?file=" + escapedtitle + "' >" + display + "</a>" print "</td>" print "<td>" if common.is_show_admin_controls(): print "<a href='home.py?action=unvote&file=" + \ escapedtitle + "' title='" + _('Unvote') + "'>" print "<img src='themes/" + myconfig['theme'] + "/delrandom.png' alt='Delete'/></a>" print "</td></tr>" maxvotes -= 1 print "<tr><td colspan='2'> </td></tr>"
def print_songs (header, filearray): cssclass = 'file2' print "<table class='statistictable'>" print "<tr><th>Song</th><th>" + header + "</th></tr>" # for every song in mostplayed # print artist/title filematcher = re.compile('\A(.*)\,\ ([A-Z0-9]*)\Z') for line in filearray: matcher = filematcher.match(line) filename = matcher.group(1) reason = matcher.group(2) displayname = taginfo.get_tag_light(filename) filename = filename.replace(mediadir, '', 1) # (does not turn up in oyster-gui) escapedfilename = urllib.quote(filename) # switch colors if cssclass == 'file': cssclass = 'file2' else: cssclass = 'file' print "<tr><td>" if oysterruns: print "<a href='home.py?action=enqueue&file=" + escapedfilename + "' " + \ "title='Enqueue'><img src='themes/" + myconfig['theme'] + "/enqueue" + cssclass + ".png'" +\ "border='0' alt='Enqueue'/></a>" print "<a class='" + cssclass + "' href='fileinfo.py?" + \ "file=/" + escapedfilename + "'>" + displayname + "</a></td>" print "<td class='" + cssclass + "' align='center'>" + reason + "</td></tr>\n" print "</table>"
def print_songs(header, filearray): cssclass = 'file2' print "<table class='statistictable'>" print "<tr><th>Song</th><th>" + header + "</th></tr>" # for every song in mostplayed # print artist/title filematcher = re.compile('\A(.*)\,\ ([A-Z0-9]*)\Z') for line in filearray: matcher = filematcher.match(line) filename = matcher.group(1) reason = matcher.group(2) displayname = taginfo.get_tag_light(filename) filename = filename.replace(mediadir, '', 1) # (does not turn up in oyster-gui) escapedfilename = urllib.quote(filename) # switch colors if cssclass == 'file': cssclass = 'file2' else: cssclass = 'file' print "<tr><td>" if oysterruns: print "<a href='home.py?action=enqueue&file=" + escapedfilename + "' " + \ "title='Enqueue'><img src='themes/" + myconfig['theme'] + "/enqueue" + cssclass + ".png'" +\ "border='0' alt='Enqueue'/></a>" print "<a class='" + cssclass + "' href='fileinfo.py?" + \ "file=/" + escapedfilename + "'>" + displayname + "</a></td>" print "<td class='" + cssclass + "' align='center'>" + reason + "</td></tr>\n" print "</table>"
def whatplayed(): start = datetime.datetime( int(form["year"].value), int(form["month"].value), int(form["day"].value), int(form["hour"].value), int(form["min"].value), ) delta = datetime.timedelta(0, 0, 0, 0, int(form["range"].value)) stop = start + delta start = start - delta rangelines = [] def gettime(line): "Parses the given line and returns a datetime object" return datetime.datetime(int(line[0:4]), int(line[4:6]), int(line[6:8]), int(line[9:11]), int(line[11:13])) def searchtime(begin, end): mid = begin + ((end - begin) / 2) midtime = gettime(loglines[mid]) if end - begin < 2: if start < midtime: return begin else: return begin + 1 if start < midtime: return searchtime(begin, mid) elif start > midtime: return searchtime(mid, end) else: return searchtime(mid, mid) for log in os.listdir("logs/"): # Read entire logfile into memory logfile = open("logs/" + log, "r") loglines = logfile.readlines() logfile.close() if len(loglines) > 0 and stop > gettime(loglines[0]) and start < gettime(loglines[-1]): counter = searchtime(0, len(loglines) - 1) curdate = gettime(loglines[counter]) while curdate < stop: rangelines.append(loglines[counter]) counter += 1 if counter < len(loglines): curdate = gettime(loglines[counter]) else: curdate = stop rangelines.sort() print "<table>" logmatcher = re.compile("\A([0-9]{8}\-[0-9]{6})\ ([^\ ]*)\ (.*)\Z") for line in rangelines: matcher = logmatcher.match(line[:-1]) playdate = matcher.group(1) reason = matcher.group(2) filename = matcher.group(3) if reason == "PLAYLIST" or reason == "VOTED" or reason == "SCORED" or reason == "ENQUEUED": displayname = taginfo.get_tag_light(filename) filename = filename.replace(mediadir, "", 1) escapedfilename = urllib.quote(filename) print "<tr>" print "<td><strong>" + playdate[9:11] + ":" + playdate[11:13] + "</strong></td>" print "<td><a class='file' href='fileinfo.py?file=" + escapedfilename + "'>" + displayname + "</a><br></td>" print "</tr>" print "</table>" sys.exit()
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():
import anydbm import os.path import taginfo cgitb.enable() import common common.hide_page_in_party_mode() common.navigation_header("Rebuild Tags") myconfig = config.get_config() mediadir = myconfig['mediadir'][:-1] form = cgi.FieldStorage() playlist = config.get_playlist() cache = anydbm.open(myconfig['savedir'] + 'tagcache-python', 'c') allfiles = cache.keys() cache.close() cache = anydbm.open(myconfig['savedir'] + 'tagcache-python', 'n') cache.close() print "<h1>Regeneration taginfos...</h1>" for filename in allfiles: if os.path.exists(filename): print taginfo.get_tag_light(filename) + "<br>" print "<h1>Done!</h1>" print "</body></html>"
def whatplayed(): start = datetime.datetime(int(form['year'].value), int(form['month'].value), int(form['day'].value), \ int(form['hour'].value), int(form['min'].value)) delta = datetime.timedelta(0, 0, 0, 0, int(form['range'].value)) stop = start + delta start = start - delta rangelines = [] def gettime(line): "Parses the given line and returns a datetime object" return datetime.datetime(int(line[0:4]), int(line[4:6]), int(line[6:8]), \ int(line[9:11]), int(line[11:13])) def searchtime(begin, end): mid = begin + ((end - begin) / 2) midtime = gettime(loglines[mid]) if end - begin < 2: if start < midtime: return begin else: return begin + 1 if start < midtime: return searchtime(begin, mid) elif start > midtime: return searchtime(mid, end) else: return searchtime(mid, mid) for log in os.listdir('logs/'): # Read entire logfile into memory logfile = open('logs/' + log, 'r') loglines = logfile.readlines() logfile.close() if len(loglines) > 0 and \ stop > gettime(loglines[0]) and start < gettime(loglines[-1]): counter = searchtime(0, len(loglines)-1) curdate = gettime(loglines[counter]) while curdate < stop: rangelines.append(loglines[counter]) counter += 1 if counter < len(loglines): curdate = gettime(loglines[counter]) else: curdate = stop rangelines.sort() print "<table>" logmatcher = re.compile('\A([0-9]{8}\-[0-9]{6})\ ([^\ ]*)\ (.*)\Z') for line in rangelines: matcher = logmatcher.match(line[:-1]) playdate = matcher.group(1) reason = matcher.group(2) filename = matcher.group(3) if reason == 'PLAYLIST' or reason == 'VOTED' or reason == 'SCORED' or reason == 'ENQUEUED': displayname = taginfo.get_tag_light(filename) filename = filename.replace(mediadir, '', 1) escapedfilename = urllib.quote(filename) print "<tr>" print "<td><strong>" + playdate[9:11] + ":" + playdate[11:13] + "</strong></td>" print "<td><a class='file' href='fileinfo.py?file=" + escapedfilename + "'>" + displayname + "</a><br></td>" print "</tr>" print "</table>" sys.exit()