# -*- coding: utf-8 -*-
#
-# Copyright (c) 2007-2009 Guillaume Pellerin <pellerin@parisson.com>
+# Copyright (c) 2007-2010 Guillaume Pellerin <pellerin@parisson.com>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
#
# Author: Guillaume Pellerin <pellerin@parisson.com>
- depends: python, python-dev, python-xml, python-shout | shout-python, libshout3,
+
+Dependencies
+=============
+
+depends: python, python-dev, python-xml, python-shout | shout-python, libshout3,
libshout3-dev, python-mutagen
- provides: shout-python
+provides: shout-python | python-shout, python-tinyurl
+
+optional: python-twitter, python-liblo | pyliblo (>= 0.26)
+
+recommends: icecast2
+
+
+Install
+=========
+
+To install the DeeFuzzer, go to the main deefuzzer app directory, for example::
+
+ cd deefuzzer-0.4.3
+
+and run the python installer::
+
+ sudo python install.py
+
+For more informations, see http://svn.parisson.org/deefuzzer/
+
- optional: python-twitter, python-tinyurl, python-liblo | pyliblo (>= 0.26)
+Twitter (optional)
+=====================
- recommends: icecast2
+To get track twitting, please install python-twitter, python-oauth2 and all their dependencies.
+As Twitter now requires oauth key system since 07/2010, you need to get your own access token key pair.
+Please run the dedicated script to do this::
+
+ python tools/get_access_token.py
+
+You will be invited to copy/paste an URL in your browser to get a pin code.
+Then copy/paste this code into the console and press ENTER.
+The script gives you a pair of keys : one access token key and one access token secret key.
-python-shout is included in the DeeFuzzer but needs to be compiled and installed
-if you don't install deefuzzer from its debian package with aptitude.
-As explained in shout-python/INSTALL, you just have to run this command :
+Change the <twitter> block options in your deefuzzer XML config file, giving the 2 keys.
+For example::
+
+ <twitter>
+ <mode>1</mode>
+ <key>85039615-H6yAtXXCx7NobF5W40FV0c8epGZsQGkE7MG6XRjD2</key>
+ <secret>A1YW3llB9H9qVbjH8zOQTOkMlhVqh2a7LnA9Lt0b6Gc</secret>
+ <tags>Music Groove</tags>
+ </twitter>
+
+Your DeeFuzzer will now tweet the currently playing track and new tracks on your profile.
- $ cd shout-python
- $ sudo python setup.py install
-To install the DeeFuzzer (from the main deefuzzer directory) :
+OSC Control
+=============
- $ sudo python install.py
+Working, but no doc yet. Please read the code :)
-For more informations, see http://svn.parisson.org/deefuzzer/
\ No newline at end of file
where CONFIGFILE is the path for a XML config file. For example::
-$ deefuzzer example/myfuzz.xml
+ deefuzzer example/myfuzz.xml
To make the deefuzzer act as a deamon, just play it in the background::
-$ deefuzzer example/myfuzz.xml &
+ deefuzzer example/myfuzz.xml &
Note that you must edit the config file with right parameters before playing.
You can find an example for a draft XML file in the directory "example/" of this
avoids shutting down the streams with CTRL+C... You have to kill them manually,
after a CTRL+Z, making this::
-$ kill -9 PROCESS_ID
+ kill -9 PROCESS_ID
or::
-$ kill -9 `pgrep deefuzzer`
+ pkill -9 deefuzzer
XML Configuration
Next track::
-$ python tools/osc_next.py
+ python tools/osc_next.py
Start twitting::
-$ python tools/osc_twitter_start.py
+ python tools/osc_twitter_start.py
Stop twitting::
-$ python see tools/osc_twitter_stop.py
+ python see tools/osc_twitter_stop.py
Start relaying::
-$ python tools/osc_relay_start.py
+ python tools/osc_relay_start.py
Stop relaying::
-$ python see tools/osc_relay_stop.py
+ python see tools/osc_relay_stop.py
Start jingling::
-$ python see tools/osc_jingles_start.py
+ python see tools/osc_jingles_start.py
Stop jingling::
-$ python see tools/osc_jingles_stop.py
+ python see tools/osc_jingles_stop.py
Author
from threading import Thread
from tools import *
-version = '0.4.3'
+version = '0.5.0'
year = datetime.datetime.now().strftime("%Y")
platform_system = platform.system()
<!-- If '1', deefuzzer will tweet #nowplaying, new tracks and other things to Twitter. 'O' does nothing. -->
<mode>0</mode>
<!-- Your twitter username -->
- <user>my_twitter_user</user>
+ <key>your access token key</key>
<!-- Your twitter password -->
- <pass>my_twitter_password</pass>
+ <secret>your access token secret key</secret>
<!-- These tags will be added to each twitter message -->
<tags>bla bla</tags>
</twitter>
--- /dev/null
+#!/usr/bin/python2.4
+#
+# Copyright 2007 The Python-Twitter Developers
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import os
+import sys
+
+# parse_qsl moved to urlparse module in v2.6
+try:
+ from urlparse import parse_qsl
+except:
+ from cgi import parse_qsl
+
+import oauth2 as oauth
+
+REQUEST_TOKEN_URL = 'https://api.twitter.com/oauth/request_token'
+ACCESS_TOKEN_URL = 'https://api.twitter.com/oauth/access_token'
+AUTHORIZATION_URL = 'https://api.twitter.com/oauth/authorize'
+SIGNIN_URL = 'https://api.twitter.com/oauth/authenticate'
+
+consumer_key = 'ozs9cPS2ci6eYQzzMSTb4g'
+consumer_secret = '1kNEffHgGSXO2gMNTr8HRum5s2ofx3VQnJyfd0es'
+
+if consumer_key is None or consumer_secret is None:
+ print 'You need to edit this script and provide values for the'
+ print 'consumer_key and also consumer_secret.'
+ print ''
+ print 'The values you need come from Twitter - you need to register'
+ print 'as a developer your "application". This is needed only until'
+ print 'Twitter finishes the idea they have of a way to allow open-source'
+ print 'based libraries to have a token that can be used to generate a'
+ print 'one-time use key that will allow the library to make the request'
+ print 'on your behalf.'
+ print ''
+ sys.exit(1)
+
+signature_method_hmac_sha1 = oauth.SignatureMethod_HMAC_SHA1()
+oauth_consumer = oauth.Consumer(key=consumer_key, secret=consumer_secret)
+oauth_client = oauth.Client(oauth_consumer)
+
+print 'Requesting temp token from Twitter'
+
+resp, content = oauth_client.request(REQUEST_TOKEN_URL, 'GET')
+
+if resp['status'] != '200':
+ print 'Invalid respond from Twitter requesting temp token: %s' % resp['status']
+else:
+ request_token = dict(parse_qsl(content))
+
+ print ''
+ print 'Please visit this Twitter page and retrieve the pincode to be used'
+ print 'in the next step to obtaining an Authentication Token:'
+ print ''
+ print '%s?oauth_token=%s' % (AUTHORIZATION_URL, request_token['oauth_token'])
+ print ''
+
+ pincode = raw_input('Pincode? ')
+
+ token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
+ token.set_verifier(pincode)
+
+ print ''
+ print 'Generating and signing request for an access token'
+ print ''
+
+ oauth_client = oauth.Client(oauth_consumer, token)
+ resp, content = oauth_client.request(ACCESS_TOKEN_URL, method='POST', body='oauth_verifier=%s' % pincode)
+ access_token = dict(parse_qsl(content))
+
+ if resp['status'] != '200':
+ print 'The request for a Token did not succeed: %s' % resp['status']
+ print access_token
+ else:
+ print 'Your Twitter Access Token key: %s' % access_token['oauth_token']
+ print ' Access Token secret: %s' % access_token['oauth_token_secret']
+ print ''
+
self.twitter_mode = 0
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']
+ self.twitter_key = self.station['twitter']['key']
+ self.twitter_secret = self.station['twitter']['secret']
self.twitter_tags = self.station['twitter']['tags'].split(' ')
if self.twitter_mode == 1:
self.twitter_callback('/twitter', [1])
def twitter_callback(self, path, value):
value = value[0]
import tinyurl
- self.twitter = Twitter(self.twitter_user, self.twitter_pass)
+ self.twitter = Twitter(self.twitter_key, self.twitter_secret)
self.twitter_mode = value
message = "Received OSC message '%s' with arguments '%d'" % (path, value)
self.m3u_tinyurl = tinyurl.create_one(self.channel.url + '/m3u/' + self.m3u.split(os.sep)[-1])
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_info('Deefuzzing on %s : id = %s, name = %s' \
+ self.logger.write_info('DeeFuzzing on %s : id = %s, name = %s' \
% (self.short_name, self.id, self.current_media_obj[0].file_name))
self.player.set_media(self.media)
if self.player_mode == 0:
def update_twitter_current(self):
artist_names = self.artist.split(' ')
artist_tags = ' #'.join(list(set(artist_names)-set(['&', '-'])))
- message = '♫ %s %s on #%s #%s' % (self.prefix, self.song, self.short_name, artist_tags)
+ message = '%s %s on #%s #%s' % (self.prefix, self.song, self.short_name, artist_tags)
tags = '#' + ' #'.join(self.twitter_tags)
message = message + ' ' + tags
message = message[:107] + ' M3U : ' + self.m3u_tinyurl
# Author: Guillaume Pellerin <yomguy@parisson.com>
# Twitter DeeFuzzer keys
-TWITTER_CONSUMER_KEY = 'ozs9cPS2ci6eYQzzMSTb4g'
-TWITTER_CONSUMER_SECRET = '1kNEffHgGSXO2gMNTr8HRum5s2ofx3VQnJyfd0es'
+DEEFUZZER_CONSUMER_KEY = 'ozs9cPS2ci6eYQzzMSTb4g'
+DEEFUZZER_CONSUMER_SECRET = '1kNEffHgGSXO2gMNTr8HRum5s2ofx3VQnJyfd0es'
class Twitter:
def __init__(self, access_token_key, access_token_secret):
import twitter
- self.username = TWITTER_CONSUMER_KEY
- self.password = TWITTER_CONSUMER_SECRET
+ self.consumer_key = DEEFUZZER_CONSUMER_KEY
+ self.consumer_secret = DEEFUZZER_CONSUMER_SECRET
self.access_token_key = access_token_key
self.access_token_secret = access_token_secret
- self.api = twitter.Api(username=self.username,
- password=self.password,
+ self.api = twitter.Api(consumer_key=self.consumer_key,
+ consumer_secret=self.consumer_secret,
access_token_key=self.access_token_key,
access_token_secret=self.access_token_secret)