]> git.parisson.com Git - deefuzzer.git/commitdiff
- Fixes for Shout
authorDominic Kanrabat <doomy23@gmail.com>
Wed, 24 Apr 2019 07:19:28 +0000 (03:19 -0400)
committerDominic Kanrabat <doomy23@gmail.com>
Wed, 24 Apr 2019 07:19:28 +0000 (03:19 -0400)
- Added MySQLdb feature

deefuzzer/station.py
setup.py

index c771b4b8fd2214b3e1c3328fc2ec2bd07b8367ec..123b3f2668639687ee34980339e8722ea5695ee5 100644 (file)
@@ -46,6 +46,7 @@ import shout
 import urllib
 import mimetypes
 import json
+import MySQLdb as mdb
 
 from threading import Thread
 from player import *
@@ -87,6 +88,13 @@ class Station(Thread):
     jingles_frequency = 2
     statusfile = ''
     base_directory = ''
+    mdb_host = '127.0.0.1'
+    mdb_port = 3306
+    mdb_user = ''
+    mdb_password = ''
+    mdb_database = ''
+    mdb_table = ''
+    mdb_field = ''
 
     def __init__(self, station, q, logqueue, m3u):
         Thread.__init__(self)
@@ -123,6 +131,23 @@ class Station(Thread):
             if not self.station['media']['source'].strip() == '':
                 self.media_source = self._path_add_base(self.station['media']['source'])
 
+        # MySQL
+        if 'mysql' in self.station['media']:
+            if 'host' in self.station['media']['mysql']:
+                self.mdb_host = self.station['media']['mysql']['host']
+            if 'port' in self.station['media']['mysql']:
+                self.mdb_port = self.station['media']['mysql']['port']
+            if 'user' in self.station['media']['mysql']:
+                self.mdb_user = self.station['media']['mysql']['user']
+            if 'password' in self.station['media']['mysql']:
+                self.mdb_password = self.station['media']['mysql']['password']
+            if 'database' in self.station['media']['mysql']:
+                self.mdb_database = self.station['media']['mysql']['database']
+            if 'table' in self.station['media']['mysql']:
+                self.mdb_table = self.station['media']['mysql']['table']
+            if 'field' in self.station['media']['mysql']:
+                self.mdb_field = self.station['media']['mysql']['field']
+
         self.media_format = self.station['media']['format']
         self.shuffle_mode = int(self.station['media']['shuffle'])
         self.bitrate = int(self.station['media']['bitrate'])
@@ -150,25 +175,26 @@ class Station(Thread):
 
         if 'stream-m' in self.type:
             self.channel = HTTPStreamer()
-            self.channel.mount = '/publish/' + self.mountpoint
+            self.channel.mount = '/publish/' + str(self.mountpoint)
         elif 'icecast' in self.type:
             self.channel = shout.Shout()
-            self.channel.mount = '/' + self.mountpoint
+            self.channel.mount = '/' + str(self.mountpoint)
             if self.appendtype:
-                self.channel.mount = self.channel.mount + '.' + self.media_format
+                self.channel.mount = str(self.channel.mount) + '.' + str(self.media_format)
         else:
             self._err('Not a compatible server type. Choose "stream-m" or "icecast".')
             return
 
-        self.channel.url = self.station['infos']['url']
-        self.channel.name = self.station['infos']['name']
-        self.channel.genre = self.station['infos']['genre']
-        self.channel.description = self.station['infos']['description']
-        self.channel.format = self.media_format
-        self.channel.host = self.station['server']['host']
+        # Shout requires non-unicode strings
+        self.channel.url = str(self.station['infos']['url'])
+        self.channel.name = str(self.station['infos']['name'])
+        self.channel.genre = str(self.station['infos']['genre'])
+        self.channel.description = str(self.station['infos']['description'])
+        self.channel.format = str(self.media_format)
+        self.channel.host = str(self.station['server']['host'])
         self.channel.port = int(self.station['server']['port'])
         self.channel.user = 'source'
-        self.channel.password = self.station['server']['sourcepassword']
+        self.channel.password = str(self.station['server']['sourcepassword'])
         self.channel.public = int(self.station['server']['public'])
         if self.channel.format == 'mp3':
             self.channel.audio_info = {'bitrate': str(self.bitrate),
@@ -180,7 +206,7 @@ class Station(Thread):
                                        'quality': str(self.ogg_quality),
                                        'channels': str(self.voices), }
 
-        self.server_url = 'http://' + self.channel.host + ':' + str(self.channel.port)
+        self.server_url = 'http://' + str(self.channel.host) + ':' + str(self.channel.port)
         self.channel_url = self.server_url + self.channel.mount
 
         # RSS
@@ -404,7 +430,24 @@ class Station(Thread):
         file_list = []
 
         try:
-            if os.path.isdir(self.media_source):
+            # MySQLdb
+            if 'mysql' in self.station['media']:
+                try:
+                    con = mdb.connect(host = self.mdb_host,
+                                      user = self.mdb_user,
+                                      passwd = self.mdb_password,
+                                      db = self.mdb_database,
+                                      port = self.mdb_port,
+                                      use_unicode = True)
+                    cur = con.cursor()
+                    cur.execute("SELECT %s FROM %s".format(self.mdb_field, self.mdb_table))
+                    file_list = cur.fetchall()
+
+                except mdb.Error, e:
+                    self._err('Could not get playlist from MySQLdb, Error %d: %s' % (e.args[0], e.args[1]))
+
+            # Directory
+            elif os.path.isdir(self.media_source):
                 self.q.get(1)
                 try:
                     for root, dirs, files in os.walk(self.media_source):
@@ -418,7 +461,8 @@ class Station(Thread):
                     pass
                 self.q.task_done()
 
-            if os.path.isfile(self.media_source):
+            # File
+            elif os.path.isfile(self.media_source):
                 self.q.get(1)
                 try:
                     f = open(self.media_source, 'r')
@@ -895,4 +939,3 @@ class Station(Thread):
 
                 self.channel_close()
                 time.sleep(1)
-
index 9f522da735e5ca143089938fc9368c5b740c096a..2c72f7a5b8e1988c06d725aa57feb31b64e847c1 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -27,7 +27,8 @@ setup(
         'mutagen',
         'pyliblo',
         'pycurl',
-        'pyyaml'
+        'pyyaml',
+        'mysql'
     ],
     platforms=['OS Independent'],
     license='CeCILL v2',