From: Guillaume Pellerin Date: Mon, 26 Oct 2009 09:16:34 +0000 (+0000) Subject: add twitter posting of the current track, modify XML conf scheme X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=93d28189c8045fda290f6d275ca3c8e99bf830de;p=deefuzzer.git add twitter posting of the current track, modify XML conf scheme --- diff --git a/INSTALL b/INSTALL index a02ecbd..5f084ac 100644 --- a/INSTALL +++ b/INSTALL @@ -10,7 +10,7 @@ # Author: Guillaume Pellerin depends : python, python-dev, python-xml, python-shout | shout-python, libshout3, - libshout3-dev, icecast2 python-mutagen + libshout3-dev, icecast2 python-mutagen, python-twitters provides : shout-python diff --git a/README b/README index 62a2b39..3befd67 100644 --- a/README +++ b/README @@ -17,6 +17,7 @@ Here are the main features of the DeeFuzzer Tools: * M3U playlist generator * Recursive, random (shuffled) or pre-defined playlists * Multi-threaded architecture (multiple stations now authorized !) + * Auto TWITTER posting of the current playing track * VERY light and optimized streaming process ! It is neccessary to provide a config file which sets all needed parameters diff --git a/deefuzzer.py b/deefuzzer.py index 03d759d..2160f56 100755 --- a/deefuzzer.py +++ b/deefuzzer.py @@ -46,6 +46,7 @@ import Queue import shout import subprocess import platform +import twitter from threading import Thread from tools import * @@ -214,7 +215,8 @@ class Station(Thread): self.counter = 0 self.command = 'cat ' self.delay = 0 - # Media + + # Media self.media_dir = self.station['media']['dir'] self.channel.format = self.station['media']['format'] self.mode_shuffle = int(self.station['media']['shuffle']) @@ -222,8 +224,11 @@ class Station(Thread): self.ogg_quality = self.station['media']['ogg_quality'] self.samplerate = self.station['media']['samplerate'] self.voices = self.station['media']['voices'] - self.rss_dir = self.station['media']['rss_dir'] - self.rss_enclosure = self.station['media']['rss_enclosure'] + + # RSS + self.rss_dir = self.station['rss']['dir'] + self.rss_enclosure = self.station['rss']['enclosure'] + # Infos self.short_name = self.station['infos']['short_name'] self.channel.name = self.station['infos']['name'] @@ -234,6 +239,7 @@ class Station(Thread): self.rss_current_file = self.base_name + '_current.xml' self.rss_playlist_file = self.base_name + '_playlist.xml' self.m3u_playlist_file = self.rss_dir + os.sep + self.short_name + '.m3u' + # Server self.channel.protocol = 'http' # | 'xaudiocast' | 'icy' self.channel.host = self.station['server']['host'] @@ -249,6 +255,7 @@ class Station(Thread): self.playlist = self.get_playlist() self.lp = len(self.playlist) self.channel.open() + # Logging self.logger.write('Opening ' + self.short_name + ' - ' + self.channel.name + \ ' (' + str(self.lp) + ' tracks)...') @@ -259,6 +266,16 @@ class Station(Thread): if not os.path.exists(self.metadata_dir): os.makedirs(self.metadata_dir) + # Twitter + if self.station['twitter']: + self.twitter_mode = 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) + else: + self.twitter_mode = '0' + def update_rss(self, media_list, rss_file, sub_title): rss_item_list = [] if not os.path.exists(self.rss_dir): @@ -354,7 +371,7 @@ class Station(Thread): self.update_rss(self.media_to_objs(self.playlist), self.rss_playlist_file, '(playlist)') else: self.id = (self.id + 1) % self.lp - + return self.playlist[self.id] else: mess = 'No media in media_dir !' @@ -427,15 +444,19 @@ class Station(Thread): artist = self.current_media_obj[0].metadata['artist'] if not (title or artist): song = str(self.current_media_obj[0].file_name) + artist = '' else: song = artist + ' : ' + title + song = str(song.encode('utf-8')) self.metadata_file = self.metadata_dir + os.sep + self.current_media_obj[0].file_name + '.xml' self.update_rss(self.current_media_obj, self.metadata_file, '') - self.channel.set_metadata({'song': str(song.encode('utf-8')), 'charset': 'utf8',}) + self.channel.set_metadata({'song': 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.short_name, self.id, self.current_media_obj[0].file_name)) + if self.twitter_mode == '1': + self.twitter.post(song + ' #' + artist.replace(' ', '')) stream = self.core_process_read(media) q.task_done() @@ -458,6 +479,22 @@ class Station(Thread): self.channel.close() +class Twitter: + """Post a message to Twitter""" + + def __init__(self, username, password): + #Thread.__init__(self) + self.username = username + self.password = password + self.api = twitter.Api(username=self.username, password=self.password) + + def set_message(self, message): + self.message = message + + def post(self, message): + self.api.PostUpdate(message) + + def main(): if len(sys.argv) == 2: d = DeeFuzzer(sys.argv[1]) diff --git a/example/myfuzz.xml b/example/myfuzz.xml index a799e16..358fac3 100644 --- a/example/myfuzz.xml +++ b/example/myfuzz.xml @@ -24,9 +24,16 @@ 44100 2 1 - /tmp/rss/ - 0 + + /tmp/rss/ + 1 + + + 0 + xxxxxx + xxxxxx + @@ -48,12 +55,19 @@ mp3 192 7 - 44100 + 44100s 2 0 - /tmp/rss/ - 1 + + /tmp/rss/ + 1 + + + 0 + xxxxxx + xxxxxx +