]> git.parisson.com Git - deefuzzer.git/commitdiff
Get a good shuffle mode
authorGuillaume Pellerin <yomguy@parisson.com>
Sun, 9 Sep 2007 21:29:03 +0000 (21:29 +0000)
committerGuillaume Pellerin <yomguy@parisson.com>
Sun, 9 Sep 2007 21:29:03 +0000 (21:29 +0000)
INSTALL
README
d-fuzz.py
myfuzz.xml
tools.py

diff --git a/INSTALL b/INSTALL
index a3c9349eb3d8bd7b70d50baf2a70fb5b65caec98..105571e8debde416976e54095594a4ed2cf6d8a4 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -7,4 +7,9 @@
 # you should have received as part of this distribution. The terms
 # are also available at http://svn.parisson.org/d-fuzz/DFuzzLicense.
 #
-# Author: Guillaume Pellerin <pellerin@parisson.com>
\ No newline at end of file
+# Author: Guillaume Pellerin <pellerin@parisson.com>
+
+ depends : python, python-xml, shout-python, libshout3, icecast2
+ recommends : python-mutagen
+ provides : shout-python
\ No newline at end of file
diff --git a/README b/README
index 5efba7ccb5fc71e9973805b4e0b77349f4060008..58db827bea4ac239679d181b5bf4e53d1f0b4666 100644 (file)
--- a/README
+++ b/README
@@ -13,7 +13,7 @@ It is neccessary to provide a config file which sets all needed parameters (see
 
 
 # 2. Installation
-# ===============
+# ===============
 
 see INSTALL
 
index 2c0761995fa4ec7ee9912d04d0d723257e383df5..d9ed714353df6650eb8f012c2fc50e4dad74e63b 100755 (executable)
--- a/d-fuzz.py
+++ b/d-fuzz.py
@@ -14,8 +14,8 @@ import os
 import sys
 import shout
 import string
+import random
 import subprocess
-from tools import *
 from xmltodict import xmltodict
 from mutagen.oggvorbis import OggVorbis
 
@@ -45,7 +45,7 @@ class DFuzz:
         self.conf = []
         self.id = 999999
         self.buffer_size = 0xFFFF
-       self.rand = []
+        self.rand_list = []
         
     def prog_info(self):
         return """
@@ -85,32 +85,35 @@ class DFuzz:
                 file_list.append(root + os.sep + file)
         return file_list
 
-    def get_next_media(self, playlist):
+    def get_next_media_lin(self, playlist):
         lp = len(playlist)
-        if self.id >= (lp - 1) :
+        if self.id >= (lp - 1):
             playlist = self.get_playlist()
             self.id = 0
         else:
             self.id = self.id + 1
-        #print self.id
         return playlist, playlist[self.id]
     
-    def get_random_media(self, playlist):
+    def get_next_media_rand(self, playlist):
         lp = len(playlist)
-        if self.id > lp:
-            self.rand = randrange(0,lp)
+        if self.id >= (lp - 1):
+            playlist = self.get_playlist()
+            lp = len(playlist)    
+            self.rand_list = range(0,lp)
+            random.shuffle(self.rand_list)
+            print self.rand_list
             self.id = 0
         else:
             self.id = self.id + 1
-        #print self.id
-        return playlist, playlist[self.rand[self.id]]
+        index = self.rand_list[self.id]
+        print str(self.id) +':'+ str(index)
+        return playlist, playlist[index]
 
     def core_process(self, command, buffer_size):
         """Apply command and stream data through a generator. 
         From Telemeta..."""
         
         __chunk = 0
-        #file_out = open(dest,'w')
 
         try:
             proc = subprocess.Popen(command,
@@ -121,8 +124,7 @@ class DFuzz:
                     close_fds = True)
         except:
             raise IOError('Command failure:', command, proc)
-            #pass
-        
+
         # Core processing
         while True:
             __chunk = proc.stdout.read(buffer_size)
@@ -132,11 +134,8 @@ class DFuzz:
             if len(__chunk) == 0:
                 break
             yield __chunk
-            #file_out.write(__chunk)
-
-        #file_out.close()
 
-    def stream(self, conf_file): 
+    def stream(self, conf_file):
         self.conf_file = conf_file
         self.get_conf_dict()
 
@@ -151,7 +150,7 @@ class DFuzz:
         # Media
         self.media_dir = station['media']['dir']
         format = station['media']['format']
-       mode_random = station['media']['random']
+        mode_shuffle = int(station['media']['shuffle'])
         s.format = format
 
         # Server
@@ -180,22 +179,26 @@ class DFuzz:
         print playlist
                     
         s.open()
+        
         while True:
             if lp == 0:
-                break 
-            if mode_random == 1:
-               playlist, media = self.get_random_media(playlist)
+                break
+            
+            if mode_shuffle == 1:
+                playlist, media = self.get_next_media_rand(playlist)
             else:
-                playlist, media = self.get_next_media(playlist)
-            print 'opening file : %s' % media
+                playlist, media = self.get_next_media_lin(playlist)
+                
             file_name = string.replace(media, self.media_dir + os.sep, '')
-            print 'streaming file : %s' % file_name
+            print 'Streaming file : %s' % file_name
             s.set_metadata({'song': file_name})
             command = 'cat "%s"' % media
             stream = self.core_process(command, self.buffer_size)
+
             for chunk in stream:
                 s.send(chunk)
                 s.sync()
+                
         s.close()
 
 
index 2865bec3edc1c7b1fa723f28c79a0347d65cfb22..5056993664986fad14d69397411e92f8e6b733ee 100644 (file)
         <public>1</public>
     </server>
     <media>
-        <dir>/mnt/data/Music/oasis</dir>
+        <dir>/home/momo/data/data1/samples2/groovemasters/Groovemasters Drums/mp3</dir>
         <format>mp3</format>
         <bitrate>192</bitrate>
         <ogg_quality>7</ogg_quality>
         <samplerate>44100</samplerate>
         <voices>2</voices>
-       <random>1</random>
+        <shuffle>1</shuffle>
     </media>
 </station>
 
index 74d191a3ae0269e7aa4cc6d5f4e5ea8571cd7c5f..98c038b93fd34523ebec7a6a6a8cf8732686114b 100755 (executable)
--- a/tools.py
+++ b/tools.py
@@ -2,11 +2,6 @@
 
 import sys, os, random
 
-#Playdir='/home/cellar/Cellar_playlist/'
-#IndexFile='/home/cellar/stream/d-fuzz_1_index.txt'
-#RandomIndexListFile='/home/cellar/stream/d-fuzz_1_random_index_list.txt'
-#PlaylistLengthOrigFile='/home/cellar/stream/d-fuzz_1_playlist_length.txt'
-
 def randrange(start, stop):
        values = range(start, stop)
        random.shuffle(values)