1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 12:04:20 +00:00
royalnet/royalpack/commands/peertube.py

25 lines
879 B
Python
Raw Normal View History

from .play import PlayCommand
2019-11-11 08:56:08 +00:00
from royalnet.commands import *
import aiohttp
import urllib.parse
2019-11-11 08:56:08 +00:00
class PeertubeCommand(PlayCommand):
2019-11-11 08:56:08 +00:00
name: str = "peertube"
aliases = ["pt", "royaltube", "rt"]
2019-11-11 08:56:08 +00:00
description: str = "Cerca un video su RoyalTube e lo aggiunge alla coda della chat vocale."
2019-11-11 08:56:08 +00:00
syntax = "{ricerca}"
2019-11-11 08:56:08 +00:00
async def get_url(self, args):
search = urllib.parse.quote(args.joined(require_at_least=1))
2019-11-11 08:56:08 +00:00
async with aiohttp.ClientSession() as session:
async with session.get(self.config["Peertube"]["instance_url"] +
f"/api/v1/search/videos?search={search}") as response:
2019-11-11 08:56:08 +00:00
j = await response.json()
if j["total"] < 1:
raise InvalidInputError("Nessun video trovato.")
return f'{self.config["Peertube"]["instance_url"]}/videos/watch/{j["data"][0]["uuid"]}'