diff --git a/royalgames.py b/royalgames.py index 7dafd123..0a31fdf3 100644 --- a/royalgames.py +++ b/royalgames.py @@ -11,7 +11,7 @@ loop = asyncio.get_event_loop() commands = [PingCommand, ShipCommand, SmecdsCommand, ColorCommand, CiaoruoziCommand, DebugCreateCommand, SyncCommand, AuthorCommand, DiarioCommand, RageCommand, DateparserCommand, ReminderCommand, KvactiveCommand, KvCommand, - KvrollCommand] + KvrollCommand, VideoinfoCommand] master = RoyalnetServer("localhost", 1234, "sas") tg_bot = TelegramBot(os.environ["TG_AK"], "localhost:1234", "sas", commands, os.environ["DB_PATH"], Royal, Telegram, "tg_id", error_command=ErrorHandlerCommand) diff --git a/royalnet/audio/__init__.py b/royalnet/audio/__init__.py index ff5ca4be..8d5d7366 100644 --- a/royalnet/audio/__init__.py +++ b/royalnet/audio/__init__.py @@ -1,3 +1,4 @@ from .playmodes import PlayMode, Playlist, Pool +from .youtubedl import YtdlFile, YtdlInfo -__all__ = ["PlayMode", "Playlist", "Pool"] +__all__ = ["PlayMode", "Playlist", "Pool", "YtdlFile", "YtdlInfo"] diff --git a/royalnet/audio/youtubedl.py b/royalnet/audio/youtubedl.py index abeadef0..715f8bef 100644 --- a/royalnet/audio/youtubedl.py +++ b/royalnet/audio/youtubedl.py @@ -129,3 +129,17 @@ class YtdlInfo: def download(self, outtmpl="%(title)s-%(id)s.%(ext)s", progress_hooks=None, **ytdl_args) -> YtdlFile: return YtdlFile(self, outtmpl, progress_hooks=progress_hooks) + + def __repr__(self): + if self.title: + return f"" + if self.webpage_url: + return f"" + return f"" + + def __str__(self): + if self.title: + return self.title + if self.webpage_url: + return self.webpage_url + return self.id diff --git a/royalnet/commands/__init__.py b/royalnet/commands/__init__.py index 33fdb22a..d03da647 100644 --- a/royalnet/commands/__init__.py +++ b/royalnet/commands/__init__.py @@ -13,8 +13,9 @@ from .reminder import ReminderCommand from .kvactive import KvactiveCommand from .kv import KvCommand from .kvroll import KvrollCommand +from .videoinfo import VideoinfoCommand __all__ = ["NullCommand", "PingCommand", "ShipCommand", "SmecdsCommand", "CiaoruoziCommand", "ColorCommand", "SyncCommand", "DiarioCommand", "RageCommand", "DateparserCommand", "AuthorCommand", "ReminderCommand", - "KvactiveCommand", "KvCommand", "KvrollCommand"] + "KvactiveCommand", "KvCommand", "KvrollCommand", "VideoinfoCommand"] diff --git a/royalnet/commands/videoinfo.py b/royalnet/commands/videoinfo.py new file mode 100644 index 00000000..7315fd20 --- /dev/null +++ b/royalnet/commands/videoinfo.py @@ -0,0 +1,24 @@ +import asyncio +from ..utils import Command, Call, asyncify +from ..audio import YtdlInfo + + +class VideoinfoCommand(Command): + + command_name = "videoinfo" + command_description = "Scarica e visualizza le informazioni di un video." + command_syntax = "" + + @classmethod + async def common(cls, call: Call): + url = call.args[0] + info_list = await asyncify(YtdlInfo.create_from_url, url) + for info in info_list: + info_dict = info.__dict__ + message = f"🔍 Dati di [b]{info}[/b]:\n" + for key in __dict__: + if info_dict[key] is None: + continue + message += f"{key}: [b]{info_dict[key]}[/b]\n" + await call.reply(message) + await asyncio.sleep(0.2)