diff --git a/interface.py b/interface.py index 6622e16..e5612be 100644 --- a/interface.py +++ b/interface.py @@ -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, diff --git a/mumbleBot.py b/mumbleBot.py index b92dd3c..a3ede1f 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -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 == "": - uri = music['path'] + 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" - 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') + path_thumbnail = uri[:-3] + "jpg" + im = None - # 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)) - 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') + if os.path.isfile(path_thumbnail): + im = Image.open(path_thumbnail) + + # 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: diff --git a/pymumble b/pymumble index 8ccfb0e..437d2eb 160000 --- a/pymumble +++ b/pymumble @@ -1 +1 @@ -Subproject commit 8ccfb0e7cf7183cc6766591b985dfc1bcf5a2d37 +Subproject commit 437d2ebec6e18b5ad69b77020596c250a5e1b785 diff --git a/templates/playlist.html b/templates/playlist.html index c2bd5a1..56fa489 100644 --- a/templates/playlist.html +++ b/templates/playlist.html @@ -20,8 +20,8 @@