parent
be6b4d4088
commit
e62fc7bdb0
21
mumbleBot.py
21
mumbleBot.py
@ -22,13 +22,10 @@ import util
|
|||||||
|
|
||||||
|
|
||||||
class MumbleBot:
|
class MumbleBot:
|
||||||
def __init__(self, args):
|
def __init__(self, args, config):
|
||||||
signal.signal(signal.SIGINT, self.ctrl_caught)
|
signal.signal(signal.SIGINT, self.ctrl_caught)
|
||||||
|
|
||||||
self.config = configparser.ConfigParser(interpolation=None)
|
self.config = config
|
||||||
self.config.read("configuration.ini", encoding='latin-1')
|
|
||||||
|
|
||||||
|
|
||||||
self.volume = self.config.getfloat('bot', 'volume')
|
self.volume = self.config.getfloat('bot', 'volume')
|
||||||
|
|
||||||
self.channel = args.channel
|
self.channel = args.channel
|
||||||
@ -332,7 +329,11 @@ def start_web_interface(addr, port):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(description='Bot for playing radio stream on Mumble')
|
global __CONFIG
|
||||||
|
parser = argparse.ArgumentParser(description='Bot for playing music on Mumble')
|
||||||
|
|
||||||
|
# General arguments
|
||||||
|
parser.add_argument("--config", dest='config', type=str, default='configuration.ini', help='Load configuration from this file. Default: configuration.ini')
|
||||||
|
|
||||||
# Mumble arguments
|
# Mumble arguments
|
||||||
parser.add_argument("-s", "--server", dest="host", type=str, required=True, help="The server's hostame of a mumble server")
|
parser.add_argument("-s", "--server", dest="host", type=str, required=True, help="The server's hostame of a mumble server")
|
||||||
@ -346,4 +347,10 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('--wi-addr', dest='wi_addr', type=str, default=None, help='Listening address of the web interface')
|
parser.add_argument('--wi-addr', dest='wi_addr', type=str, default=None, help='Listening address of the web interface')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
botamusique = MumbleBot(args)
|
__CONFIG = configparser.ConfigParser(interpolation=None)
|
||||||
|
parsed_configs = __CONFIG.read(args.config, encoding='latin-1')
|
||||||
|
if len(parsed_configs) == 0:
|
||||||
|
print('Could not read configuration from file \"{}\"'.format(args.config), file=sys.stderr)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
botamusique = MumbleBot(args, __CONFIG)
|
||||||
|
8
util.py
8
util.py
@ -1,16 +1,14 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import configparser
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import magic
|
import magic
|
||||||
import os
|
import os
|
||||||
import variables as var
|
import variables as var
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
__CONFIG = configparser.ConfigParser(interpolation=None)
|
|
||||||
__CONFIG.read("configuration.ini", encoding='latin-1')
|
|
||||||
|
|
||||||
def get_recursive_filelist_sorted(path):
|
def get_recursive_filelist_sorted(path):
|
||||||
|
global __CONFIG
|
||||||
|
|
||||||
filelist = []
|
filelist = []
|
||||||
for root, dirs, files in os.walk(path):
|
for root, dirs, files in os.walk(path):
|
||||||
relroot = root.replace(path, '')
|
relroot = root.replace(path, '')
|
||||||
@ -38,6 +36,8 @@ def get_recursive_filelist_sorted(path):
|
|||||||
# - hash is a sha1 of the string representation of the directories' contents (which are
|
# - hash is a sha1 of the string representation of the directories' contents (which are
|
||||||
# zipped)
|
# zipped)
|
||||||
def zipdir(zippath, zipname_prefix=None):
|
def zipdir(zippath, zipname_prefix=None):
|
||||||
|
global __CONFIG
|
||||||
|
|
||||||
zipname = __CONFIG.get('bot', 'tmp_folder')
|
zipname = __CONFIG.get('bot', 'tmp_folder')
|
||||||
if zipname_prefix and '../' not in zipname_prefix:
|
if zipname_prefix and '../' not in zipname_prefix:
|
||||||
zipname += zipname_prefix.strip().replace('/', '_') + '_'
|
zipname += zipname_prefix.strip().replace('/', '_') + '_'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user