Check if a file exists, read metadata. Closes #15

This commit is contained in:
Lartza 2018-06-19 14:27:28 +03:00
parent e538c3c9fb
commit f7ab210b8a
2 changed files with 30 additions and 23 deletions

View File

@ -20,6 +20,7 @@ import util
import base64
from PIL import Image
from io import BytesIO
from mutagen.easyid3 import EasyID3
class MumbleBot:
@ -321,6 +322,11 @@ class MumbleBot:
def download_music(self, url):
url_hash = hashlib.md5(url.encode()).hexdigest()
path = var.config.get('bot', 'tmp_folder') + url_hash + ".%(ext)s"
mp3 = path.replace(".%(ext)s", ".mp3")
if os.path.isfile(mp3):
audio = EasyID3(mp3)
video_title = audio["title"]
else:
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': path,
@ -343,7 +349,7 @@ class MumbleBot:
pass
else:
break
return path.replace(".%(ext)s", ".mp3"), video_title
return mp3, video_title
def loop(self):
raw_music = ""

View File

@ -4,3 +4,4 @@ flask
youtube-dl
python-magic
Pillow
mutagen