beautified, bugs fixed
This commit is contained in:
parent
4e905c1c56
commit
9f7a9287a2
@ -145,7 +145,7 @@ def post():
|
|||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
item = {'type': 'file',
|
item = {'type': 'file',
|
||||||
'path' : request.form['add_file_bottom'],
|
'path' : request.form['add_file_bottom'],
|
||||||
'title' : 'Unknown',
|
'title' : '',
|
||||||
'user' : 'Web'}
|
'user' : 'Web'}
|
||||||
var.playlist.append(var.botamusique.get_music_tag_info(item, path))
|
var.playlist.append(var.botamusique.get_music_tag_info(item, path))
|
||||||
logging.info('web: add to playlist(bottom): ' + item['path'])
|
logging.info('web: add to playlist(bottom): ' + item['path'])
|
||||||
@ -155,7 +155,7 @@ def post():
|
|||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
item = {'type': 'file',
|
item = {'type': 'file',
|
||||||
'path' : request.form['add_file_next'],
|
'path' : request.form['add_file_next'],
|
||||||
'title' : 'Unknown',
|
'title' : '',
|
||||||
'user' : 'Web'}
|
'user' : 'Web'}
|
||||||
var.playlist.insert(
|
var.playlist.insert(
|
||||||
var.playlist.current_index + 1,
|
var.playlist.current_index + 1,
|
||||||
|
28
mumbleBot.py
28
mumbleBot.py
@ -631,7 +631,7 @@ class MumbleBot:
|
|||||||
else:
|
else:
|
||||||
music = var.playlist.jump(index)
|
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":
|
if music["type"] == "url":
|
||||||
# Delete older music is the tmp folder is too big
|
# Delete older music is the tmp folder is too big
|
||||||
media.system.clear_tmp_folder(var.config.get(
|
media.system.clear_tmp_folder(var.config.get(
|
||||||
@ -687,6 +687,7 @@ class MumbleBot:
|
|||||||
|
|
||||||
elif music["type"] == "radio":
|
elif music["type"] == "radio":
|
||||||
uri = music["url"]
|
uri = music["url"]
|
||||||
|
logging.info("bot: fetching radio server description")
|
||||||
title = media.radio.get_radio_server_description(uri)
|
title = media.radio.get_radio_server_description(uri)
|
||||||
music["title"] = title
|
music["title"] = title
|
||||||
if var.config.getboolean('bot', 'announce_current_music'):
|
if var.config.getboolean('bot', 'announce_current_music'):
|
||||||
@ -782,14 +783,16 @@ class MumbleBot:
|
|||||||
|
|
||||||
# get the Path
|
# get the Path
|
||||||
if uri == "":
|
if uri == "":
|
||||||
|
if 'path' in music:
|
||||||
uri = music['path']
|
uri = music['path']
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
if os.path.isfile(uri):
|
if os.path.isfile(uri):
|
||||||
music = self.get_music_tag_info(music, uri)
|
music = self.get_music_tag_info(music, uri)
|
||||||
var.playlist.update(music)
|
var.playlist.update(music)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logging.error("Error with the path during launch_music")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_music_tag_info(self, music, uri=""):
|
def get_music_tag_info(self, music, uri=""):
|
||||||
@ -799,33 +802,39 @@ class MumbleBot:
|
|||||||
if os.path.isfile(uri):
|
if os.path.isfile(uri):
|
||||||
try:
|
try:
|
||||||
audio = EasyID3(uri)
|
audio = EasyID3(uri)
|
||||||
if audio["title"]:
|
if 'title' in audio:
|
||||||
# take the title from the file tag
|
# take the title from the file tag
|
||||||
music['title'] = audio["title"][0]
|
music['title'] = audio["title"][0]
|
||||||
|
|
||||||
|
if 'artist' in audio:
|
||||||
music['artist'] = ', '.join(audio["artist"])
|
music['artist'] = ', '.join(audio["artist"])
|
||||||
|
|
||||||
path_thumbnail = uri[:-3] + "jpg"
|
path_thumbnail = uri[:-3] + "jpg"
|
||||||
|
im = None
|
||||||
|
|
||||||
if os.path.isfile(path_thumbnail):
|
if os.path.isfile(path_thumbnail):
|
||||||
im = Image.open(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
|
# try to extract artwork from mp3 ID3 tag
|
||||||
elif uri[-3:] == "mp3":
|
elif uri[-3:] == "mp3":
|
||||||
tags = mutagen.File(uri)
|
tags = mutagen.File(uri)
|
||||||
if "APIC:" in tags:
|
if "APIC:" in tags:
|
||||||
im = Image.open(BytesIO(tags["APIC:"].data))
|
im = Image.open(BytesIO(tags["APIC:"].data))
|
||||||
|
|
||||||
|
if im:
|
||||||
im.thumbnail((100, 100), Image.ANTIALIAS)
|
im.thumbnail((100, 100), Image.ANTIALIAS)
|
||||||
buffer = BytesIO()
|
buffer = BytesIO()
|
||||||
im = im.convert('RGB')
|
im = im.convert('RGB')
|
||||||
im.save(buffer, format="JPEG")
|
im.save(buffer, format="JPEG")
|
||||||
music['thumbnail'] = base64.b64encode(buffer.getvalue()).decode('utf-8')
|
music['thumbnail'] = base64.b64encode(buffer.getvalue()).decode('utf-8')
|
||||||
|
|
||||||
|
return music
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# if nothing found
|
||||||
|
music['title'] = os.path.basename(uri)[:-4]
|
||||||
|
|
||||||
return music
|
return music
|
||||||
|
|
||||||
|
|
||||||
@ -833,7 +842,8 @@ class MumbleBot:
|
|||||||
# Function start if the next music isn't ready
|
# Function start if the next music isn't ready
|
||||||
# Do nothing in case the next music is already downloaded
|
# Do nothing in case the next music is already downloaded
|
||||||
logging.info("bot: Async download next asked ")
|
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(
|
th = threading.Thread(
|
||||||
target=self.download_music, kwargs={'index': var.playlist.next_index()})
|
target=self.download_music, kwargs={'index': var.playlist.next_index()})
|
||||||
else:
|
else:
|
||||||
|
2
pymumble
2
pymumble
@ -1 +1 @@
|
|||||||
Subproject commit 8ccfb0e7cf7183cc6766591b985dfc1bcf5a2d37
|
Subproject commit 437d2ebec6e18b5ad69b77020596c250a5e1b785
|
@ -20,8 +20,8 @@
|
|||||||
<div class="playlist-artwork">
|
<div class="playlist-artwork">
|
||||||
{% if 'title' in m and m['title'].strip() %}
|
{% if 'title' in m and m['title'].strip() %}
|
||||||
<b>{{ m['title'] }}</b>
|
<b>{{ m['title'] }}</b>
|
||||||
{% else %}
|
{% elif 'url' in m %}
|
||||||
<b>{{ m['url'] }}</b>
|
<b>{{ m['url']|truncate(30) }}</b>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="badge badge-secondary">{{ m['type'].capitalize() }}</span>
|
<span class="badge badge-secondary">{{ m['type'].capitalize() }}</span>
|
||||||
<br>
|
<br>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user