def add_track_results(self): print "Tracks:" tracklist=self.results.tracks() print " ", str(Link.from_track(tracklist[0], 0))[14:], tracklist[0].name() f.write(str(Link.from_track(tracklist[0], 0))[14:]+',') trackList.append(tracklist[0]) print len(trackList)
def _to_mopidy_track(self, spotify_track): return Track( uri=str(Link.from_track(spotify_track, 0)), title=spotify_track.name().decode(ENCODING), artists=[self._to_mopidy_artist(a) for a in spotify_track.artists()], album=self._to_mopidy_album(spotify_track.album()), track_no=spotify_track.index(), date=dt.date(spotify_track.album().year(), 1, 1), length=spotify_track.duration(), id=self._to_mopidy_id(str(Link.from_track(spotify_track, 0))), )
def action_search(self, line): if not line: if self.results is False: print "No search is in progress" return False elif self.results is None: print "Searching is in progress" else: print "Artists:" for a in self.results.artists(): print " ", Link.from_artist(a), a.name() print "Albums:" for a in self.results.albums(): print " ", Link.from_album(a), a.name() print "Tracks:" for a in self.results.tracks(): print " ", Link.from_track(a, 0), a.name() print self.results.total_tracks() - len( self.results.tracks()), "Tracks not shown" self.results = False else: self.results = None def _(results, userdata): print "\nSearch results received" self.results = results self.search(line, _)
def do_search(self, line): if not line: if self.results is False: print "No search is in progress" elif self.results is None: print "Searching is in progress" else: print "Artists:" for a in self.results.artists(): print " ", Link.from_artist(a), a.name() print "Albums:" for a in self.results.albums(): print " ", Link.from_album(a), a.name() print "Tracks:" for a in self.results.tracks(): print " ", Link.from_track(a, 0), a.name() print "%d tracks not shown" % (self.results.total_tracks() - len(self.results.tracks())) else: line = line.decode('utf-8') self.results = None def search_finished(results, userdata): print "\nSearch results received" self.results = results self.print_search_results() self.jukebox.search(line, search_finished)
def do_search(self, line): if not line: if self.results is False: print "No search is in progress" elif self.results is None: print "Searching is in progress" else: print "Artists:" for a in self.results.artists(): print " ", Link.from_artist(a), a.name() print "Albums:" for a in self.results.albums(): print " ", Link.from_album(a), a.name() print "Tracks:" for a in self.results.tracks(): print " ", Link.from_track(a, 0), a.name() print self.results.total_tracks() - \ len(self.results.tracks()), "Tracks not shown" else: line = line.decode('utf-8') self.results = None def search_finished(results, userdata): print "\nSearch results received" self.results = results self.print_search_results() self.jukebox.search(line, search_finished)
def action_search(self, line): if not line: if self.results is False: print "No search is in progress" return False elif self.results is None: print "Searching is in progress" else: print "Artists:" for a in self.results.artists(): print " ", Link.from_artist(a), a.name() print "Albums:" for a in self.results.albums(): print " ", Link.from_album(a), a.name() print "Tracks:" for a in self.results.tracks(): print " ", Link.from_track(a, 0), a.name() print self.results.total_tracks() - len(self.results.tracks()), "Tracks not shown" self.results = False else: self.results = None def _(results, userdata): print "\nSearch results received" self.results = results self.search(line, _)
def change_track(self, track_link): for index, item in enumerate(self.play_queue): if str(Link.from_track(item.track)) == track_link: self.current_track_index = index return True return False
def search_finished(results, userdata): resultsRendered = [] for a in results.tracks(): resultsRendered.append(dict(link=Link.from_track(a, 0), name=a.name())) self.results = resultsRendered jukeboxCondition.acquire() jukeboxCondition.notify() jukeboxCondition.release()
def __init__(self, track): super(PlayerCurrentTrackMessage, self).__init__( type='player.current_track', data=dict( name = track.name(), artists = ", ".join([artist.name() for artist in track.artists()]), link = str(Link.from_track(track)), duration = track.duration(), image_id = binascii.hexlify(track.album().cover())) if track else None)
def print_search_results(self): print "Artists:" for a in self.results.artists(): print " ", Link.from_artist(a), a.name() print "Albums:" for a in self.results.albums(): print " ", Link.from_album(a), a.name() print "Tracks:" for a in self.results.tracks(): print " ", Link.from_track(a, 0), a.name() print self.results.total_tracks() - len(self.results.tracks()), \ "Tracks not shown"
def to_mopidy_playlist(cls, spotify_playlist): if not spotify_playlist.is_loaded(): return Playlist(name=u'[loading...]') if spotify_playlist.type() != 'playlist': return try: return Playlist( uri=str(Link.from_playlist(spotify_playlist)), name=spotify_playlist.name(), # FIXME if check on link is a hackish workaround for is_local tracks=[cls.to_mopidy_track(t) for t in spotify_playlist if str(Link.from_track(t, 0))], ) except SpotifyError, e: logger.warning(u'Failed translating Spotify playlist: %s', e)
def create_track_object(self, track): ''' Factory for track directory objects ''' album_uri = str(Link.from_album(track.album())) track_uri = str(Link.from_track(track, 0)) thumbnail_url = self.server.get_art_url(album_uri) callback = Callback(self.play_track, uri=track_uri, ext="aiff") artists = (a.name().decode("utf-8") for a in track.artists()) return TrackObject( items=[MediaObject(parts=[PartObject(key=callback)], )], key=track.name().decode("utf-8"), rating_key=track.name().decode("utf-8"), title=track.name().decode("utf-8"), album=track.album().name().decode("utf-8"), artist=", ".join(artists), index=track.index(), duration=int(track.duration()), thumb=thumbnail_url)
def send_tracks(self): """ Send tracks that hasn't already been sent. """ tracks = set(self.loaded_tracks) - set(self.sent_tracks) tracks = list(tracks) tracks = [(unicode(Link.from_track(t, 0)), str(t.artists()[0]), t.name()) for t in tracks] # Rate limit tracks = tracks[:50] d = { 'action': 'add_tracks', 'tracks': tracks } self.connection.sendLine(pickle.dumps(d)) self.sent_tracks += tracks
def to_mopidy_playlist(cls, spotify_playlist): if not spotify_playlist.is_loaded(): return Playlist(name=u'[loading...]') # FIXME Replace this try-except with a check on the playlist type, # which is currently not supported by pyspotify, to avoid handling # playlist folder boundaries like normal playlists. try: return Playlist( uri=str(Link.from_playlist(spotify_playlist)), name=spotify_playlist.name(), # FIXME if check on link is a hackish workaround for is_local tracks=[cls.to_mopidy_track(t) for t in spotify_playlist if str(Link.from_track(t, 0))], ) except SpotifyError, e: logger.info(u'Failed translating Spotify playlist ' '(probably a playlist folder boundary): %s', e)
def to_mopidy_track(cls, spotify_track): if not spotify_track.is_loaded(): return Track(name=u'[loading...]') uri = str(Link.from_track(spotify_track, 0)) if dt.MINYEAR <= int(spotify_track.album().year()) <= dt.MAXYEAR: date = dt.date(spotify_track.album().year(), 1, 1) else: date = None return Track( uri=uri, name=spotify_track.name().decode(ENCODING), artists=[cls.to_mopidy_artist(a) for a in spotify_track.artists()], album=cls.to_mopidy_album(spotify_track.album()), track_no=spotify_track.index(), date=date, length=spotify_track.duration(), bitrate=(settings.SPOTIFY_HIGH_BITRATE and 320 or 160), )
def get_collection(self): ls = [] for pl in self.ctr: if(pl.name() != 'collection'): continue for song in pl: uri = unicode(str(Link.from_track(song))) title = unicode(song.name()) artists = [] for arts in song.artists(): artists.append(arts.name()) artist = unicode(' & '.join(artists)) album = unicode(song.album().name()) duration = int(song.duration() / 1000) ls.append(Song(uri, title, artist, album, duration)) return ls
def to_mopidy_track(cls, spotify_track): uri = str(Link.from_track(spotify_track, 0)) if not spotify_track.is_loaded(): return Track(uri=uri, name=u'[loading...]') spotify_album = spotify_track.album() if spotify_album is not None and spotify_album.is_loaded(): date = spotify_album.year() else: date = None return Track( uri=uri, name=spotify_track.name(), artists=[cls.to_mopidy_artist(a) for a in spotify_track.artists()], album=cls.to_mopidy_album(spotify_track.album()), track_no=spotify_track.index(), date=date, length=spotify_track.duration(), bitrate=settings.SPOTIFY_BITRATE, )
def to_mopidy_track(cls, spotify_track): uri = str(Link.from_track(spotify_track, 0)) if not spotify_track.is_loaded(): return Track(uri=uri, name=u'[loading...]') if (spotify_track.album() is not None and dt.MINYEAR <= int(spotify_track.album().year()) <= dt.MAXYEAR): date = dt.date(spotify_track.album().year(), 1, 1) else: date = None return Track( uri=uri, name=spotify_track.name(), artists=[cls.to_mopidy_artist(a) for a in spotify_track.artists()], album=cls.to_mopidy_album(spotify_track.album()), track_no=spotify_track.index(), date=date, length=spotify_track.duration(), bitrate=BITRATES[settings.SPOTIFY_BITRATE], )
def to_mopidy_track(cls, spotify_track): uri = str(Link.from_track(spotify_track, 0)) if not spotify_track.is_loaded(): return Track(uri=uri, name=u'[loading...]') if (spotify_track.album() is not None and dt.MINYEAR <= int(spotify_track.album().year()) <= dt.MAXYEAR): date = dt.date(spotify_track.album().year(), 1, 1) else: date = None return Track( uri=uri, name=spotify_track.name(), artists=[cls.to_mopidy_artist(a) for a in spotify_track.artists()], album=cls.to_mopidy_album(spotify_track.album()), track_no=spotify_track.index(), date=date, length=spotify_track.duration(), bitrate=settings.SPOTIFY_BITRATE, )
def to_mopidy_playlist(cls, spotify_playlist): if not spotify_playlist.is_loaded(): return Playlist(name=u'[loading...]') # FIXME Replace this try-except with a check on the playlist type, # which is currently not supported by pyspotify, to avoid handling # playlist folder boundaries like normal playlists. try: return Playlist( uri=str(Link.from_playlist(spotify_playlist)), name=spotify_playlist.name(), # FIXME if check on link is a hackish workaround for is_local tracks=[ cls.to_mopidy_track(t) for t in spotify_playlist if str(Link.from_track(t, 0)) ], ) except SpotifyError, e: logger.info( u'Failed translating Spotify playlist ' '(probably a playlist folder boundary): %s', e)
def replace_queue(self, tracks, playing_track_link_uri): # clear current playing track self.current_track_index = -1 # clear current queue del self.play_queue[:] # add new tracks for index, track in enumerate(filter(lambda track: track.availability() == 1, tracks)): self.__append_play_queue(track) if str(Link.from_track(track)) == playing_track_link_uri: self.current_track_index = index # shuffle? self.__apply_shuffling() if self.current_track_index == -1 and len(self.play_queue) > 0: self.current_track_index = 0
def do_search(self,session, line): if not line: if self.results is False: print "No search is in progress" elif self.results is None: print "Searching is in progress" else: for a in self.results.tracks(): print " ", Link.from_track(a, 0), a.name() print "%d tracks not shown" % ( self.results.total_tracks() - len(self.results.tracks())) else: line = line.decode('utf-8') self.results = None def search_finished(results, userdata): print "\nSearch results received" self.results = results self.add_track_results() session.search(line, search_finished)
def create_track_object(self, track): ''' Factory for track directory objects ''' album_uri = str(Link.from_album(track.album())) track_uri = str(Link.from_track(track, 0)) thumbnail_url = self.server.get_art_url(album_uri) callback = Callback(self.play_track, uri = track_uri, ext = "aiff") artists = (a.name().decode("utf-8") for a in track.artists()) return TrackObject( items = [ MediaObject( parts = [PartObject(key = callback)], ) ], key = track.name().decode("utf-8"), rating_key = track.name().decode("utf-8"), title = track.name().decode("utf-8"), album = track.album().name().decode("utf-8"), artist = ", ".join(artists), index = track.index(), duration = int(track.duration()), thumb = thumbnail_url )
def to_mopidy_track(spotify_track): if spotify_track is None: return uri = str(Link.from_track(spotify_track, 0)) if uri in track_cache: return track_cache[uri] if not spotify_track.is_loaded(): return Track(uri=uri, name='[loading...]') spotify_album = spotify_track.album() if spotify_album is not None and spotify_album.is_loaded(): date = spotify_album.year() else: date = None track_cache[uri] = Track( uri=uri, name=spotify_track.name(), artists=[to_mopidy_artist(a) for a in spotify_track.artists()], album=to_mopidy_album(spotify_track.album()), track_no=spotify_track.index(), date=date, length=spotify_track.duration(), bitrate=settings.SPOTIFY_BITRATE) return track_cache[uri]
def track_id(self): """ Return the id of the track within the provider namespace. """ return unicode(Link.from_track(self.track, 0))
def run(self): # wait for container container_loaded.wait() container_loaded.clear() while True: link_string = self._queue.next_link() if link_string == '': break link = Link.from_string(link_string) if link.type() == Link.LINK_TRACK: track = link.as_track() itrack = iter([track]) elif link.type() == Link.LINK_PLAYLIST \ or link_string == 'spotify:user:'******'username')+':starred': print 'Loading playlist %s ...' % link_string playlist = link.as_playlist() while not playlist.is_loaded(): time.sleep(0.1) itrack = iter(playlist) elif link.type() == Link.LINK_ALBUM: print 'Processing album %s' % str(link) itrack = [ ] album = link.as_album() album_browser = AlbumBrowser(album) while not album_browser.is_loaded(): time.sleep(0.1) if self._util.is_compilation(album): continue if album.is_available(): print 'Getting tracks for %s' % album.name() for track in album_browser: itrack.append(track) elif link.type() == Link.LINK_ARTIST: print "Processing artist %s ..." % str(link) artist = link.as_artist() artist_browser = ArtistBrowser(artist, 'no_tracks') while not artist_browser.is_loaded(): time.sleep(0.1) print "Artist loaded" print(artist.name()) similar_artists = artist_browser.similar_artists() for similar_artist in similar_artists: self._queue.add_artist_link(similar_artist, 'similar') albums = artist_browser.albums() processed_albums = [ ] itrack = [ ] for album in albums: if self._util.is_compilation(album): continue if album.is_available() and Link.from_album(album) \ not in processed_albums: processed_albums.append(Link.from_album(album)) print 'Getting tracks for %s' % album.name() album_browser = AlbumBrowser(album) while not album_browser.is_loaded(): time.sleep(0.1) for track in album_browser: itrack.append(track) else: print "Unrecognised link" os._exit(2) return # ripping loop session = self._ripper.session for track in itrack: if self._util.is_known_not_available(Link.from_track(track)): continue try: self._ripper.load_track(track) while not track.is_loaded(): time.sleep(0.1) for track_artist in track.artists(): self._queue.add_artist_link(track_artist, 'track') if self._ripper.rip_init(session, track): self._ripper.play() self._end_of_track.wait() self._end_of_track.clear() self._ripper.rip_terminate(session, track) self._ripper.rip_id3(session, track) except TrackNotAvailableException: print "Track not available (%s)" % track.name() self._util.mark_as_not_available(Link.from_track(track)) self._ripper.disconnect()