Speed updatabase generation. Generate and use a certificate by default.
This commit is contained in:
31
media/url.py
31
media/url.py
@@ -1,4 +1,4 @@
|
||||
#
|
||||
#
|
||||
# Bragi - A Mumble music bot
|
||||
# Forked from botamusique by azlux (https://github.com/azlux/botamusque)
|
||||
#
|
||||
@@ -8,11 +8,8 @@ import logging
|
||||
import os
|
||||
import hashlib
|
||||
import traceback
|
||||
from PIL import Image
|
||||
import yt_dlp as youtube_dl
|
||||
import glob
|
||||
from io import BytesIO
|
||||
import base64
|
||||
|
||||
import util
|
||||
from constants import tr_cli as tr
|
||||
@@ -52,7 +49,6 @@ class URLItem(BaseItem):
|
||||
self.duration = 0
|
||||
self.id = hashlib.md5(url.encode()).hexdigest()
|
||||
self.path = var.tmp_folder + self.id
|
||||
self.thumbnail = ""
|
||||
self.keywords = ""
|
||||
else:
|
||||
super().__init__(from_dict)
|
||||
@@ -60,7 +56,6 @@ class URLItem(BaseItem):
|
||||
self.duration = from_dict['duration']
|
||||
self.path = from_dict['path']
|
||||
self.title = from_dict['title']
|
||||
self.thumbnail = from_dict['thumbnail']
|
||||
|
||||
self.downloading = False
|
||||
self.type = "url"
|
||||
@@ -194,7 +189,6 @@ class URLItem(BaseItem):
|
||||
'format': 'bestaudio/best',
|
||||
'outtmpl': base_path,
|
||||
'noplaylist': True,
|
||||
'writethumbnail': True,
|
||||
'updatetime': False,
|
||||
'verbose': var.config.getboolean('debug', 'youtube_dl'),
|
||||
'postprocessors': [{
|
||||
@@ -232,7 +226,6 @@ class URLItem(BaseItem):
|
||||
self.log.info(
|
||||
"bot: finished downloading url (%s) %s, saved to %s." % (self.title, self.url, self.path))
|
||||
self.downloading = False
|
||||
self._read_thumbnail_from_file(base_path + ".jpg")
|
||||
self.version += 1 # notify wrapper to save me
|
||||
return True
|
||||
else:
|
||||
@@ -242,18 +235,6 @@ class URLItem(BaseItem):
|
||||
self.downloading = False
|
||||
raise PreparationFailedError(tr('unable_download', item=self.format_title()))
|
||||
|
||||
def _read_thumbnail_from_file(self, path_thumbnail):
|
||||
if os.path.isfile(path_thumbnail):
|
||||
im = Image.open(path_thumbnail)
|
||||
self.thumbnail = self._prepare_thumbnail(im)
|
||||
|
||||
def _prepare_thumbnail(self, im):
|
||||
im.thumbnail((100, 100), Image.LANCZOS)
|
||||
buffer = BytesIO()
|
||||
im = im.convert('RGB')
|
||||
im.save(buffer, format="JPEG")
|
||||
return base64.b64encode(buffer.getvalue()).decode('utf-8')
|
||||
|
||||
def to_dict(self):
|
||||
dict = super().to_dict()
|
||||
dict['type'] = 'url'
|
||||
@@ -261,7 +242,6 @@ class URLItem(BaseItem):
|
||||
dict['duration'] = self.duration
|
||||
dict['path'] = self.path
|
||||
dict['title'] = self.title
|
||||
dict['thumbnail'] = self.thumbnail
|
||||
|
||||
return dict
|
||||
|
||||
@@ -280,14 +260,7 @@ class URLItem(BaseItem):
|
||||
return self.url
|
||||
|
||||
def format_current_playing(self, user):
|
||||
display = tr("now_playing", item=self.format_song_string(user))
|
||||
|
||||
if self.thumbnail:
|
||||
thumbnail_html = '<img width="80" src="data:image/jpge;base64,' + \
|
||||
self.thumbnail + '"/>'
|
||||
display += "<br />" + thumbnail_html
|
||||
|
||||
return display
|
||||
return tr("now_playing", item=self.format_song_string(user))
|
||||
|
||||
def format_title(self):
|
||||
return self.title if self.title else self.url
|
||||
|
||||
Reference in New Issue
Block a user