From: Guillaume Pellerin Date: Mon, 14 Dec 2009 00:41:22 +0000 (+0000) Subject: add osc controller and next_media callback to skip current media X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=77f938108c38f31000cf130d4f5bef8e31adfb8a;p=deefuzzer.git add osc controller and next_media callback to skip current media --- diff --git a/deefuzzer.py b/deefuzzer.py index e071e80..a8deae8 100755 --- a/deefuzzer.py +++ b/deefuzzer.py @@ -46,8 +46,6 @@ import Queue import shout import subprocess import platform -import twitter -import tinyurl from threading import Thread from tools import * @@ -137,9 +135,6 @@ class DeeFuzzer(Thread): self.stations = [] self.logger.write('Number of stations : ' + str(self.nb_stations)) - # Create M3U playlist - self.logger.write('Writing M3U file to : ' + self.m3u) - def get_conf_dict(self): confile = open(self.conf_file,'r') conf_xml = confile.read() @@ -160,10 +155,11 @@ class DeeFuzzer(Thread): m3u.write(url) i += 1 m3u.close() + self.logger.write('Writing M3U file to : ' + self.m3u) + def run(self): # Create a Queue - # Not too much, otherwise, you will get memory leaks ! q = Queue.Queue(1) for i in range(0,self.nb_stations): @@ -273,6 +269,7 @@ class Station(Thread): if self.twitter_mode == '1': self.twitter = Twitter(self.twitter_user, self.twitter_pass) self.twitter_tags = self.station['twitter']['tags'].split(' ') + import tinyurl self.tinyurl = tinyurl.create_one(self.channel.url + '/m3u/' + self.m3u.split(os.sep)[-1]) self.jingles_mode = '0' @@ -285,13 +282,28 @@ class Station(Thread): self.jingles_length = len(self.jingles_list) self.jingle_id = 0 + self.osc_control = '0' + if 'control' in self.station: + self.osc_control_mode = self.station['control']['mode'] + self.osc_port = self.station['control']['port'] + if self.osc_control_mode =='1': + self.osc_controller = OSCController(self.osc_port) + self.osc_controller.add_method('/media/next', 'i', self.media_next_callback) + self.osc_controller.start() + + def media_next_callback(self, path, value): + value = value[0] + self.osc_next_media = value + message = "Received OSC message '%s' with arguments '%d'" % (path, value) + self.logger.write(message) + def get_playlist(self): file_list = [] 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 '/.' in file: + if ext.lower() == self.channel.format and not os.sep+'.' in file: file_list.append(root + os.sep + file) file_list.sort() return file_list @@ -302,7 +314,7 @@ class Station(Thread): for file in files: s = file.split('.') ext = s[len(s)-1] - if ext.lower() == self.channel.format and not '/.' in file: + if ext.lower() == self.channel.format and not os.sep+'.' in file: file_list.append(root + os.sep + file) file_list.sort() return file_list @@ -457,6 +469,7 @@ class Station(Thread): self.logger.write('Error : Station ' + self.short_name + ' have no media to stream !') break media = self.get_next_media() + self.osc_next_media = 0 self.counter += 1 q.task_done() @@ -492,6 +505,8 @@ class Station(Thread): try: self.channel.send(__chunk) self.channel.sync() + if self.osc_next_media != 0: + break # self.logger.write('Station delay (ms) ' + self.short_name + ' : ' + str(self.channel.delay())) except: self.logger.write('ERROR : Station ' + self.short_name + ' : could not send the buffer... ') @@ -553,7 +568,7 @@ class Player(Thread): m.close() def read_slow(self): - """Read a bigger part of the media and stream the little parts of data through a generator + """Read a bigger part of the media and stream the little parts of the data through a generator """ media = self.media @@ -578,10 +593,9 @@ class Player(Thread): class Twitter: - """Post a message to Twitter""" - + def __init__(self, username, password): - #Thread.__init__(self) + import twitter self.username = username self.password = password self.api = twitter.Api(username=self.username, password=self.password) @@ -593,6 +607,28 @@ class Twitter: pass +class OSCController(Thread): + + def __init__(self, port): + Thread.__init__(self) + import liblo + self.port = port + try: + self.server = liblo.Server(self.port) + except liblo.ServerError, err: + self.logger.write(str(err)) + + def add_method(self, path, type, method): + self.server.add_method(path, type, method) + + def server(self): + return self.server + + def run(self): + while True: + self.server.recv(1000) + + def main(): if len(sys.argv) == 2: d = DeeFuzzer(sys.argv[1]) diff --git a/example/myfuzz.xml b/example/myfuzz.xml index 676e501..eb4eda2 100644 --- a/example/myfuzz.xml +++ b/example/myfuzz.xml @@ -1,6 +1,6 @@ /tmp/deefuzz.log - /var/www/m3u/yomguy_playlist.m3u + /var/www/m3u/mystation.m3u My_Station_1 @@ -39,6 +39,10 @@ /path/to/jingles 1 + + 1 + 1234 + diff --git a/tools/osc_next.py b/tools/osc_next.py new file mode 100644 index 0000000..f57fe6c --- /dev/null +++ b/tools/osc_next.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +import liblo, sys + +# send all messages to port 1234 on the local machine +try: + target = liblo.Address(1234) +except liblo.AddressError, err: + print str(err) + sys.exit() + +# send message "/foo/message1" with int, float and string arguments +liblo.send(target, "/media/next", 1)