fix: some small issue
This commit is contained in:
@@ -30,7 +30,7 @@ class FileItem(BaseItem):
|
||||
super().__init__(bot)
|
||||
self.path = path
|
||||
self.title = ""
|
||||
self.artist = "??"
|
||||
self.artist = ""
|
||||
self.thumbnail = None
|
||||
if self.path:
|
||||
self.id = hashlib.md5(path.encode()).hexdigest()
|
||||
@@ -132,9 +132,8 @@ class FileItem(BaseItem):
|
||||
return dict
|
||||
|
||||
def format_debug_string(self):
|
||||
return "[file] {artist} - {title} ({path})".format(
|
||||
title=self.title,
|
||||
artist=self.artist,
|
||||
return "[file] {descrip} ({path})".format(
|
||||
descrip=self.format_short_string(),
|
||||
path=self.path
|
||||
)
|
||||
|
||||
@@ -154,5 +153,12 @@ class FileItem(BaseItem):
|
||||
|
||||
return display
|
||||
|
||||
def format_short_string(self):
|
||||
title = self.title if self.title else self.path
|
||||
if self.artist:
|
||||
return self.artist + " - " + title
|
||||
else:
|
||||
return title
|
||||
|
||||
def display_type(self):
|
||||
return constants.strings("file")
|
||||
|
||||
@@ -41,6 +41,7 @@ class BaseItem:
|
||||
self.bot = bot
|
||||
self.log = logging.getLogger("bot")
|
||||
self.type = "base"
|
||||
self.title = ""
|
||||
|
||||
if from_dict is None:
|
||||
self.id = ""
|
||||
@@ -83,6 +84,9 @@ class BaseItem:
|
||||
def format_current_playing(self, user):
|
||||
return self.id
|
||||
|
||||
def format_short_string(self):
|
||||
return self.title
|
||||
|
||||
def format_debug_string(self):
|
||||
return self.id
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import json
|
||||
import random
|
||||
import hashlib
|
||||
import threading
|
||||
import logging
|
||||
|
||||
import util
|
||||
import variables as var
|
||||
from media.item import BaseItem
|
||||
from media.file import FileItem
|
||||
from media.url import URLItem
|
||||
from media.url_from_playlist import PlaylistURLItem
|
||||
from media.radio import RadioItem
|
||||
|
||||
|
||||
class PlaylistItemWrapper:
|
||||
@@ -27,6 +26,9 @@ class PlaylistItemWrapper:
|
||||
def format_song_string(self):
|
||||
return self.item.format_song_string(self.user)
|
||||
|
||||
def format_short_string(self):
|
||||
return self.item.format_short_string()
|
||||
|
||||
def format_debug_string(self):
|
||||
return self.item.format_debug_string()
|
||||
|
||||
@@ -36,6 +38,10 @@ def dict_to_item(dict):
|
||||
return PlaylistItemWrapper(FileItem(var.bot, "", dict), dict['user'])
|
||||
elif dict['type'] == 'url':
|
||||
return PlaylistItemWrapper(URLItem(var.bot, "", dict), dict['user'])
|
||||
elif dict['type'] == 'url_from_playlist':
|
||||
return PlaylistItemWrapper(PlaylistURLItem(var.bot, "", "", "", "", dict), dict['user'])
|
||||
elif dict['type'] == 'radio':
|
||||
return PlaylistItemWrapper(RadioItem(var.bot, "", "", dict), dict['user'])
|
||||
|
||||
|
||||
class PlayList(list):
|
||||
@@ -79,7 +85,6 @@ class PlayList(list):
|
||||
if index == -1:
|
||||
index = self.current_index
|
||||
|
||||
item = util.attach_music_tag_info(item)
|
||||
super().insert(index, item)
|
||||
|
||||
if index <= self.current_index:
|
||||
@@ -95,9 +100,6 @@ class PlayList(list):
|
||||
|
||||
def extend(self, items):
|
||||
self.version += 1
|
||||
items = list(map(
|
||||
lambda item: item,
|
||||
items))
|
||||
super().extend(items)
|
||||
self.pending_items.extend(items)
|
||||
self.start_async_validating()
|
||||
|
||||
@@ -143,8 +143,6 @@ class URLItem(FileItem):
|
||||
'preferredquality': '192'},
|
||||
{'key': 'FFmpegMetadata'}]
|
||||
}
|
||||
# TODO
|
||||
self.send_client_message(constants.strings('download_in_progress', item=self.url))
|
||||
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
attempts = var.config.getint('bot', 'download_attempts', fallback=2)
|
||||
@@ -166,6 +164,7 @@ class URLItem(FileItem):
|
||||
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")
|
||||
return True
|
||||
else:
|
||||
for f in glob.glob(base_path + "*"):
|
||||
@@ -211,5 +210,8 @@ class URLItem(FileItem):
|
||||
|
||||
return display
|
||||
|
||||
def format_short_string(self):
|
||||
return self.title if self.title else self.url
|
||||
|
||||
def display_type(self):
|
||||
return constants.strings("url")
|
||||
|
||||
@@ -3,7 +3,6 @@ import constants
|
||||
import media
|
||||
import variables as var
|
||||
from media.url import URLItem
|
||||
from media.playlist import PlaylistItemWrapper
|
||||
|
||||
def get_playlist_info(bot, url, start_index=0, user=""):
|
||||
items = []
|
||||
@@ -33,15 +32,15 @@ def get_playlist_info(bot, url, start_index=0, user=""):
|
||||
# Add youtube url if the url in the json isn't a full url
|
||||
item_url = info['entries'][j]['url'] if info['entries'][j]['url'][0:4] == 'http' \
|
||||
else "https://www.youtube.com/watch?v=" + info['entries'][j]['url']
|
||||
print(info['entries'][j])
|
||||
|
||||
music = PlaylistItemWrapper(
|
||||
URLFromPlaylistItem(
|
||||
music = PlaylistURLItem(
|
||||
bot,
|
||||
item_url,
|
||||
title,
|
||||
url,
|
||||
playlist_title
|
||||
), user)
|
||||
)
|
||||
|
||||
items.append(music)
|
||||
except:
|
||||
@@ -49,7 +48,7 @@ def get_playlist_info(bot, url, start_index=0, user=""):
|
||||
|
||||
return items
|
||||
|
||||
class URLFromPlaylistItem(URLItem):
|
||||
class PlaylistURLItem(URLItem):
|
||||
def __init__(self, bot, url, title, playlist_url, playlist_title, from_dict=None):
|
||||
if from_dict is None:
|
||||
super().__init__(bot, url)
|
||||
|
||||
Reference in New Issue
Block a user