42 lines
1.8 KiB
Python
42 lines
1.8 KiB
Python
"""Independent Kaizoku provider implementation behind a capability contract."""
|
|
import subprocess
|
|
from flask import Blueprint, render_template
|
|
from web_framework.plugins import Plugin, Setting, get_plugins
|
|
from web_framework.plugin_runtime import Service, text, integer
|
|
from . import bridge
|
|
|
|
bp = Blueprint('plugin_anime_providers', __name__, template_folder='templates')
|
|
|
|
|
|
class Providers(Service):
|
|
plugin_id = 'anime-providers'
|
|
|
|
def call(self, command, provider, *args):
|
|
self.check()
|
|
if provider not in bridge.PROVIDERS:
|
|
raise ValueError('Choose Anikoto, AnimePahe, or legacy AniNeko.')
|
|
try:
|
|
return bridge.bridge(command, provider, *args, timeout=90)
|
|
except (OSError, bridge.ProviderError):
|
|
raise ValueError('Anime provider request failed. Check Node.js/dependencies and provider availability.') from None
|
|
|
|
def search(self, query, *, provider='anikoto', page=1):
|
|
return self.call('search', provider, text(query, 'Search', 200), integer(page, 'Page', 1, 100))
|
|
|
|
def info(self, identifier, *, provider='anikoto'):
|
|
actual, value = bridge.parse_provider_id(text(identifier, 'Provider ID', 2000), provider)
|
|
return self.call('info', actual, value)
|
|
|
|
def episodes(self, identifier, *, provider='anikoto'):
|
|
actual, value = bridge.parse_provider_id(text(identifier, 'Provider ID', 2000), provider)
|
|
return self.call('episodes', actual, value).get('episodes', [])
|
|
|
|
|
|
@bp.get('/')
|
|
def index():
|
|
return render_template('anime-providers/index.html', title='Anime Providers')
|
|
|
|
|
|
plugin = Plugin('anime-providers', 'Anime Providers', description='Kaizoku anime provider adapters with a replaceable internal API.', blueprint=bp,
|
|
endpoint='plugin_anime_providers.index', services={'anime-provider': Providers})
|