beautified, bugs fixed

This commit is contained in:
Terry Geng 2020-02-06 10:11:48 +08:00
parent 4e905c1c56
commit 9f7a9287a2
4 changed files with 38 additions and 28 deletions

View File

@ -145,7 +145,7 @@ def post():
if os.path.isfile(path):
item = {'type': 'file',
'path' : request.form['add_file_bottom'],
'title' : 'Unknown',
'title' : '',
'user' : 'Web'}
var.playlist.append(var.botamusique.get_music_tag_info(item, path))
logging.info('web: add to playlist(bottom): ' + item['path'])
@ -155,7 +155,7 @@ def post():
if os.path.isfile(path):
item = {'type': 'file',
'path' : request.form['add_file_next'],
'title' : 'Unknown',
'title' : '',
'user' : 'Web'}
var.playlist.insert(
var.playlist.current_index + 1,

View File

@ -631,7 +631,7 @@ class MumbleBot:
else:
music = var.playlist.jump(index)
logging.info("bot: play music " + str(music['path']))
logging.info("bot: play music " + str(music['path'] if 'path' in music else music['url']))
if music["type"] == "url":
# Delete older music is the tmp folder is too big
media.system.clear_tmp_folder(var.config.get(
@ -687,6 +687,7 @@ class MumbleBot:
elif music["type"] == "radio":
uri = music["url"]
logging.info("bot: fetching radio server description")
title = media.radio.get_radio_server_description(uri)
music["title"] = title
if var.config.getboolean('bot', 'announce_current_music'):
@ -782,14 +783,16 @@ class MumbleBot:
# get the Path
if uri == "":
if 'path' in music:
uri = music['path']
else:
return False
if os.path.isfile(uri):
music = self.get_music_tag_info(music, uri)
var.playlist.update(music)
return True
else:
logging.error("Error with the path during launch_music")
return False
def get_music_tag_info(self, music, uri=""):
@ -799,33 +802,39 @@ class MumbleBot:
if os.path.isfile(uri):
try:
audio = EasyID3(uri)
if audio["title"]:
if 'title' in audio:
# take the title from the file tag
music['title'] = audio["title"][0]
if 'artist' in audio:
music['artist'] = ', '.join(audio["artist"])
path_thumbnail = uri[:-3] + "jpg"
im = None
if os.path.isfile(path_thumbnail):
im = Image.open(path_thumbnail)
im.thumbnail((100, 100), Image.ANTIALIAS)
buffer = BytesIO()
im = im.convert('RGB')
im.save(buffer, format="JPEG")
music['thumbnail'] = base64.b64encode(buffer.getvalue()).decode('utf-8')
# try to extract artwork from mp3 ID3 tag
elif uri[-3:] == "mp3":
tags = mutagen.File(uri)
if "APIC:" in tags:
im = Image.open(BytesIO(tags["APIC:"].data))
if im:
im.thumbnail((100, 100), Image.ANTIALIAS)
buffer = BytesIO()
im = im.convert('RGB')
im.save(buffer, format="JPEG")
music['thumbnail'] = base64.b64encode(buffer.getvalue()).decode('utf-8')
return music
except:
pass
# if nothing found
music['title'] = os.path.basename(uri)[:-4]
return music
@ -833,7 +842,8 @@ class MumbleBot:
# Function start if the next music isn't ready
# Do nothing in case the next music is already downloaded
logging.info("bot: Async download next asked ")
if len(var.playlist.playlist) > 1 and var.playlist.next_item()['type'] == 'url' and var.playlist.next_item()['ready'] in ["no", "validation"]:
if len(var.playlist.playlist) > 1 and var.playlist.next_item()['type'] == 'url' \
and var.playlist.next_item()['ready'] in ["no", "validation"]:
th = threading.Thread(
target=self.download_music, kwargs={'index': var.playlist.next_index()})
else:

@ -1 +1 @@
Subproject commit 8ccfb0e7cf7183cc6766591b985dfc1bcf5a2d37
Subproject commit 437d2ebec6e18b5ad69b77020596c250a5e1b785

View File

@ -20,8 +20,8 @@
<div class="playlist-artwork">
{% if 'title' in m and m['title'].strip() %}
<b>{{ m['title'] }}</b>
{% else %}
<b>{{ m['url'] }}</b>
{% elif 'url' in m %}
<b>{{ m['url']|truncate(30) }}</b>
{% endif %}
<span class="badge badge-secondary">{{ m['type'].capitalize() }}</span>
<br>