Update Last.fm frontend to use pylast>=0.5 and the new Scrobbling 2.0 API
This commit is contained in:
parent
6a29222751
commit
dbbde5fdd6
@ -21,6 +21,13 @@ No description yet.
|
|||||||
- Support high bitrate (320k) audio. See
|
- Support high bitrate (320k) audio. See
|
||||||
:attr:`mopidy.settings.SPOTIFY_HIGH_BITRATE` for details.
|
:attr:`mopidy.settings.SPOTIFY_HIGH_BITRATE` for details.
|
||||||
|
|
||||||
|
- Last.fm frontend:
|
||||||
|
|
||||||
|
- If you use the Last.fm frontend, you need to upgrade to pylast 0.5.
|
||||||
|
|
||||||
|
- Update to use Last.fm's new Scrobbling 2.0 API, as the old Submissions
|
||||||
|
Protocol 1.2.1 is deprecated. (Fixes: :issue:`33`)
|
||||||
|
|
||||||
|
|
||||||
**Changes**
|
**Changes**
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,8 @@ from mopidy.utils.process import BaseThread
|
|||||||
|
|
||||||
logger = logging.getLogger('mopidy.frontends.lastfm')
|
logger = logging.getLogger('mopidy.frontends.lastfm')
|
||||||
|
|
||||||
CLIENT_ID = u'mop'
|
API_KEY = '2236babefa8ebb3d93ea467560d00d04'
|
||||||
CLIENT_VERSION = get_version()
|
API_SECRET = '94d9a09c0cd5be955c4afaeaffcaefcd'
|
||||||
|
|
||||||
# pylast raises UnicodeEncodeError on conversion from unicode objects to
|
# pylast raises UnicodeEncodeError on conversion from unicode objects to
|
||||||
# ascii-encoded bytestrings, so we explicitly encode as utf-8 before passing
|
# ascii-encoded bytestrings, so we explicitly encode as utf-8 before passing
|
||||||
@ -34,7 +34,7 @@ class LastfmFrontend(BaseFrontend):
|
|||||||
|
|
||||||
**Dependencies:**
|
**Dependencies:**
|
||||||
|
|
||||||
- `pylast <http://code.google.com/p/pylast/>`_ >= 0.4.30
|
- `pylast <http://code.google.com/p/pylast/>`_ >= 0.5
|
||||||
|
|
||||||
**Settings:**
|
**Settings:**
|
||||||
|
|
||||||
@ -64,12 +64,11 @@ class LastfmFrontendThread(BaseThread):
|
|||||||
self.name = u'LastfmFrontendThread'
|
self.name = u'LastfmFrontendThread'
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
self.lastfm = None
|
self.lastfm = None
|
||||||
self.scrobbler = None
|
|
||||||
self.last_start_time = None
|
self.last_start_time = None
|
||||||
|
|
||||||
def run_inside_try(self):
|
def run_inside_try(self):
|
||||||
self.setup()
|
self.setup()
|
||||||
while self.scrobbler is not None:
|
while self.lastfm is not None:
|
||||||
self.connection.poll(None)
|
self.connection.poll(None)
|
||||||
message = self.connection.recv()
|
message = self.connection.recv()
|
||||||
self.process_message(message)
|
self.process_message(message)
|
||||||
@ -78,10 +77,9 @@ class LastfmFrontendThread(BaseThread):
|
|||||||
try:
|
try:
|
||||||
username = settings.LASTFM_USERNAME
|
username = settings.LASTFM_USERNAME
|
||||||
password_hash = pylast.md5(settings.LASTFM_PASSWORD)
|
password_hash = pylast.md5(settings.LASTFM_PASSWORD)
|
||||||
self.lastfm = pylast.get_lastfm_network(
|
self.lastfm = pylast.LastFMNetwork(
|
||||||
|
api_key=API_KEY, api_secret=API_SECRET,
|
||||||
username=username, password_hash=password_hash)
|
username=username, password_hash=password_hash)
|
||||||
self.scrobbler = self.lastfm.get_scrobbler(
|
|
||||||
CLIENT_ID, CLIENT_VERSION)
|
|
||||||
logger.info(u'Connected to Last.fm')
|
logger.info(u'Connected to Last.fm')
|
||||||
except SettingsError as e:
|
except SettingsError as e:
|
||||||
logger.info(u'Last.fm scrobbler not started')
|
logger.info(u'Last.fm scrobbler not started')
|
||||||
@ -103,12 +101,13 @@ class LastfmFrontendThread(BaseThread):
|
|||||||
self.last_start_time = int(time.time())
|
self.last_start_time = int(time.time())
|
||||||
logger.debug(u'Now playing track: %s - %s', artists, track.name)
|
logger.debug(u'Now playing track: %s - %s', artists, track.name)
|
||||||
try:
|
try:
|
||||||
self.scrobbler.report_now_playing(
|
self.lastfm.update_now_playing(
|
||||||
artists.encode(ENCODING),
|
artists.encode(ENCODING),
|
||||||
track.name.encode(ENCODING),
|
track.name.encode(ENCODING),
|
||||||
album=track.album.name.encode(ENCODING),
|
album=track.album.name.encode(ENCODING),
|
||||||
duration=duration,
|
duration=str(duration),
|
||||||
track_number=track.track_no)
|
track_number=str(track.track_no),
|
||||||
|
mbid=(track.musicbrainz_id or '').encode(ENCODING))
|
||||||
except (pylast.ScrobblingError, socket.error) as e:
|
except (pylast.ScrobblingError, socket.error) as e:
|
||||||
logger.warning(u'Last.fm now playing error: %s', e)
|
logger.warning(u'Last.fm now playing error: %s', e)
|
||||||
|
|
||||||
@ -127,14 +126,13 @@ class LastfmFrontendThread(BaseThread):
|
|||||||
self.last_start_time = int(time.time()) - duration
|
self.last_start_time = int(time.time()) - duration
|
||||||
logger.debug(u'Scrobbling track: %s - %s', artists, track.name)
|
logger.debug(u'Scrobbling track: %s - %s', artists, track.name)
|
||||||
try:
|
try:
|
||||||
self.scrobbler.scrobble(
|
self.lastfm.scrobble(
|
||||||
artists.encode(ENCODING),
|
artists.encode(ENCODING),
|
||||||
track.name.encode(ENCODING),
|
track.name.encode(ENCODING),
|
||||||
time_started=self.last_start_time,
|
str(self.last_start_time),
|
||||||
source=pylast.SCROBBLE_SOURCE_USER,
|
|
||||||
mode=pylast.SCROBBLE_MODE_PLAYED,
|
|
||||||
duration=duration,
|
|
||||||
album=track.album.name.encode(ENCODING),
|
album=track.album.name.encode(ENCODING),
|
||||||
track_number=track.track_no)
|
track_number=str(track.track_no),
|
||||||
|
duration=str(duration),
|
||||||
|
mbid=(track.musicbrainz_id or '').encode(ENCODING))
|
||||||
except (pylast.ScrobblingError, socket.error) as e:
|
except (pylast.ScrobblingError, socket.error) as e:
|
||||||
logger.warning(u'Last.fm scrobbling error: %s', e)
|
logger.warning(u'Last.fm scrobbling error: %s', e)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user