Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 04e002b

Browse files
committed
Merge pull request #109 from sindrig/1.4.5
1.4.5
2 parents 36dc4e4 + d7581fb commit 04e002b

File tree

9 files changed

+27
-18
lines changed

9 files changed

+27
-18
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ DBus integration
4545

4646
1. Run `make install_dbus`
4747
2. Make sure you have python-gobject2 installed
48-
3. Symlink gobject (and possibly glib) to your virtualenv (that is, if you're not installing globally!)
48+
3. Symlink gi (and possibly glib) to your virtualenv (that is, if you're not installing globally!)
4949

50-
* ln -s /usr/lib/python3.5/site-packages/gobject/ $VIRTUAL_ENV/lib/python3.5/site-packages/gobject
50+
* ln -s /usr/lib/python3.5/site-packages/gi/ $VIRTUAL_ENV/lib/python3.5/site-packages/gi
5151
* ln -s /usr/lib/python3.5/site-packages/glib/ $VIRTUAL_ENV/lib/python3.5/site-packages/glib
5252

5353
4. The service will be available at "/com/spoppy" (f.x. :code:`qdbus com.spoppy /com/spoppy com.spoppy.PlayPause`)

spoppy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def get_version():
13-
return '1.4.4'
13+
return '1.4.5'
1414

1515
if click:
1616
@click.command()

spoppy/dbus_listener.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
)
2525

2626
try:
27-
import gobject
27+
from gi.repository import GObject
2828
except ImportError:
29-
gobject = None
29+
GObject = None
3030
logger.warning(
3131
'gobject not installed, you won\'t be able to control the '
3232
'player via DBus'
@@ -39,7 +39,7 @@ def __init__(self, lifecycle):
3939
self.lifecycle = lifecycle
4040

4141
def run(self):
42-
gobject.threads_init()
42+
GObject.threads_init()
4343
dbus.mainloop.glib.threads_init()
4444
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
4545
bus_name = dbus.service.BusName(
@@ -50,7 +50,7 @@ def run(self):
5050
bus_name, "/com/spoppy"
5151
)
5252

53-
self._loop = gobject.MainLoop()
53+
self._loop = GObject.MainLoop()
5454
self._loop.run()
5555

5656
def stop(self):
@@ -104,7 +104,7 @@ class DBusListener(threading.Thread):
104104
def __init__(self, lifecycle, stop_event, *args):
105105
self.lifecycle = lifecycle
106106
self.stop_event = stop_event
107-
self.should_run = dbus and gobject
107+
self.should_run = dbus and GObject
108108
if not self.should_run:
109109
logger.warning(
110110
'DBusListener thread aborting because of missing dependencies'

spoppy/menus.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import random
32
import threading
43
import webbrowser
54
from collections import namedtuple
@@ -876,6 +875,8 @@ class RadioSelected(TrackSearchResults):
876875
radio_name = ''
877876

878877
def get_header(self):
878+
if not self.search.results.total:
879+
return 'Song cannot be played in radio, sorry!'
879880
return 'Radio list "%s" generated:' % self.get_mock_playlist_name()
880881

881882
def get_mock_playlist_name(self):

spoppy/navigation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ def navigate_to(self, going):
6262
self.session.process_events()
6363
going.initialize()
6464
while self.navigating:
65-
logger.debug('clearing screen...')
6665
click.clear()
6766
self.print_header()
6867
self.print_menu(going.get_ui())
6968
response = going.get_response()
70-
logger.debug('Got response %s' % response)
7169
if callable(response):
7270
response = response()
7371
logger.debug('Got response %s after evaluation' % response)

spoppy/players.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ def add_to_queue(self, item):
494494
self.song_order.append(len(self.song_order))
495495
# Add the song to the current song list
496496
self.song_list.append(item)
497+
if not self.current_track:
498+
self.play_current_song(start_playing=False)
497499
elif hasattr(item, 'tracks'):
498500
for track in item.tracks:
499501
if track.availability != spotify.TrackAvailability.UNAVAILABLE:
@@ -586,7 +588,7 @@ def on_end_of_track(self, session=None):
586588
self.end_of_track.set()
587589
thread.interrupt_main()
588590

589-
def play_current_song(self):
591+
def play_current_song(self, start_playing=True):
590592
'''
591593
Plays the current song
592594
:returns: None
@@ -606,7 +608,8 @@ def play_current_song(self):
606608
)
607609

608610
self.player.load(self.current_track)
609-
self.play_pause()
611+
if start_playing:
612+
self.play_pause()
610613

611614
self.seconds_played = 0
612615

spoppy/radio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def get_empty_results(self):
7373
return RadioResults([])
7474

7575
def handle_results(self, response_data):
76+
logger.debug('Got %d songs', len(response_data))
7677
item_results = self.manipulate_items([
7778
self.item_cls(self.session, item['uri'])
7879
for item in response_data

spoppy/search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class Search(threading.Thread):
3232
ENDPOINTS = {
3333
# Each entry is a tuple, (HTTP_ENDPOINT, CLS)
3434
'tracks': (
35-
'/v1/search?query={query}&offset=0&limit=20&type=track',
35+
u'/v1/search?query={query}&offset=0&limit=20&type=track',
3636
Track
3737
),
3838
'albums': (
39-
'/v1/search?query={query}&offset=0&limit=20&type=album',
39+
u'/v1/search?query={query}&offset=0&limit=20&type=album',
4040
Album
4141
),
4242
'artists': (
43-
'/v1/search?query={query}&offset=0&limit=20&type=artist',
43+
u'/v1/search?query={query}&offset=0&limit=20&type=artist',
4444
None
4545
),
4646
}

tests/test_players.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,18 @@ def test_toggle_repeat(self):
264264
sorted(seen_repeat_flags)
265265
)
266266

267-
def test_add_track_to_queue(self):
267+
@patch('spoppy.players.Player.play_current_song')
268+
def test_add_track_to_queue(self, patched_play_current_song):
268269
track = MagicMock(spec=spotify.Track)
269270
self.player.playlist = 'foo'
271+
self.assertIsNone(self.player.current_track)
270272
self.assertIsNone(self.player.add_to_queue(track))
271273
self.assertIn(track, self.player.song_list)
272274
self.assertIsNone(self.player.playlist)
275+
patched_play_current_song.assert_called_once_with(start_playing=False)
273276

274-
def test_add_playlist_to_queue(self):
277+
@patch('spoppy.players.Player.play_current_song')
278+
def test_add_playlist_to_queue(self, patched_play_current_song):
275279
tracks = [
276280
MagicMock(spec=spotify.Track),
277281
MagicMock(spec=spotify.Track),
@@ -286,6 +290,8 @@ def test_add_playlist_to_queue(self):
286290
for track in tracks:
287291
self.assertIn(track, self.player.song_list)
288292
self.assertIsNone(self.player.playlist)
293+
self.assertEqual(patched_play_current_song.call_count, 3)
294+
patched_play_current_song.assert_called_with(start_playing=False)
289295

290296
@patch('spoppy.players.Player.next_song')
291297
@patch('spoppy.players.Player.play_current_song')

0 commit comments

Comments
 (0)