]> git.parisson.com Git - deefuzzer.git/commitdiff
Changes based on ChoiZ's mode_playing branch
authorachbed <github@achbed.org>
Tue, 20 Jan 2015 00:16:59 +0000 (18:16 -0600)
committerachbed <github@achbed.org>
Tue, 20 Jan 2015 00:16:59 +0000 (18:16 -0600)
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 <github@achbed.org>
deefuzzer/core.py
deefuzzer/station.py
example/deefuzzer.json
example/deefuzzer.xml
example/deefuzzer.yaml
example/deefuzzer_doc.xml
example/stationconfig_doc.xml

index 817bde4ff050417350a46e95c58d440ae8c6b674..e394c924f70f11af2c1c2cbf21dbb6016984310b 100644 (file)
@@ -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):
index c6c92b90c93c4be54664110f91f9ed9be5dc39e2..566b8e5822053d81213df5531e2732732689fd39 100644 (file)
@@ -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
 
index 7f53f8629dbe0e51ec2d390ee32f76e8231a6dfa..24a71bb07f27822a9a112c766ab45737b4f7a03d 100644 (file)
@@ -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,
index 9cadbb14d8e45684607f63c9ffa9a433e54e1182..6c16692ac4e27a1361148f29749e24ed6e79f340 100644 (file)
@@ -31,9 +31,8 @@
         </jingles>
         <media>
             <bitrate>96</bitrate>
-            <dir>/path/to/mp3/</dir>
+            <source>/path/to/mp3/or/m3u</source>
             <format>mp3</format>
-            <m3u>/path/to/m3u_file</m3u>
             <ogg_quality>4</ogg_quality>
             <samplerate>48000</samplerate>
             <shuffle>0</shuffle>
index 366cb7f018da5ff39fba7c2c03425374d4d8ed42..ffbe47b5be66dbc17b3c296a7704894332a7bd17 100644 (file)
@@ -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,
index b51348ae91effa07576f88071b67eb0297945883..93dcc3e2e79b50a64bd84fdb9a7eecb3d7c4ab31 100644 (file)
@@ -63,7 +63,8 @@
             <!-- A path to the directory containing jingles media files.
                 The files have to be of the same type of the main media files. -->
             <dir>/path/to/jingles</dir>
-            <!-- If '1', some media will be played between each main track of the playlist. '0' does nothing. -->
+            <!-- If '1', some media will be played between each main track of the 
+                playlist. '0' does nothing. -->
             <mode>0</mode>
             <!-- If '1', the jingle playlist will be randomized. '0' for alphanumeric order -->
             <shuffle>1</shuffle>
         <media>
             <!-- The mean bitrate of the media -->
             <bitrate>96</bitrate>
-            <!-- The path to the directory containing all the media. It will be analyzed recursively. -->
-            <dir>/path/to/mp3/</dir>
+            <!-- The <m3u> option is depreciated.  Please use the newer <source> option. -->
+            <m3u>/path/to/m3u_file</m3u>
+            <!-- The <dir> option is depreciated.  Please use the newer <source> option.
+                  This option overrides the <m3u> option if both are specified. -->
+            <dir>/path/to/mp3_folder</dir>
+            <!-- The path to the folder containing audio files, or the M3U playlist file to
+                  use as source audio for this  station.  This option overrides both the <dir>
+                  and <m3u> depreciated options if they are specified. -->
+            <source>/path/to/m3u_file_or_folder</source>
             <!-- The audio format of the media. Can be 'mp3' or 'ogg' -->
             <format>mp3</format>
-            <!-- You can also give a M3U playlist file -->
-            <m3u>/path/to/m3u_file</m3u>
             <!-- The ogg quality of the ogg vorbis media -->
             <ogg_quality>4</ogg_quality>
             <!-- The sample rate of the media -->
index 740b3c03101cf6ed14198f8b94636f403c29ce1f..17cec3b1545de51e293372a2d676f46e5801208a 100644 (file)
@@ -16,9 +16,8 @@
     </jingles>
     <media>
         <bitrate>96</bitrate>
-        <dir>/path/to/mp3/</dir>
+        <source>/path/to/mp3/or/m3u</source>
         <format>mp3</format>
-        <m3u>/path/to/m3u_file</m3u>
         <ogg_quality>4</ogg_quality>
         <samplerate>48000</samplerate>
         <shuffle>0</shuffle>