Check if a file exists, read metadata. Closes #15
This commit is contained in:
parent
e538c3c9fb
commit
f7ab210b8a
52
mumbleBot.py
52
mumbleBot.py
@ -20,6 +20,7 @@ import util
|
|||||||
import base64
|
import base64
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from mutagen.easyid3 import EasyID3
|
||||||
|
|
||||||
|
|
||||||
class MumbleBot:
|
class MumbleBot:
|
||||||
@ -321,29 +322,34 @@ class MumbleBot:
|
|||||||
def download_music(self, url):
|
def download_music(self, url):
|
||||||
url_hash = hashlib.md5(url.encode()).hexdigest()
|
url_hash = hashlib.md5(url.encode()).hexdigest()
|
||||||
path = var.config.get('bot', 'tmp_folder') + url_hash + ".%(ext)s"
|
path = var.config.get('bot', 'tmp_folder') + url_hash + ".%(ext)s"
|
||||||
ydl_opts = {
|
mp3 = path.replace(".%(ext)s", ".mp3")
|
||||||
'format': 'bestaudio/best',
|
if os.path.isfile(mp3):
|
||||||
'outtmpl': path,
|
audio = EasyID3(mp3)
|
||||||
'noplaylist': True,
|
video_title = audio["title"]
|
||||||
'writethumbnail': True,
|
else:
|
||||||
'updatetime': False,
|
ydl_opts = {
|
||||||
'postprocessors': [{
|
'format': 'bestaudio/best',
|
||||||
'key': 'FFmpegExtractAudio',
|
'outtmpl': path,
|
||||||
'preferredcodec': 'mp3',
|
'noplaylist': True,
|
||||||
'preferredquality': '192'},
|
'writethumbnail': True,
|
||||||
{'key': 'FFmpegMetadata'}]
|
'updatetime': False,
|
||||||
}
|
'postprocessors': [{
|
||||||
video_title = ""
|
'key': 'FFmpegExtractAudio',
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
'preferredcodec': 'mp3',
|
||||||
for i in range(2):
|
'preferredquality': '192'},
|
||||||
try:
|
{'key': 'FFmpegMetadata'}]
|
||||||
info_dict = ydl.extract_info(url)
|
}
|
||||||
video_title = info_dict['title']
|
video_title = ""
|
||||||
except youtube_dl.utils.DownloadError:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
pass
|
for i in range(2):
|
||||||
else:
|
try:
|
||||||
break
|
info_dict = ydl.extract_info(url)
|
||||||
return path.replace(".%(ext)s", ".mp3"), video_title
|
video_title = info_dict['title']
|
||||||
|
except youtube_dl.utils.DownloadError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
return mp3, video_title
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
raw_music = ""
|
raw_music = ""
|
||||||
|
@ -4,3 +4,4 @@ flask
|
|||||||
youtube-dl
|
youtube-dl
|
||||||
python-magic
|
python-magic
|
||||||
Pillow
|
Pillow
|
||||||
|
mutagen
|
||||||
|
Loading…
x
Reference in New Issue
Block a user