spotify: Fix flake8 warnings in lookup method

This commit is contained in:
Stein Magnus Jodal 2012-12-19 20:29:45 +01:00
parent aea3337fe4
commit d5c401bd07

View File

@ -10,7 +10,6 @@ from spotify import Link, SpotifyError
from mopidy.backends import base from mopidy.backends import base
from mopidy.models import Track from mopidy.models import Track
from mopidy.backends.base import BaseLibraryProvider
from mopidy.models import Playlist from mopidy.models import Playlist
from . import translator from . import translator
@ -66,10 +65,11 @@ class SpotifyLibraryProvider(base.BaseLibraryProvider):
if link.type() == Link.LINK_ALBUM: if link.type() == Link.LINK_ALBUM:
try: try:
spotify_album = Link.from_string(uri).as_album() spotify_album = Link.from_string(uri).as_album()
# TODO Block until metadata_updated callback is called. Before that # TODO Block until metadata_updated callback is called.
# the track will be unloaded, unless it's already in the stored # Before that the track will be unloaded, unless it's
# playlists. # already in the stored playlists.
browser = self.backend.spotify.session.browse_album(spotify_album) browser = self.backend.spotify.session.browse_album(
spotify_album)
#wait 5 seconds #wait 5 seconds
start = time.time() start = time.time()
@ -83,10 +83,12 @@ class SpotifyLibraryProvider(base.BaseLibraryProvider):
# track = translator.to_mopidy_track(track) # track = translator.to_mopidy_track(track)
#from translator #from translator
tracks=[translator.to_mopidy_track(t) for t in browser tracks = [
if str(Link.from_track(t, 0))] translator.to_mopidy_track(t)
for t in browser if str(Link.from_track(t, 0))]
playlist = Playlist(tracks=tracks, uri=uri, name=album.name) playlist = Playlist(
tracks=tracks, uri=uri, name=album.name)
return playlist return playlist
except SpotifyError as e: except SpotifyError as e:
@ -97,10 +99,11 @@ class SpotifyLibraryProvider(base.BaseLibraryProvider):
if link.type() == Link.LINK_ARTIST: if link.type() == Link.LINK_ARTIST:
try: try:
spotify_artist = Link.from_string(uri).as_artist() spotify_artist = Link.from_string(uri).as_artist()
# TODO Block until metadata_updated callback is called. Before that # TODO Block until metadata_updated callback is called.
# the track will be unloaded, unless it's already in the stored # Before that the track will be unloaded, unless it's
# playlists. # already in the stored playlists.
browser = self.backend.spotify.session.browse_artist(spotify_artist) browser = self.backend.spotify.session.browse_artist(
spotify_artist)
#wait 5 seconds #wait 5 seconds
start = time.time() start = time.time()
while not browser.is_loaded(): while not browser.is_loaded():
@ -113,10 +116,12 @@ class SpotifyLibraryProvider(base.BaseLibraryProvider):
# track = translator.to_mopidy_track(track) # track = translator.to_mopidy_track(track)
#from translator #from translator
tracks=[translator.to_mopidy_track(t) for t in browser tracks = [
if str(Link.from_track(t, 0))] translator.to_mopidy_track(t)
for t in browser if str(Link.from_track(t, 0))]
playlist = Playlist(tracks=tracks, uri=uri, name=artist.name) playlist = Playlist(
tracks=tracks, uri=uri, name=artist.name)
return playlist return playlist
except SpotifyError as e: except SpotifyError as e:
@ -130,9 +135,9 @@ class SpotifyLibraryProvider(base.BaseLibraryProvider):
#uri is a track #uri is a track
try: try:
spotify_track = Link.from_string(uri).as_track() spotify_track = Link.from_string(uri).as_track()
# TODO Block until metadata_updated callback is called. Before that # TODO Block until metadata_updated callback is called. Before
# the track will be unloaded, unless it's already in the stored # that the track will be unloaded, unless it's already in the
# playlists. # stored playlists.
return translator.to_mopidy_track(spotify_track) return translator.to_mopidy_track(spotify_track)
except SpotifyError as e: except SpotifyError as e:
logger.debug(u'Failed to lookup track "%s": %s', uri, e) logger.debug(u'Failed to lookup track "%s": %s', uri, e)