Beispiel #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))
Beispiel #2
0
    def getSongs(self):
        if self.length <= 0 or len(self.songs) <= 0:
            self.getLength()
        
        if len(self.songs) > 0:
            return

        iterations = math.ceil(self.length / 100)

        url = f"playlists/{self.playlistID}/tracks"

        tmp = []

        for i in range(iterations):
            selector = {
                "fields": "items(track(name%2Cartists%2Calbum%2Cid))",
                "offset": i * 100,
                "limit": 100
            }
            if self.spotify.query(url, payload=selector):
                for item in self.spotify.data["items"]:
                    tmp.append(Track(item["track"]))

        self.songs = tmp
        return self.songs
Beispiel #3
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
Beispiel #4
0
 def recursive_walk(self, path):
     for directory in os.listdir(path):
         if os.path.isdir(path + '\\' + directory):
             self.populate_db(path + '\\' + directory)
     for file in os.listdir(path):
         if not os.path.isdir(path + '\\' + file) and file.endswith(self._extentions):
             duration, fingerprint = acoustid.fingerprint_file(path + '\\' + file)
             temp_data_dict = {
                 'fingerprint': fingerprint,
                 'path': path + '\\' + file,
                 'file_size': os.path.getsize(path + '\\' + file)
             }
             with db.atomic():
                 try:
                     Track.create(**temp_data_dict)
                 except IntegrityError:
                     duplicate_track = Track.select().where(Track.fingerprint==fingerprint).get()
                     if duplicate_track.file_size < os.path.getsize(path+'\\'+file):
                         duplicate_track.delete_instance()
                     else:
                         pass
Beispiel #5
0
from Playlist import PlaylistAPI
from Util import better_mean, list2json, json2obj
import statistics
import json
import time
from Models import Track
from Genius import Genius
beg = time.time()

token = "BQBPEX_Zo3Eu1sGfSOe23PGUxt9bGkbOLxH95mrjcyc3Cj8fwqEE4EuGVi3G8Neo7mOEXCLIeNCOQXm0MPAIvYm6YU7UzSJqiF6XYzlgSGbkjhOl1NtkfmqWA7cum2CnYOeth-P3_9RbBOORhQxucYIeI7BT-Z3jsDY5qiqApRyICifRzuTYg7hSZqIoR2ssYUxKJuITYmBUzJCB2S4MyLgQbh4swmaNS6MO69_tjbgFRWUTZOIVGSp4c858pJGG5cmuHeFeH-_dqV85Zkht"

playlist = PlaylistAPI(playlistID="37i9dQZF1DZ06evO2dYtbO", token=token)

try:
    with open("playlist_dump_features.json", "r") as f:
        playlist.songs = [Track(t) for t in json2obj(f.read())]
except:
    print("File not loaded")
    pass

print("Post LOAD:", time.time() - beg)

playlist.getSongs()

print("Post getSongs():", time.time() - beg)
'''spot = Spotify(token)
if not spot.query("me/playlists"):
    print(spot.status)
    exit(1)

r = spot.data
Beispiel #6
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))
Beispiel #7
0
 def populate_db(self, path):
     if not Track.table_exists():
         db.create_tables([Track])
     db.connect()
     self.recursive_walk(path)