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

27 lines
906 B
Python
Raw Normal View History

2020-05-10 22:46:12 +00:00
from typing import *
import royalnet.commands as rc
import aiohttp
import urllib.parse
2019-11-11 08:56:08 +00:00
2020-05-10 22:46:12 +00:00
from .play import PlayCommand
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
2020-03-29 19:19:58 +00:00
async def get_urls(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:
2020-05-10 22:46:12 +00:00
raise rc.InvalidInputError("Nessun video trovato.")
2020-03-29 19:19:58 +00:00
return [f'{self.config["Peertube"]["instance_url"]}/videos/watch/{j["data"][0]["uuid"]}']