From: Guillaume Pellerin Date: Sun, 9 Sep 2007 21:29:03 +0000 (+0000) Subject: Get a good shuffle mode X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=259dfb7e26f50f4a2edeca13b4e11a048db29fc6;p=deefuzzer.git Get a good shuffle mode --- diff --git a/INSTALL b/INSTALL index a3c9349..105571e 100644 --- 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 \ No newline at end of file +# Author: Guillaume Pellerin + + 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 5efba7c..58db827 100644 --- 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 diff --git a/d-fuzz.py b/d-fuzz.py index 2c07619..d9ed714 100755 --- 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() diff --git a/myfuzz.xml b/myfuzz.xml index 2865bec..5056993 100644 --- a/myfuzz.xml +++ b/myfuzz.xml @@ -15,13 +15,13 @@ 1 - /mnt/data/Music/oasis + /home/momo/data/data1/samples2/groovemasters/Groovemasters Drums/mp3 mp3 192 7 44100 2 - 1 + 1 diff --git a/tools.py b/tools.py index 74d191a..98c038b 100755 --- 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)