Beispiel #1
0
    def activate_account(self, code: str):
        """
        Handles the activation code for the account creation

        Parameters
        ------------
        code : `str`. The activation code sent to the email provided
        """
        url = f"{self.URL}/account/activate/{code}"
        URLRequest.request_url(url, "GET", timeout=self.timeout)
Beispiel #2
0
    def delete_manga(self, manga_id: str) -> None:
        """
        Deletes a manga

        Parameters
        ------------
        id : `str`. The manga id
        """
        url = f"{self.URL}/manga{manga_id}"
        URLRequest.request_url(url, "DELETE", headers=self.bearer, timeout=self.timeout)
Beispiel #3
0
    def delete_customlist(self, customlist_id: str) -> None:
        """
        Deletes a Custom List

        Parameters
        ------------
        customlist_id : `str`. The custom list id
        """
        url = f"{self.URL}/list{customlist_id}"
        URLRequest.request_url(url, "DELETE", headers=self.bearer, timeout=self.timeout)
Beispiel #4
0
    def delete_author(self, author_id: str) -> None:
        """
        Deletes an author

        Parameters
        ---------------
        author_id : `str`. Required. The author id
        """
        url = f"{self.URL}/author/{author_id}"
        URLRequest.request_url(url, "DELETE", headers=self.bearer, timeout=self.timeout)
Beispiel #5
0
    def remove_manga_from_customlist(self, manga_id: str, list_id: str) -> None:
        """
        Removes a manga from a custom list

        Parameters
        ------------
        id : `str`. The manga id
        listId : `str`. The list id
        """
        url = f"{self.URL}/manga/{manga_id}/list/{list_id}"
        URLRequest.request_url(url, "DELETE", headers=self.bearer, timeout=self.timeout)
Beispiel #6
0
    def add_manga_to_customlist(self, manga_id: str, list_id: str) -> None:
        """
        Adds a manga to a custom list

        Parameters
        --------------
        id : `str`. The manga id.
        listId : `str`. The list id.
        """
        url = f"{self.URL}/{manga_id}/list{list_id}"
        URLRequest.request_url(url, "POST", headers=self.bearer, timeout=self.timeout)
Beispiel #7
0
    def complete_account_recover(self, code: str, new_password: str):
        """
        Completes the account recover process

        Parameters
        --------------
        code : `str`. The code sended to the email given in `recover_account`
        newPassword : `str`. The new password for the account
        """
        if len(new_password) < 8:
            raise ValueError("Password must have at least 8 characters")
        url = f"{self.URL}/account/recover/{code}"
        params = {"newPassword": new_password}
        URLRequest.request_url(url, "POST", timeout=self.timeout, params=params)
Beispiel #8
0
    def recover_account(self, email: str):
        """
        Recover an existing account

        Parameters
        --------------
        email : `str`.
        """
        email_regex = "^(\w|\.|\_|\-)+[@](\w|\_|\-|\.)+[.]\w{2,3}$"
        if re.search(email_regex, email) is None:
            raise ValueError("The email provided is not valid")
        params = {"email": email}
        url = f"{self.URL}/account/recover"
        URLRequest.request_url(url, "POST", self.timeout, params)
Beispiel #9
0
    def resend_activation_code(self, email: str):
        """
        Resends the activation code to another email

        Parameters
        -----------------
        email : `str`.
        """
        email_regex = "^(\w|\.|\_|\-)+[@](\w|\_|\-|\.)+[.]\w{2,3}$"  # regular expression for email
        if re.search(email_regex, email) is not None:
            raise ValueError("The email provided is not valid")
        params = {"email": email}
        url = f"{self.URL}/account/activate/resend"
        URLRequest.request_url(url, "POST", timeout=self.timeout, params=params)
Beispiel #10
0
    def delete_cover(self, cover_id: Union[str, CoverArt]):
        """
        Deletes a cover

        Params
        -----------
        cover_id : `str` | `CoverArt`. The cover id or the cover object
        """
        if not cover_id:
            raise ValueError("cover_id cannot be empty")
        if isinstance(cover_id, CoverArt):
            cover_id = cover_id.cover_id
        url = f"{self.URL}/cover/{cover_id}"
        URLRequest.request_url(url, "DELETE", headers=self.bearer, timeout=self.timeout)
Beispiel #11
0
    def unfollow_manga(self, manga_id: str) -> None:
        """
        Unfollows a Manga

        Parameters
        -------------
        manga_id : `str`. The manga id

        Raises
        -----------
        `ApiError`
        """
        url = f"{self.URL}/manga/{manga_id}/follow"
        URLRequest.request_url(url, "DELETE", headers=self.bearer, timeout=self.timeout)
Beispiel #12
0
    def follow_manga(self, manga_id: Union[str, int]) -> None:
        """
        Follow a manga

        Parameters
        --------------
        manga_id : `str`. The manga id

        Raises
        -------------
        `ApiError`
        """
        url = f"{self.URL}/manga/{manga_id}/follow"
        URLRequest.request_url(url, "POST", headers=self.bearer, timeout=self.timeout)
Beispiel #13
0
    def manga_feed(self, manga_id: str, **kwargs) -> List[Chapter]:
        """
        Get the manga feed

        Parameters
        ------------
        manga_id `str`, Required. The manga id

        ### QueryParams:

        limit : `int`
        offset : `int`
        translatedLanguage : `List[str]`. The translated laguages to query
        createdAtSince : `str`. Datetime String with the following format YYYY-MM-DDTHH:MM:SS
        updatedAtSince : `str`. Datetime String with the following format YYYY-MM-DDTHH:MM:SS

        Returns
        -------------
        `List[Chapter]` A list of Chapter Objects

        Raises
        -------------
        `ApiError` `ChapterError`
        """
        kwargs = self.__parse_manga_params(kwargs)
        url = f"{self.URL}/manga/{manga_id}/feed"
        resp = URLRequest.request_url(url, "GET", timeout=self.timeout, params=kwargs)
        return Chapter.create_chapter_list(resp)
Beispiel #14
0
    def upload_cover(
        self, manga_id: str, filename: str, ObjReturn: bool = False
    ) -> Union[CoverArt, None]:
        """
        Uploads a cover

        Parameters
        --------------
        manga_id : `str`
        filename : `str`
        ObjReturn : `bool`

        Returns
        -------------
        `CoverArt` if `ObjReturn` set to `True`
        """
        url = f"{self.URL}/cover/{manga_id}"
        with open(filename, "rb") as f:
            file = f.read()

        resp = URLRequest.request_url(
            url,
            "POST",
            params={"file": file},
            headers=self.bearer,
            timeout=self.timeout,
        )
        return CoverArt.cover_from_dict(resp) if ObjReturn else None
Beispiel #15
0
    def create_account(
        self, username: str, password: str, email: str, ObjReturn: bool = False
    ) -> Union[User, None]:
        """
        Creates an account

        Parameters
        ---------------
        username : `str`.
        password : `str`.
        email : `str`.
        ObjReturn : `bool`.

        Returns
        -------------
        `User` if `ObjReturn` set to `True`
        """
        url = f"{self.URL}/account/create"
        email_regex = "^(\w|\.|\_|\-)+[@](\w|\_|\-|\.)+[.]\w{2,3}$"  # regular expression for email
        if re.search(email_regex, email) is None:
            raise ValueError("The email provided is not valid")

        if len(password) < 8:
            raise ValueError("Password must have at least 8 characters")
        params = {"username": username, "password": password, "email": email}
        resp = URLRequest.request_url(url, "POST", timeout=self.timeout, params=params)
        return User.user_from_dict(resp["data"]) if ObjReturn else None
Beispiel #16
0
    def edit_cover(
        self,
        cover_id: str,
        description: str,
        volume: str = None,
        version: int = None,
        ObjReturn: bool = False,
    ) -> Union[None, CoverArt]:
        """
        Edit a cover parameters

        Parameters
        ------------
        cover_id : `str`. The cover_id
        description : `str`. The cover description
        volume : `str`. The volume representing the volume
        version : `int`. The version of the cover
        ObjReturn : `bool`. Default `False`. If set to `True`, it will return a CoverArt

        Returns
        -----------
        `CoverArt` if `ObjReturn` set to `True`
        """
        if version is None:
            raise ValueError("Version cannot be null")

        params = {"volume": volume, "version": version}
        if description is not None:
            params["description"] = description

        url = f"{self.URL}/cover/{cover_id}"
        resp = URLRequest.request_url(
            url, "PUT", params=params, headers=self.bearer, timeout=self.timeout
        )
        return CoverArt.cover_from_dict(resp) if ObjReturn else None
Beispiel #17
0
    def update_author(
        self, *, author_id: str, version: int, name: str = None, ObjReturn: bool = False
    ) -> Author:
        """
        Updates an Author

        Parameters
        -------------
        author_id : `str`. Required. The author id
        version : `int`. Required
        name : `str`.
        ObjReturn : `bool`.  `True` if you want a Author Object return

        Returns
        -----------
        `Author` if `ObjReturn` is `True`
        """
        url = f"{self.URL}/author/{author_id}"
        params = {"version": version}
        if name is not None:
            params["name"] = name
        resp = URLRequest.request_url(
            url, "PUT", timeout=self.timeout, params=params, headers=self.bearer
        )

        if ObjReturn:
            return Author.author_from_dict(resp)
Beispiel #18
0
    def get_author(self, **kwargs) -> List[Author]:
        """
        Get the author List

        Parameters
        ------------
        limit : `int`
        offset : `int`
        ids : List[`str`]. Array of ids
        name : `str`

        Returns
        -----------
        `List[Author]`. A list of Author objects

        Raises
        ------------
        `ApiError` `AuthorError`
        """
        if "ids" in kwargs:
            kwargs["ids[]"] = kwargs.pop("ids")

        url = f"{self.URL}/author"
        resp = URLRequest.request_url(url, "GET", timeout=self.timeout, params=kwargs)
        return Author.author_from_dict(resp)
Beispiel #19
0
    def chapter_list(self, **kwargs) -> List[Chapter]:
        """
        The list of chapters.
        To get the chpaters of a specific manga the manga parameter must be provided

        Parameters
        -----------
        ### QueryParams:

        limit : `int`
        offset : `int`
        title : `str`
        groups : `List[str]`
        uploader : `str`
        manga : `str`
        volume : `str | List[str]`
        chapter : `str`
        translatedLanguage : `List[str]`
        createdAtSince : `str`. Datetime String with the following format YYYY-MM-DDTHH:MM:SS
        updatedAtSince : `str`. Datetime String with the following format YYYY-MM-DDTHH:MM:SS
        publishAtSince : `str`. Datetime String with the following format YYYY-MM-DDTHH:MM:SS

        Returns
        ----------
        `List[Chpater]` A list of Chpater Objects

        Raises
        -------------
        `ApiError` `ChapterError`
        """
        params = Api.__parse_chapter_list_args(kwargs)
        url = f"{self.URL}/chapter"
        resp = URLRequest.request_url(url, "GET", timeout=self.timeout, params=params)
        return Chapter.create_chapter_list(resp)
Beispiel #20
0
    def create_manga(self, title: str, **kwargs) -> Manga:
        """
        Creates a manga

        Parameters
        -----------
        title : `str`. The manga title

        ### Optional Parameters
        altTitles : `List[Dict[str,str]]`. The alt titles
        description : `Dict[str,str]`. The alt titles in different languages
        authors : `List[str]`. The list of author id's
        artists : `List[str]`. The list of artist id's
        links : `Dict[str,str]`. The links in differents sites (al, ap, bw, mu, etc).
        Please refer to the [documentation](https://api.mangadex.org/docs.html#section/Static-data/Manga-links-data)
        originalLanguage : `str`. The original Language
        lastVolume : `str`. The last volume
        lastChapter : `str`. The last chapter
        publicationDemographic : `str`.
        status : `str`.
        year : `int`.
        contentRating : `str`.
        modNotes : `str`

        Returns
        ------------
        `Manga`. A manga object if `ObjReturn` is set to `True`
        """
        params = self.__parse_manga_params(kwargs)
        url = f"{self.URL}/manga"
        params["title"] = title
        resp = URLRequest.request_url(
            url, "POST", params=params, headers=self.bearer, timeout=self.timeout
        )
        return Manga.manga_from_dict(resp)
Beispiel #21
0
    def fetch_chapter_images(
            self) -> List[str]:  # maybe make this an async function?
        """
        Get the image links for the chapter

        Returns
        -----------
        `List[str]`. A list with the links with the chapter images

        NOTE: There links are valid for 15 minutes until you need to renew the token

        Raises
        -----------
        `ApiError`
        """
        url = f"https://api.mangadex.org/at-home/server/{self.chapter_id}"
        image_server_url = URLRequest.request_url(url, "GET", timeout=5)
        self.hash = image_server_url["chapter"]["hash"]
        self.data = image_server_url["chapter"]["data"]
        image_server_url = image_server_url["baseUrl"].replace("\\", "")
        image_server_url = f"{image_server_url}/data"
        image_urls = []
        for filename in self.data:
            image_urls.append(f"{image_server_url}/{self.hash}/{filename}")

        return image_urls
Beispiel #22
0
 def __auth_handler(self, json_payload) -> None:
     url = f"{self.URL}/auth/login"
     auth = URLRequest.request_url(
         url, "POST", params=json_payload, timeout=self.timeout
     )
     token = auth["token"]["session"]
     bearer = {"Authorization": f"Bearer {token}"}
     self.bearer = bearer
Beispiel #23
0
    def update_manga_reading_status(self, manga_id: str, status: str) -> None:
        """
        Update the reading stauts of a manga

        Parameters
        -------------
        manga_id : `str`. The manga id.\n
        status : `str`. Values : `"reading"` `"on_hold"` `"plan_to_read"` `"dropped"` `"re_reading"` `"completed"`

        Raises
        -------------
        `ApiError`
        """
        url = f"{self.URL}/manga/{manga_id}/status"
        URLRequest.request_url(
            url,
            "POST",
            params={"status": status},
            headers=self.bearer,
            timeout=self.timeout,
        )
Beispiel #24
0
    def me(self) -> User:
        """
        Get your user info

        Returns
        ---------
        `User`
        """
        url = f"{self.URL}/user/me"
        resp = URLRequest.request_url(
            url, "GET", timeout=self.timeout, headers=self.bearer
        )
        return User.user_from_dict(resp)
Beispiel #25
0
    def get_coverart_list(self, **kwargs):
        """
        Get the list of cover arts (like the manga feed)

        Optional parameters
        -------------------------
        manga : List[str]. Manga ids
        ids : List[str]. Cover ids
        uploaders : List[str]. User ids
        """
        params = Api.__parse_coverart_params(kwargs)
        url = f"{self.URL}/cover"
        resp = URLRequest.request_url(url, "GET", params=params, timeout=self.timeout)
        return CoverArt.create_coverart_list(resp)
Beispiel #26
0
    def create_customlist(
        self,
        name: str,
        visibility: str = "public",
        manga: List[str] = None,
        version: int = 1,
    ) -> None:
        """
        Creates a custom list

        Parameters
        -------------
        ### QueryParams:

        name : `str`. The custom list name
        visibility : `str. The visibility of the custom list
        manga : `List[str]`. List of manga ids
        """
        url = f"{self.URL}/list"
        params = {"name": name, "version": version}
        params["visibility"] = visibility
        params["manga[]"] = manga
        URLRequest.request_url(url, "POST", params=params, timeout=self.timeout)
Beispiel #27
0
    def tag_list(self) -> List[Tag]:
        """
        Get the list of available tags

        Returns
        ------------
        `List[Tag]`. A list of Tag objects

        Raises
        -----------
        `ApiError` `TagError`
        """
        url = f"{self.URL}/manga/tag"
        resp = URLRequest.request_url(url, "GET", timeout=self.timeout)
        return Tag.create_tag_list(resp)
Beispiel #28
0
    def get_cover(self, cover_id: str) -> CoverArt:
        """
        Gets a cover image

        Parameters
        --------------
        cover_id : `str`. The cover id

        Returns
        --------------
        `CoverArt`. A cover art object
        """
        url = f"{self.URL}/cover/{cover_id}"
        resp = URLRequest.request_url(url, "GET", timeout=self.timeout)
        return CoverArt.cover_from_dict(resp)
Beispiel #29
0
    def random_manga(self) -> Manga:
        """
        Get a random Manga

        Returns
        ----------
        `Manga`. A Manga object

        Raises
        ----------
        `ApiError` `MangaError`
        """
        url = f"{self.URL}/manga/random"
        resp = URLRequest.request_url(url, "GET", timeout=self.timeout)
        return Manga.manga_from_dict(resp)
Beispiel #30
0
    def get_manga_reading_status(self, manga_id: Union[str, int]) -> str:
        """
        Get a manga reading status given its id

        Parameters
        ------------
        manga_id : `str`. The manga id

        Returns
        ------------
        `str` The manga reading status
        """
        url = f"{self.URL}/manga/{manga_id}/status"
        resp = URLRequest.request_url(
            url, "GET", headers=self.bearer, timeout=self.timeout
        )
        return resp["status"]