1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Add videoinfo command

This commit is contained in:
Steffo 2019-04-14 17:31:30 +02:00
parent a1193f320a
commit 034c0d0edc
5 changed files with 43 additions and 3 deletions

View file

@ -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)

View file

@ -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"]

View file

@ -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"<YtdlInfo of {self.title}>"
if self.webpage_url:
return f"<YtdlInfo for {self.webpage_url}>"
return f"<YtdlInfo id={self.id} ...>"
def __str__(self):
if self.title:
return self.title
if self.webpage_url:
return self.webpage_url
return self.id

View file

@ -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"]

View file

@ -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)