@@ -3725,6 +3725,7 @@ def _open_playlist(self, a_url=None):
37253725 self ._set_active_stations ()
37263726 self ._update_status_bar_right ()
37273727 if self ._cnf .browsing_station_service :
3728+ logger .error ('1' )
37283729 # TODO
37293730 if HAS_REQUESTS :
37303731 if HAS_DNSPYTHON :
@@ -3768,6 +3769,7 @@ def _open_playlist(self, a_url=None):
37683769 self ._print_requests_not_installed_error ()
37693770 self ._cnf .browsing_station_service = False
37703771 elif self ._cnf .register_to_open :
3772+ logger .error ('2' )
37713773 ''' open a register '''
37723774 self ._playlist_in_editor = self ._cnf .register_to_open
37733775 if logger .isEnabledFor (logging .DEBUG ):
@@ -3797,6 +3799,7 @@ def _open_playlist(self, a_url=None):
37973799 self ._cnf .register_to_open = None
37983800 # self.ll('opening a register')
37993801 else :
3802+ logger .error ('3' )
38003803 ''' Open list of playlists or registers '''
38013804 #if self._cnf._open_register_list:
38023805 # txt = '''Reading registers. Please wait...'''
@@ -8337,27 +8340,67 @@ def _add_station_to_stations_history(self):
83378340 playlist = self ._cnf .station_title
83388341 station = self .stations [self .selection ]
83398342 sel = self .selection
8340- self ._cnf .stations_history .add (self ._cnf .station_title , self .stations [self .selection ][0 ], self .selection )
8343+ self ._cnf .stations_history .add (self ._cnf .station_file_name [: - 4 ] , self .stations [self .playing ][0 ], self .playing )
83418344
83428345 def _load_playlist_and_station_from_station_history (self , old_h_item , h_item ):
83438346 if logger .isEnabledFor (logging .DEBUG ):
8344- logger .debug ('activating history item: {}' .format (h_item ))
8347+ logger .debug ('Activating history item: {}' .format (h_item ))
83458348
83468349 if self .stations [h_item [- 1 ]][0 ] == h_item [1 ]:
83478350 ''' station found '''
8348- logger .error ('station found' )
8349- self .setStation (h_item [- 1 ])
8350- if self .number_of_items > 0 :
8351- self .playSelection ()
8352- self ._goto_playing_station (changing_playlist = False )
8353- self .refreshBody ()
8354- self .selections [self .ws .NORMAL_MODE ] = [self .selection ,
8355- self .startPos ,
8356- self .playing ,
8357- self .stations ]
8351+ num = h_item [- 1 ]
83588352 else :
83598353 ''' I have to scan the playlist'''
8360- logger .error ('have to scan playlist' )
8361- pass
8354+ if logger .isEnabledFor (logging .DEBUG ):
8355+ logger .error ('Scanning playlist...' )
8356+ up = down = 0
8357+ num = - 1
8358+ for i in range (h_item [- 1 ], - 1 , - 1 ):
8359+ up = i + 1
8360+ down = i - 1
8361+ if down > - 1 :
8362+ if self .stations [down ][0 ] == h_item [1 ]:
8363+ num = down
8364+ break
8365+ if up < self ._cnf .number_of_stations :
8366+ if self .stations [up ][0 ] == h_item [1 ]:
8367+ num = up
8368+ break
8369+ up += 1
8370+ down -= 1
8371+ if num == - 1 and down > - 1 :
8372+ if logger .isEnabledFor (logging .DEBUG ):
8373+ logger .debug ('Station not found... Scanning to top...' )
8374+ for i in range (down , - 1 , - 1 ):
8375+ if self .stations [i ][0 ] == h_item [1 ]:
8376+ num = i
8377+ break
8378+
8379+ if num == - 1 and up < self ._cnf .number_of_stations :
8380+ if logger .isEnabledFor (logging .DEBUG ):
8381+ logger .debug ('Station not found... Scanning to bottom...' )
8382+ for i in range (up , self ._cnf .number_of_stations - 1 ):
8383+ if self .stations [i ][0 ] == h_item [1 ]:
8384+ num = i
8385+ break
8386+
8387+ if num == - 1 :
8388+ ''' station not found '''
8389+ if logger .isEnabledFor (logging .DEBUG ):
8390+ logger .debug ('Station "{}" not found!' .format (h_item [1 ]))
8391+ return
8392+
8393+ if logger .isEnabledFor (logging .DEBUG ):
8394+ logger .debug ('Station "{0}" found at {1}' .format (h_item [1 ], num ))
8395+ self .setStation (num )
8396+ if self .number_of_items > 0 :
8397+ self .playSelection ()
8398+ #self._goto_playing_station(changing_playlist=False)
8399+ self ._align_stations_and_refresh (self .ws .PLAYLIST_MODE )
8400+ self .refreshBody ()
8401+ self .selections [self .ws .NORMAL_MODE ] = [self .selection ,
8402+ self .startPos ,
8403+ self .playing ,
8404+ self .stations ]
83628405
83638406# pymode:lint_ignore=W901
0 commit comments