Esempio n. 1
0
 def DisplayTopTracks(self):
     print "---TOP TRACKS---"
     top_tracks = Track.gql("ORDER BY times_played DESC LIMIT 10")
     #print "Total tracks:" + str(len(histogram.values()))
     #sorted(histogram.iteritems, key=operator.itemgetter(1), reverse=True)
     for item in top_tracks.run(): #heapq.nlargest(20,histogram.iteritems(),operator.itemgetter(1)):
         print "[%d] %s - %s" % (item.times_played, string.ljust(item.artist,40), string.ljust(item.title,40))
Esempio n. 2
0
    def ParseTrack(self, line):
        t = None
        #print "matching line: %s" % (line)
        match = songmatcher.search(line)
    #matchlist = songmatcher.findall(result.content)
    #for item in matchlist:
        if match is not None:
            item = [ x for x in match.groups() if x != None ]
            #print >> sys.stderr, "%s" % (str(match.groups()))
            #if len(item[0]) == 0:
            #    item = item[2:]
            title = string.capwords(item[0].strip('\t /'))
            artist = string.capwords(item[1].strip('\t /'))
            title = title.partition("<")[0]
            artist = artist.partition("<")[0]
            if len(artist) == 0:
                tmp = title.split("/")
                if len(tmp) < 2: 
                    logging.error("unable to parse artist from title: %s" % (title))
                    return None
                title = tmp[0].strip(' ')
                artist = tmp[1].strip(' ')
            q = Track.gql("WHERE title=:1 AND artist=:2", title, artist)
            t = q.get()
            if t is None:
                t = Track(title=title, artist=artist)
                self._total_parsed = self._total_parsed+1
            #print "[%d] %s - %s" % (self._total_parsed, artist, title)
                logging.info("[%d] %s - %s" % (self._total_parsed, t.artist, t.title))

            #histogram[(artist, title)] = histogram.get((artist, title),0)+1
        else:
            #print "--- skip line: " + line
            pass
        return t
Esempio n. 3
0
 def DisplayAllTracks(self):
     print "---TOTAL TRACKS: %d---" % (self._total_parsed)
     all_tracks = Track.gql("ORDER BY date_added DESC")
     for item in all_tracks.run():
         print "[%d] %s - %s" % (item.times_played, string.ljust(item.artist,40), string.ljust(item.title,40))