logfile and reload youtube-dl
This commit is contained in:
parent
dddabc94ca
commit
eb24594d54
37
mumbleBot.py
37
mumbleBot.py
@ -56,7 +56,7 @@ type : file
|
|||||||
user
|
user
|
||||||
"""
|
"""
|
||||||
|
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
|
|
||||||
class MumbleBot:
|
class MumbleBot:
|
||||||
@ -70,18 +70,18 @@ class MumbleBot:
|
|||||||
|
|
||||||
# Set specific format for the log
|
# Set specific format for the log
|
||||||
FORMAT = '%(asctime)s: %(message)s'
|
FORMAT = '%(asctime)s: %(message)s'
|
||||||
|
loglevel = logging.INFO
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
logging.basicConfig(
|
loglevel = logging.DEBUG
|
||||||
format=FORMAT, level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S')
|
|
||||||
logging.debug("Starting in DEBUG loglevel")
|
logging.debug("Starting in DEBUG loglevel")
|
||||||
elif args.quiet:
|
elif args.quiet:
|
||||||
logging.basicConfig(
|
loglevel = logging.ERROR
|
||||||
format=FORMAT, level=logging.ERROR, datefmt='%Y-%m-%d %H:%M:%S')
|
|
||||||
logging.error("Starting in ERROR loglevel")
|
logging.error("Starting in ERROR loglevel")
|
||||||
|
logfile = var.config.get('bot', 'logfile')
|
||||||
|
if logfile:
|
||||||
|
logging.basicConfig(filename=logfile,format=FORMAT, level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S')
|
||||||
else:
|
else:
|
||||||
logging.basicConfig(
|
logging.basicConfig(format=FORMAT, level=loglevel, datefmt='%Y-%m-%d %H:%M:%S')
|
||||||
format=FORMAT, level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S')
|
|
||||||
logging.info("Starting in INFO loglevel")
|
|
||||||
|
|
||||||
# the playlist is... a list (Surprise !!)
|
# the playlist is... a list (Surprise !!)
|
||||||
var.playlist = []
|
var.playlist = []
|
||||||
@ -137,8 +137,7 @@ class MumbleBot:
|
|||||||
|
|
||||||
self.mumble = pymumble.Mumble(host, user=self.username, port=port, password=password, tokens=tokens,
|
self.mumble = pymumble.Mumble(host, user=self.username, port=port, password=password, tokens=tokens,
|
||||||
debug=var.config.getboolean('debug', 'mumbleConnection'), certfile=certificate)
|
debug=var.config.getboolean('debug', 'mumbleConnection'), certfile=certificate)
|
||||||
self.mumble.callbacks.set_callback(
|
self.mumble.callbacks.set_callback(pymumble.constants.PYMUMBLE_CLBK_TEXTMESSAGERECEIVED, self.message_received)
|
||||||
"text_received", self.message_received)
|
|
||||||
|
|
||||||
self.mumble.set_codec_profile("audio")
|
self.mumble.set_codec_profile("audio")
|
||||||
self.mumble.start() # start the mumble thread
|
self.mumble.start() # start the mumble thread
|
||||||
@ -447,8 +446,8 @@ class MumbleBot:
|
|||||||
if url != "-1":
|
if url != "-1":
|
||||||
logging.info('Found url: ' + url)
|
logging.info('Found url: ' + url)
|
||||||
music = {'type': 'radio',
|
music = {'type': 'radio',
|
||||||
'url': url,
|
'url': url,
|
||||||
'user': user}
|
'user': user}
|
||||||
var.playlist.append(music)
|
var.playlist.append(music)
|
||||||
self.async_download_next()
|
self.async_download_next()
|
||||||
else:
|
else:
|
||||||
@ -572,8 +571,7 @@ class MumbleBot:
|
|||||||
'strings', 'queue_contents') + '<br />'
|
'strings', 'queue_contents') + '<br />'
|
||||||
i = 1
|
i = 1
|
||||||
for value in var.playlist[1:]:
|
for value in var.playlist[1:]:
|
||||||
msg += '[{}] ({}) {}<br />'.format(i, value['type'],
|
msg += '[{}] ({}) {}<br />'.format(i, value['type'], value['title'] if 'title' in value else value['url'])
|
||||||
value['title'] if 'title' in value else value['url'])
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
self.send_msg(msg, text)
|
self.send_msg(msg, text)
|
||||||
@ -639,10 +637,10 @@ class MumbleBot:
|
|||||||
buffer = BytesIO()
|
buffer = BytesIO()
|
||||||
im.save(buffer, format="JPEG")
|
im.save(buffer, format="JPEG")
|
||||||
thumbnail_base64 = base64.b64encode(buffer.getvalue())
|
thumbnail_base64 = base64.b64encode(buffer.getvalue())
|
||||||
thumbnail_html = '<img - src="data:image/PNG;base64,' + \
|
thumbnail_html = '<img src="data:image/PNG;base64,' + \
|
||||||
thumbnail_base64.decode() + '"/>'
|
thumbnail_base64.decode() + '"/>'
|
||||||
|
|
||||||
logging.debug("Thunbail data " + thumbnail_html)
|
logging.debug("Thumbail data " + thumbnail_html)
|
||||||
if var.config.getboolean('bot', 'announce_current_music'):
|
if var.config.getboolean('bot', 'announce_current_music'):
|
||||||
self.send_msg(var.config.get(
|
self.send_msg(var.config.get(
|
||||||
'strings', 'now_playing') % (title, thumbnail_html))
|
'strings', 'now_playing') % (title, thumbnail_html))
|
||||||
@ -818,6 +816,7 @@ class MumbleBot:
|
|||||||
self.mumble.users.myself.comment(var.config.get('bot', 'comment'))
|
self.mumble.users.myself.comment(var.config.get('bot', 'comment'))
|
||||||
|
|
||||||
def send_msg(self, msg, text=None):
|
def send_msg(self, msg, text=None):
|
||||||
|
msg = msg.encode('utf-8', 'ignore').decode('utf-8')
|
||||||
# text if the object message, contain information if direct message or channel message
|
# text if the object message, contain information if direct message or channel message
|
||||||
if not text or not text.session:
|
if not text or not text.session:
|
||||||
own_channel = self.mumble.channels[self.mumble.users.myself['channel_id']]
|
own_channel = self.mumble.channels[self.mumble.users.myself['channel_id']]
|
||||||
@ -866,11 +865,11 @@ if __name__ == '__main__':
|
|||||||
var.dbfile = args.db
|
var.dbfile = args.db
|
||||||
config = configparser.ConfigParser(interpolation=None, allow_no_value=True)
|
config = configparser.ConfigParser(interpolation=None, allow_no_value=True)
|
||||||
parsed_configs = config.read(
|
parsed_configs = config.read(
|
||||||
['configuration.default.ini', args.config], encoding='latin-1')
|
['configuration.default.ini', args.config], encoding='utf-8')
|
||||||
|
|
||||||
db = configparser.ConfigParser(
|
db = configparser.ConfigParser(
|
||||||
interpolation=None, allow_no_value=True, delimiters='²')
|
interpolation=None, allow_no_value=True, delimiters='²')
|
||||||
db.read(var.dbfile, encoding='latin-1')
|
db.read(var.dbfile, encoding='utf-8')
|
||||||
|
|
||||||
if 'url_ban' not in db.sections():
|
if 'url_ban' not in db.sections():
|
||||||
db.add_section('url_ban')
|
db.add_section('url_ban')
|
||||||
@ -886,4 +885,4 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
var.config = config
|
var.config = config
|
||||||
var.db = db
|
var.db = db
|
||||||
botamusique = MumbleBot(args)
|
botamusique = MumbleBot(args)
|
7
util.py
7
util.py
@ -8,7 +8,8 @@ import zipfile
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
import logging
|
import logging
|
||||||
|
import youtube_dl
|
||||||
|
from importlib import reload
|
||||||
|
|
||||||
def get_recursive_filelist_sorted(path):
|
def get_recursive_filelist_sorted(path):
|
||||||
filelist = []
|
filelist = []
|
||||||
@ -99,6 +100,8 @@ def update(version):
|
|||||||
msg += "Youtube-dl is up-to-date"
|
msg += "Youtube-dl is up-to-date"
|
||||||
else:
|
else:
|
||||||
msg += "Update done : " + tp.split('Successfully installed')[1]
|
msg += "Update done : " + tp.split('Successfully installed')[1]
|
||||||
|
reload(youtube_dl)
|
||||||
|
msg += "<br/> Youtube-dl reloaded"
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
@ -213,7 +216,7 @@ class Dir(object):
|
|||||||
|
|
||||||
for key, val in self.subdirs.items():
|
for key, val in self.subdirs.items():
|
||||||
files.extend(map(lambda file: key + '/' + file, val.get_files_recursively()))
|
files.extend(map(lambda file: key + '/' + file, val.get_files_recursively()))
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def render_text(self, ident=0):
|
def render_text(self, ident=0):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user