Skip to content

Commit b103e16

Browse files
author
Dimitris Dalianis
committed
Make scrobbler plugin use proxy settings
1 parent c6a2ac8 commit b103e16

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

mopidy_scrobbler/frontend.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,21 @@ def __init__(self, config, core):
2626
def on_start(self):
2727
try:
2828
self.lastfm = pylast.LastFMNetwork(
29-
api_key=API_KEY, api_secret=API_SECRET,
30-
username=self.config['scrobbler']['username'],
31-
password_hash=pylast.md5(self.config['scrobbler']['password']))
29+
api_key=API_KEY,
30+
api_secret=API_SECRET
31+
)
32+
if self.config.get('proxy'):
33+
self.lastfm.enable_proxy(
34+
self.config['proxy']['hostname'],
35+
self.config['proxy']['port']
36+
)
37+
self.lastfm.username = self.config['scrobbler']['username']
38+
self.lastfm.password_hash = pylast.md5(
39+
self.config['scrobbler']['password'])
40+
sk_gen = pylast.SessionKeyGenerator(self.lastfm)
41+
self.lastfm.session_key = sk_gen.get_session_key(
42+
self.lastfm.username,
43+
self.lastfm.password_hash)
3244
logger.info('Scrobbler connected to Last.fm')
3345
except (pylast.NetworkError, pylast.MalformedResponseError,
3446
pylast.WSError) as e:

tests/test_frontend.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,34 @@ def setUp(self):
1717
'scrobbler': {
1818
'username': 'alice',
1919
'password': 'secret',
20+
},
21+
'proxy': {
22+
'hostname': 'myhost',
23+
'port': 8080
2024
}
2125
}
2226
self.frontend = frontend_lib.ScrobblerFrontend(
2327
self.config, mock.sentinel.core)
2428

2529
def test_on_start_creates_lastfm_network(self, pylast_mock):
30+
self.frontend.lastfm = mock.Mock(spec=pylast.LastFMNetwork)
31+
sk_gen = mock.Mock(spec=pylast.SessionKeyGenerator)
32+
pylast_mock.SessionKeyGenerator.return_value = sk_gen
2633
pylast_mock.md5.return_value = mock.sentinel.password_hash
2734

2835
self.frontend.on_start()
2936

3037
pylast_mock.LastFMNetwork.assert_called_with(
3138
api_key=frontend_lib.API_KEY,
32-
api_secret=frontend_lib.API_SECRET,
33-
username='alice',
34-
password_hash=mock.sentinel.password_hash)
39+
api_secret=frontend_lib.API_SECRET)
40+
self.frontend.lastfm.enable_proxy.assert_called_with(
41+
'myhost',
42+
8080)
43+
pylast_mock.SessionKeyGenerator.assert_called_with(
44+
self.frontend.lastfm)
45+
sk_gen.get_session_key.assert_called_with(
46+
'alice',
47+
mock.sentinel.password_hash)
3548

3649
def test_on_start_stops_actor_on_error(self, pylast_mock):
3750
pylast_mock.NetworkError = pylast.NetworkError

0 commit comments

Comments
 (0)