Skip to content

Commit b9d3474

Browse files
committed
- adding continous_playback config option
- fixing a CVS read crash when no items in file
1 parent cf26815 commit b9d3474

File tree

5 files changed

+43
-18
lines changed

5 files changed

+43
-18
lines changed

pyradio/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ def update_stations_csv(self, print_messages=True):
642642
class CsvReadWrite():
643643
''' A base class to read and write a PyRadio playlist '''
644644
_items = None
645+
_version = Station.url
645646

646647
encoding_to_remove = None
647648

pyradio/config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ default_playlist = stations
2727
# Default value: False
2828
default_station = False
2929

30+
# Continuous playback
31+
# When changing playlists while playing a station, PyRadio will check if the
32+
# station currently playing is in the newly opened playlist. If it is,
33+
# playback will continue. If it is not there, playback will stop.
34+
#
35+
# When this option is set to True, playback will not stop even when the
36+
# station does not exist in the newly opened playlist.
37+
#
38+
# Default value: False
39+
continous_playback = False
40+
3041

3142
# Mouse support
3243
# If this options is enabled, the mouse can be used to scroll the playlist,

pyradio/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,7 @@ class PyRadioConfig(PyRadioStations):
12961296
opts['default_playlist'] = ['Def. playlist: ', 'stations']
12971297
opts['default_station'] = ['Def. station: ', 'False']
12981298
opts['default_encoding'] = ['Def. encoding: ', 'utf-8']
1299+
opts['continous_playback'] = ['Continous playback: ', False]
12991300
opts['recording_dir'] = ['Recordings dir: ', '']
13001301
opts['resource_opener'] = ['Resource Opener: ', 'auto']
13011302
opts['log_titles'] = ['Log titles: ', False]
@@ -1467,6 +1468,15 @@ def __init__(self, user_config_dir=None, headless=False):
14671468
self._read_notification_command()
14681469
self.profile_manager = ProfileManager()
14691470

1471+
@property
1472+
def continous_playback(self):
1473+
return self.opts['continous_playback'][1]
1474+
1475+
@continous_playback.setter
1476+
def continous_playback(self, val):
1477+
self.opts['continous_playback'][1] = val
1478+
self.opts['dirty_config'][1] = True
1479+
14701480
@property
14711481
def mplayer_save_br(self):
14721482
return self.opts['mplayer_save_br'][1]
@@ -2354,6 +2364,11 @@ def _read_config(self, distro_config=False):
23542364
self.opts['default_station'][1] = None
23552365
else:
23562366
self.opts['default_station'][1] = st
2367+
elif sp[0] == 'continous_playback':
2368+
if sp[1].lower() == 'false':
2369+
self.opts['continous_playback'][1] = False
2370+
else:
2371+
self.opts['continous_playback'][1] = True
23572372
elif sp[0] == 'open_last_playlist':
23582373
if sp[1].lower() == 'false':
23592374
self.opts['open_last_playlist'][1] = False

pyradio/config_window.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class PyRadioConfigWindow():
7070
_help_text.append(['This is the encoding used by default when reading data provided by a station such as song title, etc. If reading said data ends up in an error, "utf-8" will be used instead.', '|',
7171
'If changed, playback must be restarted so that changes take effect.',
7272
'|', 'Default value: utf-8'])
73+
_help_text.append(['When changing playlists while playing a station, PyRadio will check if the station currently playing is in the newly opened playlist. If it is, playback will continue. If it is not there, playback will stop.', '|', 'When this option is set to True, playback will not stop even when the station does not exist in the newly opened playlist.', '|', 'Default value: False'])
7374
_help_text.append([ 'This is the folder where recorded files will be saved', '|', 'Tip: When you open the window "h" will display HTML help about this parameter (not in Line Editor).', '|', 'Default value: "pyradio-recordings" in home dir' ])
7475
_help_text.append(['This is a Linux (et al) only parameter. It has no effect on Windows or MacOS.', '|',
7576
'Default value is "auto", in which case, PyRadio will try to use xdg-open, gio, mimeopen, mimeo or handlr, in that order of detection. If none if found, the requested file will simply not open.'
@@ -1105,7 +1106,8 @@ def keypress(self, char):
11051106
sel == 'wheel_adjusts_volume' or \
11061107
sel == 'log_titles' or \
11071108
sel == 'remove_station_icons' or \
1108-
sel == 'mplayer_save_br':
1109+
sel == 'mplayer_save_br' or \
1110+
sel == 'continous_playback':
11091111
self._config_options[sel][1] = not self._config_options[sel][1]
11101112
# # if sel == 'open_last_playlist':
11111113
# # if self._config_options[sel][1]:

pyradio/radio.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,10 +3900,10 @@ def _align_stations_and_refresh(self,
39003900
''' The playlist is empty '''
39013901
# ok
39023902
self.detect_if_player_exited = False
3903-
if self.player.isPlaying():
3903+
if self.player.isPlaying() and \
3904+
not self._cnf.continous_playback:
39043905
self.stopPlayer()
3905-
self.playing, self.selection, self.stations, \
3906-
self.number_of_items = (-1, 0, 0, 0)
3906+
self.playing, self.selection, self.startPos = (-1, 0, 0)
39073907
self.refreshBody()
39083908
return
39093909
else:
@@ -3969,22 +3969,18 @@ def _align_stations_and_refresh(self,
39693969
logger.error('DE \n\n{}\n\n'.format(self.active_stations))
39703970
logger.error('DE \n\n{}\n\n'.format(self._last_played_station))
39713971
logger.error('DE \n\n{}\n\n'.format(self._last_played_playlist))
3972-
if self.player.isPlaying():
3973-
if self.active_stations[1][0]:
3974-
self.selection, self.playing = self._get_stations_ids((
3975-
self.active_stations[0][0],
3976-
self.active_stations[1][0]))
3977-
logger.error('1')
3978-
else:
3979-
self.selection, self.playing = self._get_stations_ids((
3980-
self.active_stations[0][0],
3981-
self._last_played_station[0]))
3982-
logger.error('2')
3983-
else:
3972+
logger.error('\n\nself.playing = {}, self._cnf.continous_playback = {}\n\n'.format(self.playing, self._cnf.continous_playback))
3973+
self.selection, self.playing = self._get_stations_ids((
3974+
self.active_stations[0][0],
3975+
self.active_stations[1][0]))
3976+
if self.playing == -1 and \
3977+
not self._cnf.continous_playback:
3978+
self.stopPlayer()
3979+
if self.player.isPlaying() and \
3980+
self.active_stations[1][0] == '':
39843981
self.selection, self.playing = self._get_stations_ids((
39853982
self.active_stations[0][0],
3986-
self.active_stations[1][0]))
3987-
logger.error('3')
3983+
self._last_played_station[0]))
39883984
# TODO: continue playing after changing playlist
39893985
# if self.player.isPlaying():
39903986
if self.playing > -1:

0 commit comments

Comments
 (0)