]> git.parisson.com Git - deefuzzer.git/commitdiff
add twitter posting of the current track, modify XML conf scheme
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 26 Oct 2009 09:16:34 +0000 (09:16 +0000)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 26 Oct 2009 09:16:34 +0000 (09:16 +0000)
INSTALL
README
deefuzzer.py
example/myfuzz.xml

diff --git a/INSTALL b/INSTALL
index a02ecbda394a793684d51357aa01ce9b1d31c1ac..5f084ac9da3918167dd1b4ea3739c7b6aedeae32 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -10,7 +10,7 @@
 # Author: Guillaume Pellerin <pellerin@parisson.com>
 
  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 62a2b395a51a5f492459aa6c173f419de0445302..3befd67089135c0c9fb8c318517fba40b7c257c3 100644 (file)
--- 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
index 03d759da833e21ae3bb85ee8975038ab3abb5361..2160f560720f73d4831fbc9822a328bef23b1cd9 100755 (executable)
@@ -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])
index a799e16a80802b7b46af7976271b2bde1d34fcb6..358fac30bd478e858c8ab74fcd024066fcf00f6a 100644 (file)
             <samplerate>44100</samplerate>
             <voices>2</voices>
             <shuffle>1</shuffle>
-            <rss_dir>/tmp/rss/</rss_dir>
-            <rss_enclosure>0</rss_enclosure>
         </media>
+        <rss>
+            <dir>/tmp/rss/</dir>
+            <enclosure>1</enclosure>
+        </rss>
+        <twitter>
+            <mode>0</mode>
+            <user>xxxxxx</user>
+            <pass>xxxxxx</pass>
+        </twitter>
     </station>
     <station>
         <infos>
             <format>mp3</format>
             <bitrate>192</bitrate>
             <ogg_quality>7</ogg_quality>
-            <samplerate>44100</samplerate>
+            <samplerate>44100</samplerate>s
             <voices>2</voices>
             <shuffle>0</shuffle>
-            <rss_dir>/tmp/rss/</rss_dir>
-            <rss_enclosure>1</rss_enclosure>
         </media>
+        <rss>
+            <dir>/tmp/rss/</dir>
+            <enclosure>1</enclosure>
+        </rss>
+        <twitter>
+            <mode>0</mode>
+            <user>xxxxxx</user>
+            <pass>xxxxxx</pass>
+        </twitter>
     </station>
 </deefuzzer>