mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Fix things in the discord embed
This commit is contained in:
parent
31ca3e4556
commit
6b00d3410a
3 changed files with 13 additions and 5 deletions
|
@ -2,8 +2,10 @@ import typing
|
||||||
import logging as _logging
|
import logging as _logging
|
||||||
import discord
|
import discord
|
||||||
import os
|
import os
|
||||||
|
import dateparser
|
||||||
import datetime
|
import datetime
|
||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL
|
||||||
|
from ..utils import ytdldateformat
|
||||||
|
|
||||||
log = _logging.getLogger(__name__)
|
log = _logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ class YtdlInfo:
|
||||||
self.uploader_url: typing.Optional[str] = info.get("uploader_url")
|
self.uploader_url: typing.Optional[str] = info.get("uploader_url")
|
||||||
self.channel_id: typing.Optional[str] = info.get("channel_id")
|
self.channel_id: typing.Optional[str] = info.get("channel_id")
|
||||||
self.channel_url: typing.Optional[str] = info.get("channel_url")
|
self.channel_url: typing.Optional[str] = info.get("channel_url")
|
||||||
self.upload_date: typing.Optional[str] = info.get("upload_date")
|
self.upload_date: typing.Optional[datetime.datetime] = dateparser.parse(ytdldateformat(info.get("upload_date")))
|
||||||
self.license: typing.Optional[str] = info.get("license")
|
self.license: typing.Optional[str] = info.get("license")
|
||||||
self.creator: typing.Optional[...] = info.get("creator")
|
self.creator: typing.Optional[...] = info.get("creator")
|
||||||
self.title: typing.Optional[str] = info.get("title")
|
self.title: typing.Optional[str] = info.get("title")
|
||||||
|
@ -82,7 +84,7 @@ class YtdlInfo:
|
||||||
self.tags: typing.Optional[typing.List[str]] = info.get("tags")
|
self.tags: typing.Optional[typing.List[str]] = info.get("tags")
|
||||||
self.subtitles: typing.Optional[typing.Dict[str, typing.List[typing.Dict[str, str]]]] = info.get("subtitles")
|
self.subtitles: typing.Optional[typing.Dict[str, typing.List[typing.Dict[str, str]]]] = info.get("subtitles")
|
||||||
self.automatic_captions: typing.Optional[dict] = info.get("automatic_captions")
|
self.automatic_captions: typing.Optional[dict] = info.get("automatic_captions")
|
||||||
self.duration: typing.Optional[int] = info.get("duration")
|
self.duration: typing.Optional[datetime.timedelta] = datetime.timedelta(seconds=info.get("duration", 0))
|
||||||
self.age_limit: typing.Optional[int] = info.get("age_limit")
|
self.age_limit: typing.Optional[int] = info.get("age_limit")
|
||||||
self.annotations: typing.Optional[...] = info.get("annotations")
|
self.annotations: typing.Optional[...] = info.get("annotations")
|
||||||
self.chapters: typing.Optional[...] = info.get("chapters")
|
self.chapters: typing.Optional[...] = info.get("chapters")
|
||||||
|
@ -150,7 +152,7 @@ class YtdlInfo:
|
||||||
embed.set_author(name=self.uploader, url=self.uploader_url)
|
embed.set_author(name=self.uploader, url=self.uploader_url)
|
||||||
embed.set_footer(text="Fonte: youtube-dl", icon_url="https://i.imgur.com/TSvSRYn.png")
|
embed.set_footer(text="Fonte: youtube-dl", icon_url="https://i.imgur.com/TSvSRYn.png")
|
||||||
embed.add_field(name="Duration", value=str(self.duration), inline=True)
|
embed.add_field(name="Duration", value=str(self.duration), inline=True)
|
||||||
embed.add_field(name="Published on", value=self.upload_date, inline=True)
|
embed.add_field(name="Published on", value=str(self.upload_date), inline=True)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -9,7 +9,7 @@ from .safeformat import safeformat
|
||||||
from .classdictjanitor import cdj
|
from .classdictjanitor import cdj
|
||||||
from .sleepuntil import sleep_until
|
from .sleepuntil import sleep_until
|
||||||
from .networkhandler import NetworkHandler
|
from .networkhandler import NetworkHandler
|
||||||
from .formatters import andformat, plusformat, fileformat
|
from .formatters import andformat, plusformat, fileformat, ytdldateformat
|
||||||
|
|
||||||
__all__ = ["asyncify", "Call", "Command", "safeformat", "cdj", "sleep_until", "plusformat", "CommandArgs",
|
__all__ = ["asyncify", "Call", "Command", "safeformat", "cdj", "sleep_until", "plusformat", "CommandArgs",
|
||||||
"NetworkHandler", "andformat", "plusformat", "fileformat"]
|
"NetworkHandler", "andformat", "plusformat", "fileformat", "ytdldateformat"]
|
||||||
|
|
|
@ -38,3 +38,9 @@ def plusformat(i: int) -> str:
|
||||||
def fileformat(string: str) -> str:
|
def fileformat(string: str) -> str:
|
||||||
"""Ensure a string can be used as a filename by replacing all non-word characters with underscores."""
|
"""Ensure a string can be used as a filename by replacing all non-word characters with underscores."""
|
||||||
return re.sub(r"\W", "_", string)
|
return re.sub(r"\W", "_", string)
|
||||||
|
|
||||||
|
|
||||||
|
def ytdldateformat(string: typing.Optional[str], separator: str = "-") -> str:
|
||||||
|
if string is None:
|
||||||
|
return ""
|
||||||
|
return f"{string[0:4]}-{string[4:6]}-{string[6:8]}"
|
||||||
|
|
Loading…
Reference in a new issue