From: Guillaume Pellerin Date: Tue, 22 Dec 2009 12:07:36 +0000 (+0000) Subject: fix twitter management X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=85310b8eb244fc0be1862217ec22aa66b72a5500;p=deefuzzer.git fix twitter management --- diff --git a/deefuzzer.py b/deefuzzer.py index 1b4d6a9..c6f4177 100755 --- a/deefuzzer.py +++ b/deefuzzer.py @@ -45,10 +45,11 @@ import random import Queue import shout import platform +import tinyurl from threading import Thread from tools import * -version = '0.3.6' +version = '0.4' year = datetime.datetime.now().strftime("%Y") platform_system = platform.system() @@ -257,6 +258,23 @@ class Station(Thread): if not os.path.exists(self.metadata_dir): os.makedirs(self.metadata_dir) + # A jingle between each media + self.jingles_mode = 0 + if 'jingles' in self.station: + self.jingles_mode = int(self.station['jingles']['mode']) + self.jingles_shuffle = self.station['jingles']['shuffle'] + self.jingles_dir = self.station['jingles']['dir'] + if self.jingles_mode == 1: + self.jingles_list = self.get_jingles() + self.jingles_length = len(self.jingles_list) + self.jingle_id = 0 + + # Relay + self.relay_mode = 0 + if 'relay' in self.station: + self.relay_mode = int(self.station['relay']['mode']) + self.relay_url = self.station['relay']['url'] + # OSC self.osc_control_mode = 0 if 'control' in self.station: @@ -268,37 +286,18 @@ class Station(Thread): # OSC paths and callbacks self.osc_controller.add_method('/media/next', 'i', self.media_next_callback) self.osc_controller.add_method('/media/relay', 'i', self.relay_callback) - self.osc_controller.add_method('/mode/twitter', 'i', self.twitter_callback) - self.osc_controller.add_method('/mode/jingles', 'i', self.jingles_callback) + self.osc_controller.add_method('/twitter', 'i', self.twitter_callback) + self.osc_controller.add_method('/jingles', 'i', self.jingles_callback) # Twitter self.twitter_mode = 0 + self.tinyurl = tinyurl.create_one(self.channel.url + '/m3u/' + self.m3u.split(os.sep)[-1]) if 'twitter' in self.station: self.twitter_mode = int(self.station['twitter']['mode']) self.twitter_user = self.station['twitter']['user'] self.twitter_pass = self.station['twitter']['pass'] - 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]) - - # A jingle between each media - self.jingles_mode = 0 - if 'jingles' in self.station: - self.jingles_mode = int(self.station['jingles']['mode']) - self.jingles_shuffle = self.station['jingles']['shuffle'] - self.jingles_dir = self.station['jingles']['dir'] - if self.jingles_mode == 1: - self.jingles_list = self.get_jingles() - self.jingles_length = len(self.jingles_list) - self.jingle_id = 0 - - # Relay - self.relay_mode = 0 - if 'relay' in self.station: - self.relay_mode = int(self.station['relay']['mode']) - self.relay_url = self.station['relay']['url'] + self.twitter_tags = self.station['twitter']['tags'].split(' ') + self.twitter = Twitter(self.twitter_user, self.twitter_pass) # The station's player self.player = Player() @@ -385,8 +384,9 @@ class Station(Thread): song = artist + ' : ' + title song = song.encode('utf-8') artist = artist.encode('utf-8') - message = 'New track ! %s #%s #%s' % (song.replace('_', ' '), artist.replace(' ', ''), self.short_name) - self.update_twitter(message) + if self.twitter_mode == 1: + message = 'New track ! %s #%s #%s' % (song.replace('_', ' '), artist.replace(' ', ''), self.short_name) + self.update_twitter(message) if self.mode_shuffle == 1: # Shake it, Fuzz it ! @@ -396,7 +396,7 @@ class Station(Thread): ' : generating new playlist (' + str(self.lp) + ' tracks)') self.update_rss(self.media_to_objs(self.playlist), self.rss_playlist_file, '(playlist)') - if self.jingles_mode == '1' and (self.counter % 2) == 0 and not self.jingles_length == 0: + if self.jingles_mode == 1 and (self.counter % 2) == 0 and not self.jingles_length == 0: media = self.jingles_list[self.jingle_id] self.jingle_id = (self.jingle_id + 1) % self.jingles_length else: @@ -487,13 +487,12 @@ class Station(Thread): f.close() def update_twitter(self, message): - if self.twitter_mode == '1': - tags = '#' + ' #'.join(self.twitter_tags) - message = message + ' ' + tags - message = message[:113] + ' ' + self.tinyurl - message = message.decode('utf8') - self.logger.write('Twitting : "' + message + '"') - self.twitter.post(message) + tags = '#' + ' #'.join(self.twitter_tags) + message = message + ' ' + tags + message = message[:113] + ' ' + self.tinyurl + message = message.decode('utf8') + self.logger.write('Twitting : "' + message + '"') + self.twitter.post(message) def run(self): while True: @@ -528,13 +527,13 @@ class Station(Thread): self.update_rss(self.current_media_obj, self.metadata_file, '') self.channel.set_metadata({'song': self.song, 'charset': 'utf8',}) self.update_rss(self.current_media_obj, self.rss_current_file, '(currently playing)') - self.logger.write('DeeFuzzing this file on %s : id = %s, name = %s' \ + self.logger.write('Deefuzzing this file on %s : id = %s, name = %s' \ % (self.short_name, self.id, self.current_media_obj[0].file_name)) self.player.set_media(self.media) self.stream = self.player.file_read_slow() - if not (self.jingles_mode == 1 and (self.counter % 2) == 1): - message = 'Now playing: %s #%s #%s' % (self.song.replace('_', ' '), self.artist.replace(' ', ''), self.short_name) + if (not (self.jingles_mode == 1 and (self.counter % 2) == 1)) and self.twitter_mode == 1: + message = 'Now playing : %s #%s #%s' % (self.song.replace('_', ' '), self.artist.replace(' ', ''), self.short_name) self.update_twitter(message) self.q.task_done() diff --git a/tools/__init__.py b/tools/__init__.py index f103ac3..d2e383d 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -6,5 +6,5 @@ from ogg import * from logger import * from player import * from osc import * -from twitter import * +from twitt import * from relay import * diff --git a/tools/osc_twitter_start.py b/tools/osc_twitter_start.py new file mode 100644 index 0000000..c298be6 --- /dev/null +++ b/tools/osc_twitter_start.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +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, "/twitter", 1) diff --git a/tools/osc_twitter_stop.py b/tools/osc_twitter_stop.py new file mode 100644 index 0000000..3470fcc --- /dev/null +++ b/tools/osc_twitter_stop.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +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, "/twitter", 0) diff --git a/tools/twitt.py b/tools/twitt.py new file mode 100644 index 0000000..a03907c --- /dev/null +++ b/tools/twitt.py @@ -0,0 +1,50 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2006-2009 Guillaume Pellerin + +# + +# This software is a computer program whose purpose is to stream audio +# and video data through icecast2 servers. + +# This software is governed by the CeCILL license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL +# license as circulated by CEA, CNRS and INRIA at the following URL +# "http://www.cecill.info". + +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. + +# In this respect, the user's attention is drawn to the risks associated +# with loading, using, modifying and/or developing or reproducing the +# software by the user in light of its specific status of free software, +# that may mean that it is complicated to manipulate, and that also +# therefore means that it is reserved for developers and experienced +# professionals having in-depth computer knowledge. Users are therefore +# encouraged to load and test the software's suitability as regards their +# requirements in conditions enabling the security of their systems and/or +# data to be ensured and, more generally, to use and operate it in the +# same conditions as regards security. + +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL license and that you accept its terms. + +# Author: Guillaume Pellerin + +class Twitter: + + def __init__(self, username, password): + import twitter + self.username = username + self.password = password + self.api = twitter.Api(username=self.username, password=self.password) + + def post(self, message): + self.api.PostUpdate(message) + + diff --git a/tools/twitter.py b/tools/twitter.py deleted file mode 100644 index 6451116..0000000 --- a/tools/twitter.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2006-2009 Guillaume Pellerin - -# - -# This software is a computer program whose purpose is to stream audio -# and video data through icecast2 servers. - -# This software is governed by the CeCILL license under French law and -# abiding by the rules of distribution of free software. You can use, -# modify and/ or redistribute the software under the terms of the CeCILL -# license as circulated by CEA, CNRS and INRIA at the following URL -# "http://www.cecill.info". - -# As a counterpart to the access to the source code and rights to copy, -# modify and redistribute granted by the license, users are provided only -# with a limited warranty and the software's author, the holder of the -# economic rights, and the successive licensors have only limited -# liability. - -# In this respect, the user's attention is drawn to the risks associated -# with loading, using, modifying and/or developing or reproducing the -# software by the user in light of its specific status of free software, -# that may mean that it is complicated to manipulate, and that also -# therefore means that it is reserved for developers and experienced -# professionals having in-depth computer knowledge. Users are therefore -# encouraged to load and test the software's suitability as regards their -# requirements in conditions enabling the security of their systems and/or -# data to be ensured and, more generally, to use and operate it in the -# same conditions as regards security. - -# The fact that you are presently reading this means that you have had -# knowledge of the CeCILL license and that you accept its terms. - -# Author: Guillaume Pellerin - -class Twitter: - - def __init__(self, username, password): - import twitter - self.username = username - self.password = password - self.api = twitter.Api(username=self.username, password=self.password) - - def post(self, message): - try: - self.api.PostUpdate(message) - except: - pass -