@@ -94,6 +94,7 @@ def clear(self):
9494 self .playlist = None
9595 self .song_list = []
9696 self ._trigger_redraw = False
97+ self .temporary_song = None
9798
9899 def has_been_loaded (self ):
99100 '''
@@ -263,33 +264,34 @@ def get_ui(self):
263264 for song_idx in songs_to_show :
264265 song = self .get_track_by_idx (song_idx )
265266 right_side = right_side_items and right_side_items .pop (0 )
267+ extra_text = (
268+ artist_banned_text (self .navigator , song ) or
269+ (
270+ self .song_order [song_idx ] == self .temporary_song and
271+ '[temporary]'
272+ )
273+ )
266274 if song_idx == self .current_track_idx :
267275 if song_idx != songs_to_show [0 ]:
268276 # Small spacing around current...
269277 res .append (('' , right_side or '' ))
270278 right_side = (
271279 right_side_items and right_side_items .pop (0 )
272280 )
273- formatted_song = '>>>%s' % format_track (
274- song ,
275- artist_banned_text (self .navigator , song )
276- )
281+ formatted_song = '>>>%s' % format_track (song , extra_text )
277282 else :
278- formatted_song = format_track (
279- song ,
280- artist_banned_text (self .navigator , song )
281- )
283+ formatted_song = format_track (song , extra_text )
282284 res .append ((formatted_song , right_side or '' ))
283285 if song_idx == self .current_track_idx :
284286 if song_idx != songs_to_show [- 1 ]:
285287 # Small spacing around current...
286288 right_side = (
287- right_side_items and right_side_items .pop ()
289+ right_side_items and right_side_items .pop (0 )
288290 )
289291 res .append (('' , right_side or '' ))
290292 while right_side_items :
291293 # This can happend f.x. when we have one song...
292- res .append (('' , right_side_items .pop ()))
294+ res .append (('' , right_side_items .pop (0 )))
293295 else :
294296 res .append ('No songs found in playlist!' )
295297
@@ -503,6 +505,22 @@ def toggle_repeat(self):
503505 return NOOP
504506
505507 # Song handling
508+ def add_play_then_remove (self , item ):
509+ '''
510+ Adds item to the current queue temporary. After the song has been added
511+ it will start playing. Once it's finished or navigated from it, it will
512+ be removed and the song that was playing when it was added will start
513+ playing.
514+ temporary_song is the index to the currently temporary song in the
515+ song_list, not in song_order
516+ '''
517+ self .clean_temporary_song ()
518+ idx_of_new_item = len (self .song_list )
519+ self .song_list .append (item )
520+ self .song_order .insert (self .current_track_idx , idx_of_new_item )
521+ self .temporary_song = idx_of_new_item
522+ self .play_current_song (start_playing = True , clean_temporary = False )
523+
506524 def add_to_queue (self , item ):
507525 '''
508526 Adds item to the end of the current song list. Item can be either
@@ -522,6 +540,23 @@ def add_to_queue(self, item):
522540 self .add_to_queue (track )
523541 self .playlist = None
524542
543+ def clean_temporary_song (self ):
544+ '''
545+ If there is a temporary song in the queue, remove it from the song list
546+ and make sure that the song playing before it gets selected
547+ :returns: None
548+ '''
549+ if self .temporary_song :
550+ temporary_song_index = self .song_order .index (self .temporary_song )
551+ self .song_order .remove (self .temporary_song )
552+ del self .song_list [self .temporary_song ]
553+ self .temporary_song = None
554+ if temporary_song_index < self .current_track_idx :
555+ # If the previous song came before the current (which happens
556+ # unless the user selected the previous song) we have to
557+ # select the previous song so we don't jump to the next one.
558+ self .current_track_idx = self .get_prev_idx ()
559+
525560 def check_end_of_track (self ):
526561 '''
527562 Checks if the current song has finished playing and starts playing
@@ -607,14 +642,22 @@ def on_end_of_track(self, session=None):
607642 '''
608643 self .end_of_track .set ()
609644 thread .interrupt_main ()
645+ return False
610646
611- def play_current_song (self , start_playing = True ):
647+ def play_current_song (self , start_playing = True , clean_temporary = True ):
612648 '''
613- Plays the current song
649+ Plays the current song.
650+ Before playing these actions are performed:
651+ 1. Removes the temporary song if there is one.
652+ 2. If the current track's artist is banned, removes the current
653+ song.
614654 :returns: None
615655 '''
616656 self .player .unload ()
617657
658+ if clean_temporary :
659+ self .clean_temporary_song ()
660+
618661 current_track = self .get_track_by_idx (self .current_track_idx )
619662 if not current_track :
620663 self .current_track = None
0 commit comments