Skip to content

Commit e7a76e3

Browse files
committed
playlist history now works for local playlists
1 parent 1a5e729 commit e7a76e3

File tree

5 files changed

+262
-55
lines changed

5 files changed

+262
-55
lines changed

Changelog

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
2019-11-15
1+
2019-12-02 s-n-g
2+
* Adding playlist history (for local playlists)
3+
* WINDOWS: Volume will be saved when mplayer is installed in %APPDATA%\pyradio
4+
5+
2019-11-15 s-n-g
26
* PyRadio will not crush with mpv 0.30.0
37
Changing mpv's volume is still possible, but no info will be
48
presented on the Status Bar.
59
Furthermore, saving mpv's volume will not be possible
610
( mpv issue #7153: https://github.com/mpv-player/mpv/issues/7153 )
711

8-
2019-11-12
12+
2019-11-12 s-n-g
913
* When default played is changed in the config, a message to restart
1014
the application is presented to the user
1115
* Config / Default station: pading fixed
1216

13-
2019-11-10
17+
2019-11-10 s-n-g
1418
* Fixing vlc returned volume parsing (due to locales decimal separator)
1519

1620
2019-10-29 s-n-g

pyradio/config.py

Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ class PyRadioStations(object):
7171

7272
jump_tag = -1
7373

74-
_browsing_station_service = False
75-
7674
# station directory service object
7775
_online_browser = None
7876

@@ -133,11 +131,35 @@ def playlist_version(self, value):
133131

134132
@property
135133
def browsing_station_service(self):
136-
return self._browsing_station_service
134+
return self._ps.browsing_station_service
137135

138136
@browsing_station_service.setter
139137
def browsing_station_service(self, value):
140-
self._browsing_station_service = value
138+
self._ps.browsing_station_service = value
139+
140+
@property
141+
def history_selection(self):
142+
return self._ps.selection
143+
144+
@history_selection.setter
145+
def history_selection(self, value):
146+
self._ps.selection = value
147+
148+
@property
149+
def history_startPos(self):
150+
return self._ps.startPos
151+
152+
@history_startPos.setter
153+
def history_startPos(self, value):
154+
self._ps.startPos = value
155+
156+
@property
157+
def browsing_station_service(self):
158+
return self._ps.browsing_station_service
159+
160+
@browsing_station_service.setter
161+
def browsing_station_service(self, value):
162+
self._ps.browsing_station_service = value
141163

142164
@property
143165
def stations_file(self):
@@ -157,7 +179,7 @@ def stations_filename_only(self, value):
157179

158180
@property
159181
def stations_filename_only_no_extension(self):
160-
return self._ps.stations_filename_only
182+
return self._ps.stations_filename_only_no_extension
161183

162184
@stations_filename_only_no_extension.setter
163185
def stations_filename_only_no_extension(self, value):
@@ -172,7 +194,7 @@ def can_go_back_in_time(self, value):
172194
raise ValueError('property is read only')
173195

174196
def url(self, id_in_list):
175-
if self._browsing_station_service:
197+
if self._ps.browsing_station_service:
176198
# TODO get browser url
177199
return self._online_browser.url(id_in_list)
178200
#return self.stations[id_in_list][1].strip()
@@ -511,17 +533,24 @@ def _set_playlist_elements(self, a_playlist, a_title=''):
511533

512534
def add_to_playlist_history(self, stations_file='',
513535
stations_filename_only='',
514-
stations_filename_only_no_extension=''):
536+
stations_filename_only_no_extension='',
537+
startPos=0, selection=0, playing=-1,
538+
browsing_station_service=False):
515539
self._ps.add(stations_file,
516540
stations_filename_only,
517-
stations_filename_only_no_extension)
541+
stations_filename_only_no_extension,
542+
startPos, selection, playing,
543+
browsing_station_service)
518544

519545
def reset_playlist_history(self):
520546
self._ps.reset()
521547

522548
def remove_from_playlist_history(self):
523549
return self._ps.pop()
524550

551+
def copy_playlist_history(self):
552+
return self._ps.copy()
553+
525554
def _bytes_to_human(self, B):
526555
''' Return the given bytes as a human friendly KB, MB, GB, or TB string '''
527556
KB = float(1024)
@@ -713,10 +742,11 @@ def open_browser(self, url):
713742
self.number_of_stations = len(self.stations)
714743
self.dirty_playlist = False
715744

716-
def save_station_position(self, startPos, selection):
745+
def save_station_position(self, startPos, selection, playing):
717746
logger.error('DE startPos = {0}, selection = {1}'.format(startPos, selection))
718747
self._ps.startPos = startPos
719748
self._ps.selection = selection
749+
self._ps.playing = playing
720750
logger.error('\n\nDE {}\n\n'.format(self._ps._p))
721751

722752
class PyRadioConfig(PyRadioStations):
@@ -892,7 +922,7 @@ def _check_config_file(self, usr):
892922
copyfile(package_config_file, user_config_file)
893923

894924
def internal_header_height(self):
895-
if self._browsing_station_service:
925+
if self.browsing_station_service:
896926
return self.online_browser.internal_header_height
897927
else:
898928
return 0
@@ -1107,15 +1137,32 @@ class PyRadioPlaylistStack(object):
11071137
_p = []
11081138

11091139
_id = {'stations_file': 0,
1140+
'path': 0,
11101141
'stations_filename_only': 1,
1142+
'filename': 1,
11111143
'stations_filename_only_no_extension': 2,
1144+
'title': 2,
11121145
'startPos': 3,
11131146
'selection': 4,
1147+
'playing' : 5,
1148+
'browsing_station_service': 6,
11141149
}
11151150

11161151
def __init__(self):
11171152
pass
11181153

1154+
@property
1155+
def browsing_station_service(self):
1156+
if self._p:
1157+
return self._p[-1][self._id['browsing_station_service']]
1158+
else:
1159+
return False
1160+
1161+
@browsing_station_service.setter
1162+
def browsing_station_service(self, value):
1163+
if self._p:
1164+
self._p[-1][self._id['browsing_station_service']] = value
1165+
11191166
@property
11201167
def stations_file(self):
11211168
if self._p:
@@ -1157,7 +1204,7 @@ def selection(self):
11571204
if self._p:
11581205
return self._p[-1][self._id['selection']]
11591206
else:
1160-
return ''
1207+
return 0
11611208

11621209
@selection.setter
11631210
def selection(self, value):
@@ -1169,13 +1216,25 @@ def startPos(self):
11691216
if self._p:
11701217
return self._p[-1][self._id['startPos']]
11711218
else:
1172-
return ''
1219+
return 0
11731220

11741221
@startPos.setter
11751222
def startPos(self, value):
11761223
if self._p:
11771224
self._p[-1][self._id['startPos']] = value
11781225

1226+
@property
1227+
def playing(self):
1228+
if self._p:
1229+
return self._p[-1][self._id['playing']]
1230+
else:
1231+
return -1
1232+
1233+
@playing.setter
1234+
def playing(self, value):
1235+
if self._p:
1236+
self._p[-1][self._id['playing']] = value
1237+
11791238
def remove_duplicates(self):
11801239
if len(self._p) > 1:
11811240
val1 = self._p[-1][self._id['stations_filename_only']]
@@ -1189,7 +1248,9 @@ def remove_duplicates(self):
11891248

11901249
def add(self, stations_file='',
11911250
stations_filename_only='',
1192-
stations_filename_only_no_extension=''):
1251+
stations_filename_only_no_extension='',
1252+
startPos=0, selection=0, playing=-1,
1253+
browsing_station_service=False):
11931254
if len(self._p) > 1 and stations_file:
11941255
if self._p[-2][self._id['stations_file']] == stations_file:
11951256
if logger.isEnabledFor(logging.DEBUG):
@@ -1198,7 +1259,8 @@ def add(self, stations_file='',
11981259
self._p.append([stations_file,
11991260
stations_filename_only,
12001261
stations_filename_only_no_extension,
1201-
0, 0])
1262+
startPos, selection, playing,
1263+
browsing_station_service])
12021264

12031265
def get_member(self, member):
12041266
if member in self._id.keys():
@@ -1208,13 +1270,22 @@ def get_member(self, member):
12081270

12091271
def pop(self):
12101272
if len(self._p) > 1:
1211-
self._p.pop()
1212-
return True
1273+
return self._p.pop()
12131274
else:
12141275
if logger.isEnabledFor(logging.DEBUG):
12151276
logger.debug('Refusing to remove first entry')
1216-
return False
1277+
return self._p[0]
1278+
1279+
def set(self, a_list):
1280+
if a_list:
1281+
self._p = a_list[:]
1282+
else:
1283+
raise ValueError('playlist history cannot be empty')
12171284

12181285
def reset(self):
12191286
if self._p:
1220-
iself._p = self._p[:1]
1287+
self._p = self._p[:1]
1288+
1289+
def copy(self):
1290+
return self._p[:]
1291+

pyradio/player.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def save_volume(self):
6262
def _do_save_volume(self, config_string):
6363
if not self.config_files:
6464
if logger.isEnabledFor(logging.DEBUG):
65-
logger.debug('Volume not daved!!! (config file not found!!!)')
65+
logger.debug('Volume not saved!!! (config file not found!!!)')
6666
return 'Volume not saved!!!'
6767
ret_strings = ('Volume: already saved...',
6868
'Volume: {}% saved',
@@ -617,6 +617,8 @@ class MpPlayer(Player):
617617
config_files[0] = 'C:\\mplayer\mplayer\\config'
618618
elif os.path.exists(os.path.join(os.getenv('USERPROFILE'), "mplayer", "mplayer.exe")):
619619
config_files[0] = os.path.join(os.getenv('USERPROFILE'), "mplayer", "mplayer", "config")
620+
elif os.path.exists(os.path.join(os.getenv('APPDATA'), "pyradio", "mplayer", "mplayer.exe")):
621+
config_files[0] = os.path.join(os.getenv('APPDATA'), "pyradio", "mplayer", "mplayer", "config")
620622
else:
621623
config_files = []
622624
else:

0 commit comments

Comments
 (0)