Fix thumbnail error
This commit is contained in:
32
mumbleBot.py
32
mumbleBot.py
@ -35,10 +35,15 @@ class MumbleBot:
|
|||||||
self.channel = args.channel
|
self.channel = args.channel
|
||||||
|
|
||||||
FORMAT = '%(asctime)s: %(message)s'
|
FORMAT = '%(asctime)s: %(message)s'
|
||||||
if args.quiet:
|
if args.verbose:
|
||||||
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')
|
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")
|
||||||
|
|
||||||
var.playlist = []
|
var.playlist = []
|
||||||
|
|
||||||
@ -335,6 +340,7 @@ class MumbleBot:
|
|||||||
|
|
||||||
def launch_music(self):
|
def launch_music(self):
|
||||||
uri = ""
|
uri = ""
|
||||||
|
logging.debug("launch_music asked" + str(var.playlist[0]))
|
||||||
if var.playlist[0]["type"] == "url":
|
if var.playlist[0]["type"] == "url":
|
||||||
media.system.clear_tmp_folder(var.config.get('bot', 'tmp_folder'), var.config.getint('bot', 'tmp_folder_max_size'))
|
media.system.clear_tmp_folder(var.config.get('bot', 'tmp_folder'), var.config.getint('bot', 'tmp_folder_max_size'))
|
||||||
|
|
||||||
@ -345,14 +351,13 @@ class MumbleBot:
|
|||||||
self.download_music(index=0)
|
self.download_music(index=0)
|
||||||
|
|
||||||
uri = var.playlist[0]['path']
|
uri = var.playlist[0]['path']
|
||||||
|
|
||||||
if os.path.isfile(uri):
|
if os.path.isfile(uri):
|
||||||
audio = EasyID3(uri)
|
audio = EasyID3(uri)
|
||||||
title = ""
|
title = ""
|
||||||
if audio["title"]:
|
if audio["title"]:
|
||||||
title = audio["title"][0]
|
title = audio["title"][0]
|
||||||
|
|
||||||
path_thumbnail = var.config.get('bot', 'tmp_folder') + hashlib.md5(uri.encode()).hexdigest() + '.jpg'
|
path_thumbnail = var.playlist[0]['path'][:-4] + '.jpg' # Remove .mp3 and add .jpg
|
||||||
thumbnail_html = ""
|
thumbnail_html = ""
|
||||||
if os.path.isfile(path_thumbnail):
|
if os.path.isfile(path_thumbnail):
|
||||||
im = Image.open(path_thumbnail)
|
im = Image.open(path_thumbnail)
|
||||||
@ -362,10 +367,11 @@ class MumbleBot:
|
|||||||
thumbnail_base64 = base64.b64encode(buffer.getvalue())
|
thumbnail_base64 = base64.b64encode(buffer.getvalue())
|
||||||
thumbnail_html = '<img - src="data:image/PNG;base64,' + thumbnail_base64.decode() + '"/>'
|
thumbnail_html = '<img - src="data:image/PNG;base64,' + thumbnail_base64.decode() + '"/>'
|
||||||
|
|
||||||
logging.debug(thumbnail_html)
|
logging.debug("Thunbail 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('strings', 'now_playing') % (title, thumbnail_html))
|
self.send_msg(var.config.get('strings', 'now_playing') % (title, thumbnail_html))
|
||||||
else:
|
else:
|
||||||
|
logging.error("Error with the path during launch_music")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif var.playlist[0]["type"] == "file":
|
elif var.playlist[0]["type"] == "file":
|
||||||
@ -391,12 +397,15 @@ class MumbleBot:
|
|||||||
if media.url.get_url_info(index=index):
|
if media.url.get_url_info(index=index):
|
||||||
if var.playlist[index]['duration'] > var.config.getint('bot', 'max_track_duration'):
|
if var.playlist[index]['duration'] > var.config.getint('bot', 'max_track_duration'):
|
||||||
var.playlist.pop()
|
var.playlist.pop()
|
||||||
|
logging.info("the music " + var.playlist[index]["url"] + " has a duration of " + var.playlist[index]['duration'] + "s -- too long")
|
||||||
self.send_msg(var.config.get('strings', 'too_long'))
|
self.send_msg(var.config.get('strings', 'too_long'))
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
var.playlist[index]['ready'] = "no"
|
var.playlist[index]['ready'] = "no"
|
||||||
else:
|
else:
|
||||||
var.playlist.pop(index)
|
var.playlist.pop(index)
|
||||||
self.send_msg(var.config.get('strings', 'unable_download'))
|
logging.error("Error while fetching info from the URL")
|
||||||
|
self.send_msg(var.config.get('strings', 'unable_download'))
|
||||||
|
|
||||||
if var.playlist[index]['type'] == 'url' and var.playlist[index]['ready'] == "no":
|
if var.playlist[index]['type'] == 'url' and var.playlist[index]['ready'] == "no":
|
||||||
var.playlist[index]['ready'] = "downloading"
|
var.playlist[index]['ready'] = "downloading"
|
||||||
@ -515,7 +524,7 @@ class MumbleBot:
|
|||||||
|
|
||||||
|
|
||||||
def start_web_interface(addr, port):
|
def start_web_interface(addr, port):
|
||||||
print('Starting web interface on {}:{}'.format(addr, port))
|
logging.info('Starting web interface on {}:{}'.format(addr, port))
|
||||||
interface.web.run(port=port, host=addr)
|
interface.web.run(port=port, host=addr)
|
||||||
|
|
||||||
|
|
||||||
@ -527,6 +536,7 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument("--db", dest='db', type=str, default='db.ini', help='database file. Default db.ini')
|
parser.add_argument("--db", dest='db', type=str, default='db.ini', help='database file. Default db.ini')
|
||||||
|
|
||||||
parser.add_argument("-q", "--quiet", dest="quiet", action="store_true", help="Only Error logs")
|
parser.add_argument("-q", "--quiet", dest="quiet", action="store_true", help="Only Error logs")
|
||||||
|
parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", help="Show debug log")
|
||||||
|
|
||||||
# Mumble arguments
|
# Mumble arguments
|
||||||
parser.add_argument("-s", "--server", dest="host", type=str, help="Hostname of the Mumble server")
|
parser.add_argument("-s", "--server", dest="host", type=str, help="Hostname of the Mumble server")
|
||||||
@ -544,7 +554,7 @@ if __name__ == '__main__':
|
|||||||
db.read([var.dbfile], encoding='latin-1')
|
db.read([var.dbfile], encoding='latin-1')
|
||||||
|
|
||||||
if len(parsed_configs) == 0:
|
if len(parsed_configs) == 0:
|
||||||
print('Could not read configuration from file \"{}\"'.format(args.config), file=sys.stderr)
|
logging.error('Could not read configuration from file \"{}\"'.format(args.config), file=sys.stderr)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
var.config = config
|
var.config = config
|
||||||
|
Reference in New Issue
Block a user