Module mangdl.providers

Expand source code
from importlib import import_module
from typing import Any, Dict, List

from .api.base import Ch, Manga


class CloudflareProtected(Exception):
    pass

class Provider:
    def __init__(self, prov: str):
        self.prov = import_module(f".{prov}", "mangdl.api.providers")
        if getattr(self.prov, "cloudflare", False):
            raise CloudflareProtected(
                f"""{prov} is protected by Cloudflare's UAM. If you know how to
                bypass Cloudflare, do a pull reqeust at
                https://github.com/MangDL/MangDL/pulls.""".replace('\n', ' ')
            )
        tpl = getattr(
            self.prov,
            "template",
            None
        )
        if tpl:
            self.template = import_module(f".{tpl}", "mangdl.api.providers.templates").template(self.prov)
        else:
            self.template = self.prov

    def chapter(self, url: str) -> Ch:
        local = locals()
        [local.pop(i) for i in ["self",]]
        return self.template.chapter(
            **local,
        )

    def manga(self, url: str, chs: int=0) -> Manga:
        local = locals()
        [local.pop(i) for i in ["self",]]
        return self.template.manga(
            **local,
        )

    def dl_search(self, title: str, **kwargs: Dict[str, Any]) -> Dict[str, str]:
        """Used for downloading when imported.
        Args:
            s (Search): Search dataclass, search parameters for searching.
        Returns:
            Dict[str, str]: Search results.
        """
        local = locals()
        [local.pop(i) for i in ["self",]]
        return self.template.dl_search(
            **local,
        )

    def search(self, title: str, **kwargs: Dict[str, Any]) -> List[Manga]:
        local = locals()
        [local.pop(i) for i in ["self",]]
        op = []
        for i in self.template.dl_search(**local).values():
            op.append(self.template.manga(i))
        return op

    def dl(self, url: str, **kwargs: Dict[str, Any]):
        return self.template.dl(url, **kwargs)

    def cli_dl(self, title: str, **kwargs: Dict[str, Any]):
        return self.template.cli_dl(title, **kwargs)

Classes

class CloudflareProtected (*args, **kwargs)

Common base class for all non-exit exceptions.

Expand source code
class CloudflareProtected(Exception):
    pass

Ancestors

  • builtins.Exception
  • builtins.BaseException
class Provider (prov: str)
Expand source code
class Provider:
    def __init__(self, prov: str):
        self.prov = import_module(f".{prov}", "mangdl.api.providers")
        if getattr(self.prov, "cloudflare", False):
            raise CloudflareProtected(
                f"""{prov} is protected by Cloudflare's UAM. If you know how to
                bypass Cloudflare, do a pull reqeust at
                https://github.com/MangDL/MangDL/pulls.""".replace('\n', ' ')
            )
        tpl = getattr(
            self.prov,
            "template",
            None
        )
        if tpl:
            self.template = import_module(f".{tpl}", "mangdl.api.providers.templates").template(self.prov)
        else:
            self.template = self.prov

    def chapter(self, url: str) -> Ch:
        local = locals()
        [local.pop(i) for i in ["self",]]
        return self.template.chapter(
            **local,
        )

    def manga(self, url: str, chs: int=0) -> Manga:
        local = locals()
        [local.pop(i) for i in ["self",]]
        return self.template.manga(
            **local,
        )

    def dl_search(self, title: str, **kwargs: Dict[str, Any]) -> Dict[str, str]:
        """Used for downloading when imported.
        Args:
            s (Search): Search dataclass, search parameters for searching.
        Returns:
            Dict[str, str]: Search results.
        """
        local = locals()
        [local.pop(i) for i in ["self",]]
        return self.template.dl_search(
            **local,
        )

    def search(self, title: str, **kwargs: Dict[str, Any]) -> List[Manga]:
        local = locals()
        [local.pop(i) for i in ["self",]]
        op = []
        for i in self.template.dl_search(**local).values():
            op.append(self.template.manga(i))
        return op

    def dl(self, url: str, **kwargs: Dict[str, Any]):
        return self.template.dl(url, **kwargs)

    def cli_dl(self, title: str, **kwargs: Dict[str, Any]):
        return self.template.cli_dl(title, **kwargs)

Methods

def chapter(self, url: str) ‑> Ch
Expand source code
def chapter(self, url: str) -> Ch:
    local = locals()
    [local.pop(i) for i in ["self",]]
    return self.template.chapter(
        **local,
    )
def cli_dl(self, title: str, **kwargs: Dict[str, Any])
Expand source code
def cli_dl(self, title: str, **kwargs: Dict[str, Any]):
    return self.template.cli_dl(title, **kwargs)
def dl(self, url: str, **kwargs: Dict[str, Any])
Expand source code
def dl(self, url: str, **kwargs: Dict[str, Any]):
    return self.template.dl(url, **kwargs)

Used for downloading when imported.

Args

s : Search
Search dataclass, search parameters for searching.

Returns

Dict[str, str]
Search results.
Expand source code
def dl_search(self, title: str, **kwargs: Dict[str, Any]) -> Dict[str, str]:
    """Used for downloading when imported.
    Args:
        s (Search): Search dataclass, search parameters for searching.
    Returns:
        Dict[str, str]: Search results.
    """
    local = locals()
    [local.pop(i) for i in ["self",]]
    return self.template.dl_search(
        **local,
    )
def manga(self, url: str, chs: int = 0) ‑> Manga
Expand source code
def manga(self, url: str, chs: int=0) -> Manga:
    local = locals()
    [local.pop(i) for i in ["self",]]
    return self.template.manga(
        **local,
    )
def search(self, title: str, **kwargs: Dict[str, Any]) ‑> List[Manga]
Expand source code
def search(self, title: str, **kwargs: Dict[str, Any]) -> List[Manga]:
    local = locals()
    [local.pop(i) for i in ["self",]]
    op = []
    for i in self.template.dl_search(**local).values():
        op.append(self.template.manga(i))
    return op