From 871bf9da94b821d2662e61084acb93175c6ca9d4 Mon Sep 17 00:00:00 2001 From: achbed Date: Mon, 19 Jan 2015 18:16:59 -0600 Subject: [PATCH] Changes based on ChoiZ's mode_playing branch Station: media.dir now overrides media.m3u if both are specified and non-blank Station: Noted media.m3u and media.dir options as depreciated (uses them if present for smooth upgrade path) Station: Combine media.m3u and media.dir options into one new media.source option Station: media.source is now checked to see if it's a file or folder at load time, and playlist or folder list mode is selected automatically Core: Updated to reflect new source setting when using station autocreation Signed-off-by: achbed --- deefuzzer/core.py | 2 +- deefuzzer/station.py | 73 +++++++++++++++++++++++------------ example/deefuzzer.json | 3 +- example/deefuzzer.xml | 3 +- example/deefuzzer.yaml | 3 +- example/deefuzzer_doc.xml | 16 +++++--- example/stationconfig_doc.xml | 3 +- 7 files changed, 64 insertions(+), 39 deletions(-) diff --git a/deefuzzer/core.py b/deefuzzer/core.py index 817bde4..e394c92 100644 --- a/deefuzzer/core.py +++ b/deefuzzer/core.py @@ -204,7 +204,7 @@ class DeeFuzzer(Thread): s[i] = replace_all(options[i], d) if not 'media' in s.keys(): s['media'] = {} - s['media']['dir'] = folder + s['media']['source'] = folder self.add_station(s) def load_stations_fromconfig(self, folder): diff --git a/deefuzzer/station.py b/deefuzzer/station.py index c6c92b9..566b8e5 100644 --- a/deefuzzer/station.py +++ b/deefuzzer/station.py @@ -65,6 +65,7 @@ class Station(Thread): start_time = time.time() server_ping = False playlist = [] + media_source = None lp = 1 player_mode = 1 osc_control_mode = 0 @@ -94,7 +95,7 @@ class Station(Thread): self.logqueue = logqueue self.m3u = m3u - if 'station_statusfile' in station: + if 'station_statusfile' in self.station: self.statusfile = station['station_statusfile'] try: if os.path.exists(self.statusfile): @@ -108,16 +109,24 @@ class Station(Thread): self.station_dir = self.station['station_dir'] # Media - self.media_dir = self.station['media']['dir'] + if 'm3u' in self.station['media'].keys(): + if not self.station['media']['m3u'].strip() == '': + self.media_source = self.station['media']['m3u'] + + if 'dir' in self.station['media'].keys(): + if not self.station['media']['dir'].strip() == '': + self.media_source = self.station['media']['dir'] + + if 'source' in self.station['media'].keys(): + if not self.station['media']['source'].strip() == '': + self.media_source = self.station['media']['source'] + self.media_format = self.station['media']['format'] self.shuffle_mode = int(self.station['media']['shuffle']) self.bitrate = int(self.station['media']['bitrate']) self.ogg_quality = int(self.station['media']['ogg_quality']) self.samplerate = int(self.station['media']['samplerate']) self.voices = int(self.station['media']['voices']) - self.m3u_playlist_file = [] - if 'm3u' in self.station['media'].keys(): - self.m3u_playlist_file = self.station['media']['m3u'] # Server if 'mountpoint' in self.station['server'].keys(): @@ -326,6 +335,9 @@ class Station(Thread): self.twitter = Twitter(self.twitter_key, self.twitter_secret) self.twitter_mode = value message = "received OSC message '%s' with arguments '%d'" % (path, value) + + # IMPROVEMENT: The URL paths should be configurable because they're + # server-implementation specific self.m3u_url = self.channel.url + '/m3u/' + self.m3u.split(os.sep)[-1] self.feeds_url = self.channel.url + '/rss/' + self.feeds_playlist_file.split(os.sep)[-1] self._info(message) @@ -382,27 +394,38 @@ class Station(Thread): def get_playlist(self): file_list = [] - if not self.m3u_playlist_file: - for root, dirs, files in os.walk(self.media_dir): - for file in files: - s = file.split('.') - ext = s[len(s)-1] - if ext.lower() == self.channel.format and not os.sep+'.' in file: - file_list.append(root + os.sep + file) - file_list.sort() - else: - self.q.get(1) - try: - f = open(self.m3u_playlist_file, 'r') + + try: + if os.path.isdir(self.media_source): + self.q.get(1) try: - for path in f.readlines(): - if '#' != path[0]: - file_list.append(path[:-1]) + for root, dirs, files in os.walk(self.media_source): + for file in files: + s = file.split('.') + ext = s[len(s)-1] + if ext.lower() == self.channel.format and not os.sep+'.' in file: + file_list.append(root + os.sep + file) + file_list.sort() except: - f.close() - except: - pass - self.q.task_done() + pass + self.q.task_done() + + if os.path.isfile(self.media_source): + self.q.get(1) + try: + f = open(self.media_source, 'r') + try: + for path in f.readlines(): + if '#' != path[0]: + file_list.append(path[:-1]) + except: + f.close() + except: + pass + self.q.task_done() + except: + pass + return file_list def get_jingles(self): @@ -511,7 +534,7 @@ class Station(Thread): self.q.task_done() return media else: - mess = 'No media in media_dir!' + mess = 'No media in source!' self._err(mess) self.run_mode = 0 diff --git a/example/deefuzzer.json b/example/deefuzzer.json index 7f53f86..24a71bb 100644 --- a/example/deefuzzer.json +++ b/example/deefuzzer.json @@ -43,9 +43,8 @@ }, "media": { "bitrate": 96, - "dir": "/path/to/mp3/", + "source": "/path/to/mp3/or/m3u", "format": "mp3", - "m3u": "/path/to/m3u_file", "ogg_quality": 4, "samplerate": 48000, "shuffle": 0, diff --git a/example/deefuzzer.xml b/example/deefuzzer.xml index 9cadbb1..6c16692 100644 --- a/example/deefuzzer.xml +++ b/example/deefuzzer.xml @@ -31,9 +31,8 @@ 96 - /path/to/mp3/ + /path/to/mp3/or/m3u mp3 - /path/to/m3u_file 4 48000 0 diff --git a/example/deefuzzer.yaml b/example/deefuzzer.yaml index 366cb7f..ffbe47b 100644 --- a/example/deefuzzer.yaml +++ b/example/deefuzzer.yaml @@ -25,9 +25,8 @@ deefuzzer: shuffle: 1} media: {bitrate: 96, - dir: /path/to/mp3/, + source: /path/to/mp3/or/m3u, format: mp3, - m3u: /path/to/m3u_file, ogg_quality: 4, samplerate: 48000, shuffle: 0, diff --git a/example/deefuzzer_doc.xml b/example/deefuzzer_doc.xml index b51348a..93dcc3e 100644 --- a/example/deefuzzer_doc.xml +++ b/example/deefuzzer_doc.xml @@ -63,7 +63,8 @@ /path/to/jingles - + 0 1 @@ -71,12 +72,17 @@ 96 - - /path/to/mp3/ + + /path/to/m3u_file + + /path/to/mp3_folder + + /path/to/m3u_file_or_folder mp3 - - /path/to/m3u_file 4 diff --git a/example/stationconfig_doc.xml b/example/stationconfig_doc.xml index 740b3c0..17cec3b 100644 --- a/example/stationconfig_doc.xml +++ b/example/stationconfig_doc.xml @@ -16,9 +16,8 @@ 96 - /path/to/mp3/ + /path/to/mp3/or/m3u mp3 - /path/to/m3u_file 4 48000 0 -- 2.39.5