def scrobble_cueue(self): """Tries to scrobble all tracks in the queue to last.fm. When tracks fail to scrobble, they will be re-added tot he queue.""" if not os.path.isfile(self.queuefile): return #get all scrobbles from the cache file, # then purge it and parse it. When tracks # can not be scrobbled, they will be re-added # to the file later f = open(self.queuefile, 'r') lines = f.readlines() f.close() f = open(self.queuefile, 'w') f.write("") f.close() timestamp = None for line in lines: line = line.rstrip() if not timestamp: #Try some sort of error recovery, when timestamp is expected, # but a nontimestamp has been read, break and the current line is ignored try: int(line) timestamp = line except: pass else: track = Track.deserialize(simplejson.loads(line)) self.scrobble(track, timestamp) timestamp = None
def scan(self): print "Start scanning SmallMediumFileCollection "+self.collectionroot found_tracks = [] extentions = ["mp3", "flac"] for (path, dir, files) in os.walk(self.collectionroot): for mfile in files: if mfile.split(".")[-1] in extentions: filename = path+"/"+mfile try: t = Track.loadFromFile(filename) found_tracks.append(t) except: print "Could not open file for ID3 %s" % filename self._tracks = found_tracks self.writetofile() self.sortTracks() return
def queue_track(self, filename): track = Track.loadFromFile(filename) self.queue.addToQueue(track)
def set_track(self, filename): track = Track.loadFromFile(filename) self.player.changeTrack(track)
def load_tracks_as_json(self, jsonstring): for trackdata in simplejson.loads(jsonstring): t = Track(None) t.load(trackdata) self._tracks.append(t) self.sortTracks()