Ejemplo n.º 1
0
    def __init__(self):
        signal.signal(signal.SIGINT, self.ctrl_caught)

        self.config = configparser.ConfigParser(interpolation=None)
        self.config.read("configuration.ini", encoding='utf-8')

        parser = argparse.ArgumentParser(description='Bot for playing audio files on Mumble')
        parser.add_argument("-s", "--server", dest="host", type=str, required=True, help="The hostame of a mumble server")
        parser.add_argument("-u", "--user", dest="user", type=str, required=True, help="Username for the bot", default="botamusique")
        parser.add_argument("-P", "--password", dest="password", type=str, default="", help="Password if server requires one")
        parser.add_argument("-p", "--port", dest="port", type=int, default=64738, help="Port of the mumble server")
        parser.add_argument("-c", "--channel", dest="channel", type=str, default="", help="Starting channel for the bot")

        args = parser.parse_args()
        self.volume = self.config.getfloat('bot', 'volume')

        self.channel = args.channel
        var.current_music = None
        var.playlist = []
        var.user = args.user
        var.music_folder = self.config.get('bot', 'music_folder')
        var.filters = self.config['filters']
        var.filter_select = self.config.get('bot', 'filter')
        var.is_proxified = self.config.getboolean("bot", "is_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None

        interface.init_proxy()

        t = threading.Thread(target=start_web_interface)
        t.daemon = True
        t.start()

        self.mumble = pymumble.Mumble(args.host, user=args.user, port=args.port, password=args.password,
                                      debug=self.config.getboolean('debug', 'mumbleConnection'))
        self.mumble.callbacks.set_callback("text_received", self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # be sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.loop()
Ejemplo n.º 2
0
def start_web_interface(addr, port):
    global formatter
    import interface

    # setup logger
    werkzeug_logger = logging.getLogger('werkzeug')
    logfile = util.solve_filepath(var.config.get('webinterface', 'web_logfile'))
    if logfile:
        handler = logging.handlers.RotatingFileHandler(logfile, mode='a', maxBytes=10240)  # Rotate after 10KB
    else:
        handler = logging.StreamHandler()

    werkzeug_logger.addHandler(handler)

    interface.init_proxy()
    interface.web.env = 'development'
    interface.web.run(port=port, host=addr)
Ejemplo n.º 3
0
    def __init__(self, args):
        signal.signal(signal.SIGINT, self.ctrl_caught)
        self.volume = var.config.getfloat('bot', 'volume')
        if db.has_option('bot', 'volume'):
            self.volume = var.db.getfloat('bot', 'volume')

        self.channel = args.channel

        # Set specific format for the log
        FORMAT = '%(asctime)s: %(message)s'
        if args.verbose:
            logging.basicConfig(format=FORMAT, level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S')
            logging.debug("Starting in DEBUG loglevel")
        elif args.quiet:
            logging.basicConfig(format=FORMAT, level=logging.ERROR, datefmt='%Y-%m-%d %H:%M:%S')
            logging.error("Starting in ERROR loglevel")
        else:
            logging.basicConfig(format=FORMAT, level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S')
            logging.info("Starting in INFO loglevel")

        # the playlist is... a list (Surprise !!)
        var.playlist = []

        var.user = args.user
        var.music_folder = var.config.get('bot', 'music_folder')
        var.is_proxified = var.config.getboolean("webinterface", "is_web_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None
        self.is_playing = False

        if var.config.getboolean("webinterface", "enabled"):
            wi_addr = var.config.get("webinterface", "listening_addr")
            wi_port = var.config.getint("webinterface", "listening_port")
            interface.init_proxy()
            tt = threading.Thread(target=start_web_interface, args=(wi_addr, wi_port))
            tt.daemon = True
            tt.start()

        if args.host:
            host = args.host
        else:
            host = var.config.get("server", "host")

        if args.port:
            port = args.port
        else:
            port = var.config.getint("server", "port")

        if args.password:
            password = args.password
        else:
            password = var.config.get("server", "password")

        if args.certificate:
            certificate = args.certificate
        else:
            certificate = var.config.get("server", "certificate")

        if args.tokens:
            tokens = args.tokens
        else:
            tokens = var.config.get("server", "tokens")
            tokens = tokens.split(',')

        if args.user:
            self.username = args.user
        else:
            self.username = var.config.get("bot", "username")

        self.mumble = pymumble.Mumble(host, user=self.username, port=port, password=password, tokens=tokens,
                                      debug=var.config.getboolean('debug', 'mumbleConnection'), certfile=certificate)
        self.mumble.callbacks.set_callback("text_received", self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.loop()
Ejemplo n.º 4
0
    def __init__(self, args):
        signal.signal(signal.SIGINT, self.ctrl_caught)
        self.volume = var.config.getfloat('bot', 'volume')
        self.channel = args.channel
        var.current_music = {}

        FORMAT = '%(asctime)s: %(message)s'
        if args.quiet:
            logging.basicConfig(format=FORMAT,
                                level=logging.ERROR,
                                datefmt='%Y-%m-%d %H:%M:%S')
        else:
            logging.basicConfig(format=FORMAT,
                                level=logging.DEBUG,
                                datefmt='%Y-%m-%d %H:%M:%S')

        ######
        ## Format of the Playlist :
        ## [("<type>","<path/url>")]
        ## types : file, radio, url, is_playlist, number_music_to_play
        ######

        ######
        ## Format of the current_music variable
        # var.current_music = { "type" : str,
        #                       "path" : str,                 # path of the file to play
        #                       "url" : str                   # url to download
        #                       "title" : str,
        #                       "user" : str,
        #                       "is_playlist": boolean,
        #                       "number_track_to_play": int,  # FOR PLAYLIST ONLY
        #                       "start_index" : int,          # FOR PLAYLIST ONLY
        #                       "current_index" : int}        # FOR PLAYLIST ONLY
        # len(var.current_music) = 6

        var.playlist = []

        var.user = args.user
        var.music_folder = var.config.get('bot', 'music_folder')
        var.is_proxified = var.config.getboolean("webinterface",
                                                 "is_web_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None
        self.playing = False

        if var.config.getboolean("webinterface", "enabled"):
            wi_addr = var.config.get("webinterface", "listening_addr")
            wi_port = var.config.getint("webinterface", "listening_port")
            interface.init_proxy()
            tt = threading.Thread(target=start_web_interface,
                                  args=(wi_addr, wi_port))
            tt.daemon = True
            tt.start()

        if args.host:
            host = args.host
        else:
            host = var.config.get("server", "host")
        if args.port:
            port = args.port
        else:
            port = var.config.getint("server", "port")
        if args.password:
            password = args.password
        else:
            password = var.config.get("server", "password")

        if args.user:
            username = args.user
        else:
            username = var.config.get("bot", "username")

        self.mumble = pymumble.Mumble(host,
                                      user=username,
                                      port=port,
                                      password=password,
                                      debug=var.config.getboolean(
                                          'debug', 'mumbleConnection'))
        self.mumble.callbacks.set_callback("text_received",
                                           self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.loop()
Ejemplo n.º 5
0
    def __init__(self, args):
        signal.signal(signal.SIGINT, self.ctrl_caught)

        self.volume = var.config.getfloat('bot', 'volume')
        self.channel = args.channel
        var.current_music = None

        FORMAT = '%(asctime)s: %(message)s'
        if args.quiet:
            logging.basicConfig(format=FORMAT,
                                level=logging.ERROR,
                                datefmt='%Y-%m-%d %H:%M:%S')
        else:
            logging.basicConfig(format=FORMAT,
                                level=logging.DEBUG,
                                datefmt='%Y-%m-%d %H:%M:%S')

        ######
        ## Format of the Playlist :
        ## [("<type>","<path>")]
        ## [("<radio>","<luna>"), ("<youtube>","<url>")]
        ## types : file, radio, url
        ######

        ######
        ## Format of the current_music variable
        # len(var.current_music) = 4
        # var.current_music[0] = <Type>
        # var.current_music[1] = <url> if url of radio
        # var.current_music[2] = <title>
        # var.current_music[3] = <path> if url or file

        var.playlist = []

        var.user = args.user
        var.music_folder = var.config.get('bot', 'music_folder')
        var.is_proxified = var.config.getboolean("webinterface",
                                                 "is_web_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None

        if var.config.getboolean("webinterface", "enabled"):
            wi_addr = var.config.get("webinterface", "listening_addr")
            wi_port = var.config.getint("webinterface", "listening_port")
            interface.init_proxy()
            tt = threading.Thread(target=start_web_interface,
                                  args=(wi_addr, wi_port))
            tt.daemon = True
            tt.start()

        self.mumble = pymumble.Mumble(args.host,
                                      user=args.user,
                                      port=args.port,
                                      password=args.password,
                                      debug=var.config.getboolean(
                                          'debug', 'mumbleConnection'))
        self.mumble.callbacks.set_callback("text_received",
                                           self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.loop()
Ejemplo n.º 6
0
    def __init__(self):
        signal.signal(signal.SIGINT, self.ctrl_caught)

        self.config = configparser.ConfigParser(interpolation=None)
        self.config.read("configuration.ini", encoding='latin-1')

        parser = argparse.ArgumentParser(
            description='Bot for playing radio stream on Mumble')
        parser.add_argument("-s",
                            "--server",
                            dest="host",
                            type=str,
                            required=True,
                            help="The server's hostame of a mumble server")
        parser.add_argument("-u",
                            "--user",
                            dest="user",
                            type=str,
                            required=True,
                            help="Username you wish, Default=abot")
        parser.add_argument("-P",
                            "--password",
                            dest="password",
                            type=str,
                            default="",
                            help="Password if server requires one")
        parser.add_argument("-p",
                            "--port",
                            dest="port",
                            type=int,
                            default=64738,
                            help="Port for the mumble server")
        parser.add_argument("-c",
                            "--channel",
                            dest="channel",
                            type=str,
                            default="",
                            help="Default chanel for the bot")
        parser.add_argument("-q",
                            "--quiet",
                            dest="quiet",
                            action="store_true",
                            help="Only Error logs")

        args = parser.parse_args()
        self.volume = self.config.getfloat('bot', 'volume')

        self.channel = args.channel
        var.current_music = None

        FORMAT = '%(asctime)s: %(message)s'
        if args.quiet:
            logging.basicConfig(format=FORMAT,
                                level=logging.ERROR,
                                datefmt='%Y-%m-%d %H:%M:%S')
        else:
            logging.basicConfig(format=FORMAT,
                                level=logging.DEBUG,
                                datefmt='%Y-%m-%d %H:%M:%S')

        ######
        ## Format of the Playlist :
        ## [("<type>","<path>")]
        ## [("<radio>","<luna>"), ("<youtube>","<url>")]
        ## types : file, radio, url
        ######

        ######
        ## Format of the current_music variable
        # len(var.current_music) = 4
        # var.current_music[0] = <Type>
        # var.current_music[1] = <url> if url of radio
        # var.current_music[2] = <title>
        # var.current_music[3] = <path> if url or file

        var.playlist = []

        var.user = args.user
        var.music_folder = self.config.get('bot', 'music_folder')
        var.is_proxified = self.config.getboolean("bot", "is_web_proxified")

        self.exit = False
        self.nb_exit = 0
        self.thread = None

        if self.config.getboolean("bot", "web_interface"):
            interface.init_proxy()
            t = threading.Thread(target=start_web_interface)
            t.daemon = True
            t.start()

        self.mumble = pymumble.Mumble(args.host,
                                      user=args.user,
                                      port=args.port,
                                      password=args.password,
                                      debug=self.config.getboolean(
                                          'debug', 'mumbleConnection'))
        self.mumble.callbacks.set_callback("text_received",
                                           self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.loop()
Ejemplo n.º 7
0
    def __init__(self, args):
        signal.signal(signal.SIGINT, self.ctrl_caught)
        self.cmd_handle = {}
        self.volume_set = var.config.getfloat('bot', 'volume')
        if var.db.has_option('bot', 'volume'):
            self.volume_set = var.db.getfloat('bot', 'volume')

        self.volume = self.volume_set

        self.channel = args.channel

        if args.verbose:
            root.setLevel(logging.DEBUG)
            logging.debug("Starting in DEBUG loglevel")
        elif args.quiet:
            root.setLevel(logging.ERROR)
            logging.error("Starting in ERROR loglevel")

        var.playlist = PlayList()

        var.user = args.user
        var.music_folder = var.config.get('bot', 'music_folder')
        var.is_proxified = var.config.getboolean("webinterface",
                                                 "is_web_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None
        self.is_playing = False
        self.is_pause = False
        self.playhead = -1
        self.song_start_at = -1

        if var.config.getboolean("webinterface", "enabled"):
            wi_addr = var.config.get("webinterface", "listening_addr")
            wi_port = var.config.getint("webinterface", "listening_port")
            interface.init_proxy()
            tt = threading.Thread(target=start_web_interface,
                                  args=(wi_addr, wi_port))
            tt.daemon = True
            tt.start()

        if args.host:
            host = args.host
        else:
            host = var.config.get("server", "host")

        if args.port:
            port = args.port
        else:
            port = var.config.getint("server", "port")

        if args.password:
            password = args.password
        else:
            password = var.config.get("server", "password")

        if args.certificate:
            certificate = args.certificate
        else:
            certificate = var.config.get("server", "certificate")

        if args.tokens:
            tokens = args.tokens
        else:
            tokens = var.config.get("server", "tokens")
            tokens = tokens.split(',')

        if args.user:
            self.username = args.user
        else:
            self.username = var.config.get("bot", "username")

        self.mumble = pymumble.Mumble(host,
                                      user=self.username,
                                      port=port,
                                      password=password,
                                      tokens=tokens,
                                      debug=var.config.getboolean(
                                          'debug', 'mumbleConnection'),
                                      certfile=certificate)
        self.mumble.callbacks.set_callback(
            pymumble.constants.PYMUMBLE_CLBK_TEXTMESSAGERECEIVED,
            self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.is_ducking = False
        self.on_ducking = False
        self.ducking_release = time.time()


        if not var.db.has_option("bot", "ducking") and var.config.getboolean("bot", "ducking", fallback=False)\
                or var.config.getboolean("bot", "ducking"):
            self.is_ducking = True
            self.ducking_volume = var.config.getfloat("bot",
                                                      "ducking_volume",
                                                      fallback=0.05)
            self.ducking_volume = var.db.getfloat("bot",
                                                  "ducking_volume",
                                                  fallback=self.ducking_volume)
            self.ducking_threshold = var.config.getfloat("bot",
                                                         "ducking_threshold",
                                                         fallback=5000)
            self.ducking_threshold = var.db.getfloat(
                "bot", "ducking_threshold", fallback=self.ducking_threshold)
            self.mumble.callbacks.set_callback(
                pymumble.constants.PYMUMBLE_CLBK_SOUNDRECEIVED,
                self.ducking_sound_received)
            self.mumble.set_receive_sound(True)