1
# Copyright (C) 2006 Adam Olsen
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 1, or (at your option)
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
This plugin is a complete hack.
22
Props to Vidar Madsen for the lastfmproxy application, which this plugin
26
from xl.nls import gettext as _
27
from xl import event, common, playlist, track, settings
28
from xl.radio import *
29
import os, os.path, logging
33
logger = logging.getLogger(__name__)
35
def album_callback(*e):
39
def run_proxy(config):
43
STATION.listenport = config.listenport
44
PROXY.run(config.bind_address, config.listenport)
52
logger.warning("LastFM Proxy: Port %d in use, trying %d" %
53
(config.listenport, config.listenport + 1))
54
config.listenport += 1
60
event.add_callback(_enable, 'exaile_loaded')
62
_enable(None, exaile, None)
69
def _enable(devicename, exaile, nothing):
70
global STATION, PROXY, HTTP_CLIENT, BUTTONS, SHOW_COVER
72
port = settings.get_option('plugin/lastfm/listenport', 1881)
73
config.listenport = port
75
config.username = settings.get_option('plugin/lastfm/user', '')
76
config.password = settings.get_option('plugin/lastfm/password', '')
79
STATION = LastFMRadioStation(config)
80
exaile.radio.add_station(STATION)
81
HTTP_CLIENT = httpclient.httpclient('__localhost', config.listenport)
83
PROXY = lastfmmain.proxy(config.username, config.password)
84
PROXY.np_image_func = album_callback
85
basedir = os.path.dirname(os.path.realpath(__file__))
86
PROXY.basedir = basedir
89
event.add_callback(STATION.on_playback_start, 'playback_start',
97
exaile.radio.remove_station(STATION)
99
PROXY.np_image_func = None
104
event.remove_callback(STATION.on_playback_start, 'playback_track_start',
108
class LastFMRadioStation(RadioStation):
113
def __init__(self, config):
115
Initializes the lastfm radio station
119
def on_playback_start(self, type, player, track):
120
station = track['lastfmstation']
122
self.command('/changestation/%s' % station)
125
def command(self, command):
126
logger.info("LastFM: running command %s" % command)
127
HTTP_CLIENT.req(command)
129
def _load_cache(self):
132
def _save_cache(self):
135
def get_lists(self, no_cache=False):
137
Returns the list of items for lastfm
140
(_('Personal'), 'lastfm://user/%s/personal' % self.config.username),
141
(_('Recommended'), 'lastfm://user/%s/recommended/100' %
142
self.config.username),
143
(_('Neighbourhood'), 'lastfm://user/%s/neighbours' %
144
self.config.username),
145
(_('Loved Tracks'), 'lastfm://user/%s/loved' % self.config.username),
149
for name, url in stations:
150
item = RadioItem(name, station=self)
151
item.get_playlist = lambda url=url, name=name: \
152
self._get_playlist(url, name)
157
def _get_playlist(self, url, name):
158
self.listenport = config.listenport
160
tr.set_loc('http://localhost:%d/lastfm.mp3' % self.listenport)
161
tr['album'] = "LastFM: %s" % name
162
tr['title'] = "LastFM: %s" % name
163
tr['artist'] = _("LastFM Radio")
164
tr['lastfmstation'] = url
166
pl = playlist.Playlist(name=_("LastFM: %s") % name, kind='radio')
171
def get_menu(self, parent):