-from core import *
-from station import *
-from tools import *
+from .core import *
+from .station import *
+from .tools import *
__version__ = '0.7.3'
# Author: Guillaume Pellerin <yomguy@parisson.com>
+
import os
import shout
-import Queue
+import queue
import datetime
import mimetypes
import hashlib
+import platform
from threading import Thread
from deefuzzer.station import *
from deefuzzer.tools import *
station_settings = []
station_instances = {}
watch_folder = {}
- log_queue = Queue.Queue()
+ log_queue = queue.Queue()
main_loop = False
ignore_errors = False
max_retry = 0
Thread.__init__(self)
self.conf_file = conf_file
self.conf = get_conf_dict(self.conf_file)
-
- if 'deefuzzer' not in self.conf:
- return
+
+ print(self.conf)
+
+ if 'deefuzzer' not in self.conf :
+ raise('This is not a standard deefuzzer config file')
# Get the log setting first (if possible)
log_file = str(self.conf['deefuzzer'].pop('log', ''))
os.makedirs(self.log_dir)
self.logger = QueueLogger(log_file, self.log_queue)
self.logger.start()
- #print(self.conf)
- for key in self.conf['deefuzzer'].keys():
+ for key in list(self.conf['deefuzzer'].keys()):
if key == 'm3u':
self.m3u = str(self.conf['deefuzzer'][key])
# Set the deefuzzer logger
self._info('Starting DeeFuzzer')
+ self._info('Using Python version %s' % platform.python_version())
self._info('Using libshout version %s' % shout.version())
self._info('Number of stations : ' + str(len(self.station_settings)))
return
self._info('Creating station for folder ' + folder)
d = dict(path=folder, name=name)
- for i in options.keys():
+ for i in list(options.keys()):
if 'folder' not in i:
s[i] = replace_all(options[i], d)
if 'media' not in s:
return
def run(self):
- q = Queue.Queue(1)
+ q = queue.Queue(1)
ns = 0
p = Producer(q)
p.start()
if 'short_name' in self.station_settings[i]['infos']:
name = self.station_settings[i]['infos']['short_name']
y = 1
- while name in self.station_instances.keys():
+ while name in list(self.station_instances.keys()):
y += 1
name = self.station_settings[i]['infos']['short_name'] + " " + str(y)
self.station_settings[i]['station_name'] = name
- namehash = hashlib.md5(name).hexdigest()
+ namehash = hashlib.md5(str(name).encode('utf-8')).hexdigest()
self.station_settings[i]['station_statusfile'] = os.sep.join([self.log_dir, namehash])
new_station = Station(self.station_settings[i], q, self.log_queue, self.m3u)
# Author: Guillaume Pellerin <yomguy@parisson.com>
-from relay import *
+from .relay import *
import time
def file_read_slow(self):
"""Read a bigger part of the media and stream the little parts
of the data through a generator"""
- m = open(self.media, 'r')
+ m = open(self.media, 'rb')
while True:
self.main_chunk = m.read(self.main_buffer_size)
if not self.main_chunk:
def __init__(self, relay):
self.__relayparam = relay
- self.relay = urllib.urlopen(self.__relayparam)
+ self.relay = urllib.request.urlopen(self.__relayparam)
self.rec_mode = 0
def set_recorder(self, recorder, mode=1):
except:
while True:
try:
- self.relay = urllib.urlopen(self.__relayparam)
+ self.relay = urllib.request.urlopen(self.__relayparam)
chunk = self.relay.read(size)
break
except:
# Author: Guillaume Pellerin <yomguy@parisson.com>
from threading import Thread
-import Queue
-import urllib
+import queue
+import urllib.request, urllib.parse, urllib.error
class Relay(Thread):
Thread.__init__(self)
self.sub_buffer_size = sub_buffer_size
self.queue_size = queue_size
- self.queue = Queue.Queue(self.queue_size)
+ self.queue = queue.Queue(self.queue_size)
self.stream = None
def set_url(self, url):
def open(self):
try:
- self.stream = urllib.urlopen(self.url)
+ self.stream = urllib.request.urlopen(self.url)
self.isopen = True
except:
self.isopen = False
import string
import random
import shout
-import urllib
+import urllib.request, urllib.parse, urllib.error
import mimetypes
import json
import hashlib
import MySQLdb as mdb
from threading import Thread
-from player import *
-from recorder import *
-from relay import *
-from streamer import *
-from tools import *
+from .player import *
+from .recorder import *
+from .relay import *
+from .streamer import *
+from .tools import *
class Station(Thread):
for row in rows:
file_list.append(row[0])
- except mdb.Error, e:
+ except mdb.Error as e:
self._err('Could not get playlist from MySQLdb, Error %d: %s' % (e.args[0], e.args[1]))
finally:
return file_list
def get_array_hash(self, s):
- return hashlib.md5(str(s)).hexdigest()
+ return hashlib.md5(str(s).encode('utf-8')).hexdigest()
def get_jingles(self):
file_list = []
file_meta = Ogg(media)
elif file_ext.lower() == 'webm' or mimetypes.guess_type(media)[0] == 'video/webm':
file_meta = WebM(media)
- except Exception, e:
+ except Exception as e:
self._err('Could not get specific media type class for %s' % (media))
self._err('Error: %s' % (str(e)))
pass
media_description = '<table>'
media_description_item = '<tr><td>%s: </td><td><b>%s</b></td></tr>'
- for key in media.metadata.keys():
+ for key in list(media.metadata.keys()):
if media.metadata[key] != '':
if key == 'filepath' and not self.feeds_showfilepath:
continue
song = mediaobj.get_song(True)
except:
pass
-
+
+ print(title, artist, song)
return title, artist, song
def get_currentsongmeta(self):
while not self.server_ping:
try:
- server = urllib.urlopen(self.server_url)
+ server = urllib.request.urlopen(self.server_url)
self.server_ping = True
self._info('Channel available.')
except:
self.set_read_mode()
return True
- except Exception, e:
+ except Exception as e:
self._err('icecastloop_nextmedia: Error: ' + str(e))
return False
try:
self.update_twitter_current()
if self.song:
- self.channel.set_metadata({'song': self.song, 'charset': 'utf-8'})
+ self.channel.set_metadata({'song': str(self.song), 'charset': 'utf-8'})
return True
- except Exception, e:
+ except Exception as e:
self._err('icecastloop_metadata: Error: ' + str(e))
return False
def to_xml(self, encoding="iso-8859-1"):
try:
- import cStringIO as StringIO
+ import io as StringIO
except ImportError:
- import StringIO
- f = StringIO.StringIO()
+ import io
+ f = io.StringIO()
self.write_xml(f, encoding)
return f.getvalue()
def _element(handler, name, obj, d=None):
if not d:
d = {}
- if isinstance(obj, basestring) or obj is None:
+ if isinstance(obj, str) or obj is None:
# special-case handling to make the API easier
# to use for the common case.
handler.startElement(name, d)
_opt_element(handler, "lastBuildDate", lastBuildDate)
for category in self.categories:
- if isinstance(category, basestring):
+ if isinstance(category, str):
category = Category(category)
category.publish(handler)
_opt_element(handler, "author", self.author)
for category in self.categories:
- if isinstance(category, basestring):
+ if isinstance(category, str):
category = Category(category)
category.publish(handler)
# -*- coding: utf-8 -*-
-from xmltodict import *
-from PyRSS2Gen import *
-from mediabase import *
-from mp3 import *
-from ogg import *
-from webm import *
-from logger import *
-from osc import *
-from twitt import *
-from utils import *
+from .xmltodict import *
+from .PyRSS2Gen import *
+from .mediabase import *
+from .mp3 import *
+from .ogg import *
+from .webm import *
+from .logger import *
+from .osc import *
+from .twitt import *
+from .utils import *
# parse_qsl moved to urlparse module in v2.6
try:
- from urlparse import parse_qsl
+ from urllib.parse import parse_qsl
except:
from cgi import parse_qsl
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 ''
+ 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'
+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']
+ 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 ''
+ 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? ')
+ pincode = 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 ''
+ 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
+ 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 ''
+ print('Your Twitter Access Token key: %s' % access_token['oauth_token'])
+ print(' Access Token secret: %s' % access_token['oauth_token_secret'])
+ print('')
def read_file_metadata(self):
"""Reads the metadata for the media, filtered by the tagdata dictionary for this media type"""
self.metadata = {}
- for key in self.tagdata.keys():
+ for key in list(self.tagdata.keys()):
self.metadata[key] = ''
try:
self.metadata[key] = self.sourceobj[key][0]
r = "";
if clean:
r = r.replace('_',' ').strip()
- return r.encode('utf-8')
+ return r
def get_title(self):
"""Returns the cleaned title for this media"""
from mutagen.easyid3 import EasyID3
from mutagen.mp3 import MP3, MPEGInfo
from mutagen import id3
-from utils import *
+from .utils import *
EasyID3.valid_keys["comment"] = "COMM::'XXX'"
EasyID3.valid_keys["copyright"] = "TCOP::'XXX'"
respect of mutagen classes and methods"""
self.sourceobj.add_tags()
- self.sourceobj.tags['TIT2'] = id3.TIT2(encoding=2, text=u'text')
+ self.sourceobj.tags['TIT2'] = id3.TIT2(encoding=2, text='text')
self.sourceobj.save()
'''
import string
import datetime
from mutagen.oggvorbis import OggVorbis
-from utils import *
+from .utils import *
class Ogg(MediaBase):
def write_tags(self):
# self.ogg.add_tags()
- for tag in self.metadata.keys():
+ for tag in list(self.metadata.keys()):
self.sourceobj[tag] = str(self.metadata[tag])
self.sourceobj.save()
else:
args.append('-Q -b ' + self.bitrate_default)
- for tag in self.metadata.keys():
+ for tag in list(self.metadata.keys()):
value = clean_word(self.metadata[tag])
args.append('-c %s="%s"' % (tag, value))
if tag in self.tagdata:
self.port = port
try:
self.server = liblo.Server(self.port)
- except liblo.ServerError, err:
- print str(err)
+ except liblo.ServerError as err:
+ print(str(err))
def add_method(self, path, type, method):
self.server.add_method(path, type, method)
return r
elif isinstance(option, dict):
r = {}
- for key in option.keys():
+ for key in list(option.keys()):
r[key] = replace_all(option[key], repl)
return r
elif isinstance(option, str):
r = option
- for key in repl.keys():
+ for key in list(repl.keys()):
r = r.replace('[' + key + ']', repl[key])
return r
return option
elif 'yaml' in mime_type or 'yml' in mime_type:
import yaml
-
- def custom_str_constructor(loader, node):
- return loader.construct_scalar(node).encode('utf-8')
-
- yaml.add_constructor(u'tag:yaml.org,2002:str', custom_str_constructor)
confile = open(file, 'r')
- data = confile.read()
- confile.close()
- for c in yaml.load_all(data):
- conf = c
+ conf = yaml.safe_load(confile)
return conf
elif 'json' in mime_type:
import os
import string
import datetime
-from utils import *
+from .utils import *
class WebM(MediaBase):
# argument was a file
try:
ret = parser.ParseFromFile(xml)
- except expat.ExpatError, e:
+ except expat.ExpatError as e:
errmsg = _("The XML in '%s' is not well-formed and cannot be parsed: %s") % (xml, e)
else:
# argument must have been raw xml:
except expat.ExpatError:
errmsg = _("An invalid XML string was encountered")
if errmsg:
- raise dabo.dException.XmlException, errmsg
+ raise dabo.dException.XmlException(errmsg)
if addCodeFile and isPath:
# Get the associated code file, if any
codePth = "%s-code.py" % os.path.splitext(xml)[0]
try:
codeDict = desUtil.parseCodeFile(open(codePth).read())
desUtil.addCodeToClassDict(ret, codeDict)
- except StandardError, e:
- print "Failed to parse code file:", e
+ except Exception as e:
+ print("Failed to parse code file:", e)
return ret
"""Add surrounding quotes to the string, and escape
any illegal XML characters.
"""
- if not isinstance(val, basestring):
+ if not isinstance(val, str):
val = str(val)
- if not isinstance(val, unicode):
- val = unicode(val, default_encoding)
+ if not isinstance(val, str):
+ val = str(val, default_encoding)
if noQuote:
qt = ''
else:
ret = ""
if "attributes" in dct:
- for key, val in dct["attributes"].items():
+ for key, val in list(dct["attributes"].items()):
# Some keys are already handled.
noEscape = key in ("sizerInfo",)
val = escQuote(val, noEscape)
ret += "%s" % dct["cdata"].replace("<", "<")
if "code" in dct:
- if len(dct["code"].keys()):
+ if len(list(dct["code"].keys())):
ret += "%s%s<code>%s" % (eol, "\t" * (level + 1), eol)
methodTab = "\t" * (level + 2)
- for mthd, cd in dct["code"].items():
+ for mthd, cd in list(dct["code"].items()):
# Convert \n's in the code to eol:
cd = eol.join(cd.splitlines())
ret += "%s</code>%s" % ("\t" * (level + 1), eol)
if "properties" in dct:
- if len(dct["properties"].keys()):
+ if len(list(dct["properties"].keys())):
ret += "%s%s<properties>%s" % (eol, "\t" * (level + 1), eol)
currTab = "\t" * (level + 2)
- for prop, val in dct["properties"].items():
+ for prop, val in list(dct["properties"].items()):
ret += "%s<%s>%s" % (currTab, prop, eol)
- for propItm, itmVal in val.items():
+ for propItm, itmVal in list(val.items()):
itmTab = "\t" * (level + 3)
ret += "%s<%s>%s</%s>%s" % (itmTab, propItm, itmVal, propItm, eol)
ret += "%s</%s>%s" % (currTab, prop, eol)
-#!/usr/bin/python
+#!/usr/bin/python3
import os
import sys
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
- print str(err)
+except liblo.AddressError as err:
+ print(str(err))
sys.exit()
# send message "/foo/message1" with int, float and string arguments
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
- print str(err)
+except liblo.AddressError as err:
+ print(str(err))
sys.exit()
# send message "/foo/message1" with int, float and string arguments
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
- print str(err)
+except liblo.AddressError as err:
+ print(str(err))
sys.exit()
# send message "/foo/message1" with int, float and string arguments
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
+except liblo.AddressError as err:
sys.exit(err)
# send message "/foo/message1" with int, float and string arguments
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
- print str(err)
+except liblo.AddressError as err:
+ print(str(err))
sys.exit()
# send message "/foo/message1" with int, float and string arguments
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
- print str(err)
+except liblo.AddressError as err:
+ print(str(err))
sys.exit()
# send message "/foo/message1" with int, float and string arguments
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
- print str(err)
+except liblo.AddressError as err:
+ print(str(err))
sys.exit()
# send message "/foo/message1" with int, float and string arguments
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
- print str(err)
+except liblo.AddressError as err:
+ print(str(err))
sys.exit()
# send message "/foo/message1" with int, float and string arguments
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
- print str(err)
+except liblo.AddressError as err:
+ print(str(err))
sys.exit()
# send message "/foo/message1" with int, float and string arguments
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
- print str(err)
+except liblo.AddressError as err:
+ print(str(err))
sys.exit()
# send message "/foo/message1" with int, float and string arguments
# send all messages to port 1234 on the local machine
try:
target = liblo.Address(1234)
-except liblo.AddressError, err:
- print str(err)
+except liblo.AddressError as err:
+ print(str(err))
sys.exit()
# send message "/foo/message1" with int, float and string arguments