Enma


NameEnma JSON
Version 2.2.1 PyPI version JSON
download
home_pagehttps://github.com/AlexandreSenpai/Enma
SummaryEnma is a Python library designed to fetch manga and doujinshi data from various sources.
upload_time2023-12-19 04:30:50
maintainer
docs_urlNone
authorAlexandreSenpai
requires_python
licenseMIT
keywords tags hentai nhentai nhentai.net api nsfw erohoshi manganato doujinshi manga scrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI download month](https://img.shields.io/pypi/dm/Enma.svg)](https://pypi.python.org/pypi/Enma/)
[![codecov](https://codecov.io/gh/AlexandreSenpai/Enma/branch/master/graph/badge.svg?token=F3LP15DYMR)](https://codecov.io/gh/AlexandreSenpai/Enma)
[![Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/downloads/release/python-390/)
[![PyPI license](https://img.shields.io/pypi/l/ansicolortags.svg)](https://pypi.python.org/pypi/ansicolortags/)
[![GitHub forks](https://img.shields.io/github/forks/AlexandreSenpai/Enma)](https://github.com/AlexandreSenpai/Enma)
[![GitHub stars](https://img.shields.io/github/stars/AlexandreSenpai/Enma)](https://github.com/AlexandreSenpai/Enma)
[![GitHub issues](https://img.shields.io/github/issues/AlexandreSenpai/Enma)](https://github.com/AlexandreSenpai/Enma/issues)


# Enma

Enma is a Python library designed to fetch manga and doujinshi data from various sources. It provides a unified interface to interact with different manga repositories, making it easier to retrieve manga details, search for manga, paginate through results, and fetch random manga.

## Requirements

- Python 3.9+

## Installation
```py
pip install enma
```

Ensure you have the required Python version:
```py
import sys

package_name = "enma"
python_major = "3"
python_minor = "9"

try:
    assert sys.version_info >= (int(python_major), int(python_minor))
except AssertionError:
    raise RuntimeError(f"{package_name!r} requires Python {python_major}.{python_minor}+ (You have Python {sys.version})")
```

## Features Comparison

Feature   | NHentai | Manganato
----------|---------|-----------
search    |    ✅   |     ✅    
random    |    ✅   |     🚫    
get       |    ✅   |     ✅    
paginate  |    ✅   |     🚫
download  |    ✅   |     ✅       
set_config|    ✅   |     🚫

## Usage

### Example 1: Using Default Available Sources

```py
from typing import cast
from enma import Enma, DefaultAvailableSources, CloudFlareConfig, NHentai, Sort

enma = Enma[DefaultAvailableSources]()

config = CloudFlareConfig(
    user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
    cf_clearance=''
)

enma.source_manager.set_source(source_name='nhentai')
nh_source = cast(NHentai, enma.source_manager.source)
nh_source.set_config(config=config)

doujin = enma.random()
print(doujin)
```

### Example 2: Extending with Custom Sources
```py
from enum import Enum
from typing import cast
from enma import Enma, SourcesEnum, Manganato, IMangaRepository

class AvailableSources(SourcesEnum):
    NHENTAI = 'nhentai'
    MANGANATO = 'manganato'
    NEW_SOURCE = 'new-source'

enma = Enma[AvailableSources]()

enma.source_manager.add_source(source_name='new-source', source=Manganato()) # Source MUST be an instance of IMangaRepository
enma.source_manager.set_source(source_name=AvailableSources.MANGANATO)

manga = enma.random()
print(manga)
```

### Example 3: Downloading Chapters
```py
from enum import Enum
from enma import Enma, SourcesEnum, Manganato, IMangaRepository, default_downloader

enma = Enma()

enma.source_manager.set_source('nhentai')

if enma.source_manager.source:
    config = CloudFlareConfig(
        user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
        cf_clearance=''
    )

    enma.source_manager.source.set_config(config=config)

manga = enma.random()
manga.chapters[0].download(downloader=default_downloader)
# or manga.chapters[0].download(downloader=default_downloader, output_path='./naruto/chapters/01')

```

## Retrieving `user-agent` and `cf_clearance` for NHentai

To retrieve the `user-agent` and `cf_clearance` for NHentai:

1. **Open NHentai in your browser**: Navigate to the NHentai website.
2. **Open Developer Tools**:
    - **For Google Chrome**: Right-click on the webpage and select Inspect or simply press Ctrl + Shift + I (or Cmd + Option + I on Mac).
    - **For Firefox**: Right-click on the webpage and select Inspect Element or press Ctrl + Shift + I (or Cmd + Option + I on Mac).
3. **Navigate to the Network Tab**: In the Developer Tools panel, click on the Network tab. This tab captures all network requests made by the webpage.
4. **Reload the Page**: With the Network tab open, reload the NHentai website by pressing Ctrl + R (or Cmd + R on Mac). This ensures that all network requests are captured.
5. **Select the nhentai.net Request**: After reloading, you'll see a list of files on the left side of the Network tab. Click on the first file named nhentai.net. This represents the main request to the NHentai website.
6. **Find the Request Headers**: On the right side, you'll see several tabs like Headers, Preview, Response, etc. Make sure you're on the Headers tab. Scroll down until you find a section named Request Headers.
7. **Copy the user-agent and cf_clearance**:
    - **user-agent**: This is a string that tells the server which web browser is being used. Look for an entry named User-Agent and copy its value.
    - **cf_clearance**: This is a specific cookie set by CloudFlare for security purposes. Look for an entry named cf_clearance and copy its value.

![example](./images/user-agent.png)
## Example:

```py
config = CloudFlareConfig(
    user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
    cf_clearance=''
)
```
> **Note**: The user-agent and cf_clearance values can change over time. If you encounter issues accessing NHentai through the Enma library, you might need to repeat the above steps to get updated values.

## Errors

While using the library, you might encounter some specific errors. Here's a description of each:

1. **InstanceError**: 
   - **Description**: Raised when an instance of an object is not of the expected type.
   - **Common Cause**: Trying to add a source that isn't an instance of `IMangaRepository`.

2. **SourceNotAvailable**: 
   - **Description**: Raised when attempting to access a source that isn't available in the defined source list.
   - **Common Cause**: Trying to set a source that hasn't been previously added.

3. **SourceWasNotDefined**: 
   - **Description**: Raised when trying to perform an action (like fetching a manga) without first defining a source.
   - **Common Cause**: Forgetting to set the source before performing an operation.

4. **ExceedRetryCount**: 
   - **Description**: Specific to the `NHentai` adapter. Raised when the `random` method fails to fetch a random doujin after several attempts.
   - **Common Cause**: Consecutive failures when trying to fetch a random doujin from NHentai.

5. **NhentaiSourceWithoutConfig**: 
   - **Description**: Raised when trying to make a request to NHentai without providing the necessary configurations.
   - **Common Cause**: Forgetting to provide the `user-agent` and `cf_clearance` when configuring the NHentai adapter.

6. **InvalidResource**: 
   - **Description**: Raised when trying to perform an action with an invalid or inexistent resource.
   - **Common Cause**: Providing an inexistent folder path to downloader.

When encountering one of these errors, refer to the description and common cause to assist in troubleshooting.

## Future Plans

We are actively working on introducing an asynchronous version of the Enma library to better cater to applications that require non-blocking operations. This version will be maintained in a separate repository to keep the core library lightweight. However, for ease of access and installation, you'll be able to install the asynchronous version directly using:

```bash
pip install enma[async]
```
Stay tuned for updates and ensure to check our repository for the latest advancements!
## Frequently Asked Questions (FAQ)

**Q: Can I add more sources to Enma?**</br>
A: Yes! Enma is designed to be extensible. You can add more sources by extending the `SourcesEnum` and implementing `IMangaRepository` that contains the required methods for the new source.

**Q: I'm facing issues with a specific source. What should I do?**</br>
A: Ensure you have the latest version of Enma. If the issue persists, please raise an issue on our GitHub repository detailing the problem.

**Q: How often is Enma updated?**</br>
A: Enma is updated regularly as new sources are added or when there are significant changes to existing sources.

## Contributing

We welcome contributions! If you'd like to contribute:

1. Fork the repository.
2. Make your changes.
3. Submit a pull request.

Ensure you follow the coding standards and write tests for new features.

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AlexandreSenpai/Enma",
    "name": "Enma",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Tags,hentai,nhentai,nhentai.net,API,NSFW,erohoshi,Manganato,Doujinshi,Manga,Scrapper",
    "author": "AlexandreSenpai",
    "author_email": "alexandrebsramos@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a2/c2/52db57a0edda5e4415dab8a27d1af7aad6be6fcddea0af82c0ae62245409/Enma-2.2.1.tar.gz",
    "platform": null,
    "description": "[![PyPI download month](https://img.shields.io/pypi/dm/Enma.svg)](https://pypi.python.org/pypi/Enma/)\n[![codecov](https://codecov.io/gh/AlexandreSenpai/Enma/branch/master/graph/badge.svg?token=F3LP15DYMR)](https://codecov.io/gh/AlexandreSenpai/Enma)\n[![Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/downloads/release/python-390/)\n[![PyPI license](https://img.shields.io/pypi/l/ansicolortags.svg)](https://pypi.python.org/pypi/ansicolortags/)\n[![GitHub forks](https://img.shields.io/github/forks/AlexandreSenpai/Enma)](https://github.com/AlexandreSenpai/Enma)\n[![GitHub stars](https://img.shields.io/github/stars/AlexandreSenpai/Enma)](https://github.com/AlexandreSenpai/Enma)\n[![GitHub issues](https://img.shields.io/github/issues/AlexandreSenpai/Enma)](https://github.com/AlexandreSenpai/Enma/issues)\n\n\n# Enma\n\nEnma is a Python library designed to fetch manga and doujinshi data from various sources. It provides a unified interface to interact with different manga repositories, making it easier to retrieve manga details, search for manga, paginate through results, and fetch random manga.\n\n## Requirements\n\n- Python 3.9+\n\n## Installation\n```py\npip install enma\n```\n\nEnsure you have the required Python version:\n```py\nimport sys\n\npackage_name = \"enma\"\npython_major = \"3\"\npython_minor = \"9\"\n\ntry:\n    assert sys.version_info >= (int(python_major), int(python_minor))\nexcept AssertionError:\n    raise RuntimeError(f\"{package_name!r} requires Python {python_major}.{python_minor}+ (You have Python {sys.version})\")\n```\n\n## Features Comparison\n\nFeature   | NHentai | Manganato\n----------|---------|-----------\nsearch    |    \u2705   |     \u2705    \nrandom    |    \u2705   |     \ud83d\udeab    \nget       |    \u2705   |     \u2705    \npaginate  |    \u2705   |     \ud83d\udeab\ndownload  |    \u2705   |     \u2705       \nset_config|    \u2705   |     \ud83d\udeab\n\n## Usage\n\n### Example 1: Using Default Available Sources\n\n```py\nfrom typing import cast\nfrom enma import Enma, DefaultAvailableSources, CloudFlareConfig, NHentai, Sort\n\nenma = Enma[DefaultAvailableSources]()\n\nconfig = CloudFlareConfig(\n    user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',\n    cf_clearance=''\n)\n\nenma.source_manager.set_source(source_name='nhentai')\nnh_source = cast(NHentai, enma.source_manager.source)\nnh_source.set_config(config=config)\n\ndoujin = enma.random()\nprint(doujin)\n```\n\n### Example 2: Extending with Custom Sources\n```py\nfrom enum import Enum\nfrom typing import cast\nfrom enma import Enma, SourcesEnum, Manganato, IMangaRepository\n\nclass AvailableSources(SourcesEnum):\n    NHENTAI = 'nhentai'\n    MANGANATO = 'manganato'\n    NEW_SOURCE = 'new-source'\n\nenma = Enma[AvailableSources]()\n\nenma.source_manager.add_source(source_name='new-source', source=Manganato()) # Source MUST be an instance of IMangaRepository\nenma.source_manager.set_source(source_name=AvailableSources.MANGANATO)\n\nmanga = enma.random()\nprint(manga)\n```\n\n### Example 3: Downloading Chapters\n```py\nfrom enum import Enum\nfrom enma import Enma, SourcesEnum, Manganato, IMangaRepository, default_downloader\n\nenma = Enma()\n\nenma.source_manager.set_source('nhentai')\n\nif enma.source_manager.source:\n    config = CloudFlareConfig(\n        user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',\n        cf_clearance=''\n    )\n\n    enma.source_manager.source.set_config(config=config)\n\nmanga = enma.random()\nmanga.chapters[0].download(downloader=default_downloader)\n# or manga.chapters[0].download(downloader=default_downloader, output_path='./naruto/chapters/01')\n\n```\n\n## Retrieving `user-agent` and `cf_clearance` for NHentai\n\nTo retrieve the `user-agent` and `cf_clearance` for NHentai:\n\n1. **Open NHentai in your browser**: Navigate to the NHentai website.\n2. **Open Developer Tools**:\n    - **For Google Chrome**: Right-click on the webpage and select Inspect or simply press Ctrl + Shift + I (or Cmd + Option + I on Mac).\n    - **For Firefox**: Right-click on the webpage and select Inspect Element or press Ctrl + Shift + I (or Cmd + Option + I on Mac).\n3. **Navigate to the Network Tab**: In the Developer Tools panel, click on the Network tab. This tab captures all network requests made by the webpage.\n4. **Reload the Page**: With the Network tab open, reload the NHentai website by pressing Ctrl + R (or Cmd + R on Mac). This ensures that all network requests are captured.\n5. **Select the nhentai.net Request**: After reloading, you'll see a list of files on the left side of the Network tab. Click on the first file named nhentai.net. This represents the main request to the NHentai website.\n6. **Find the Request Headers**: On the right side, you'll see several tabs like Headers, Preview, Response, etc. Make sure you're on the Headers tab. Scroll down until you find a section named Request Headers.\n7. **Copy the user-agent and cf_clearance**:\n    - **user-agent**: This is a string that tells the server which web browser is being used. Look for an entry named User-Agent and copy its value.\n    - **cf_clearance**: This is a specific cookie set by CloudFlare for security purposes. Look for an entry named cf_clearance and copy its value.\n\n![example](./images/user-agent.png)\n## Example:\n\n```py\nconfig = CloudFlareConfig(\n    user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',\n    cf_clearance=''\n)\n```\n> **Note**: The user-agent and cf_clearance values can change over time. If you encounter issues accessing NHentai through the Enma library, you might need to repeat the above steps to get updated values.\n\n## Errors\n\nWhile using the library, you might encounter some specific errors. Here's a description of each:\n\n1. **InstanceError**: \n   - **Description**: Raised when an instance of an object is not of the expected type.\n   - **Common Cause**: Trying to add a source that isn't an instance of `IMangaRepository`.\n\n2. **SourceNotAvailable**: \n   - **Description**: Raised when attempting to access a source that isn't available in the defined source list.\n   - **Common Cause**: Trying to set a source that hasn't been previously added.\n\n3. **SourceWasNotDefined**: \n   - **Description**: Raised when trying to perform an action (like fetching a manga) without first defining a source.\n   - **Common Cause**: Forgetting to set the source before performing an operation.\n\n4. **ExceedRetryCount**: \n   - **Description**: Specific to the `NHentai` adapter. Raised when the `random` method fails to fetch a random doujin after several attempts.\n   - **Common Cause**: Consecutive failures when trying to fetch a random doujin from NHentai.\n\n5. **NhentaiSourceWithoutConfig**: \n   - **Description**: Raised when trying to make a request to NHentai without providing the necessary configurations.\n   - **Common Cause**: Forgetting to provide the `user-agent` and `cf_clearance` when configuring the NHentai adapter.\n\n6. **InvalidResource**: \n   - **Description**: Raised when trying to perform an action with an invalid or inexistent resource.\n   - **Common Cause**: Providing an inexistent folder path to downloader.\n\nWhen encountering one of these errors, refer to the description and common cause to assist in troubleshooting.\n\n## Future Plans\n\nWe are actively working on introducing an asynchronous version of the Enma library to better cater to applications that require non-blocking operations. This version will be maintained in a separate repository to keep the core library lightweight. However, for ease of access and installation, you'll be able to install the asynchronous version directly using:\n\n```bash\npip install enma[async]\n```\nStay tuned for updates and ensure to check our repository for the latest advancements!\n## Frequently Asked Questions (FAQ)\n\n**Q: Can I add more sources to Enma?**</br>\nA: Yes! Enma is designed to be extensible. You can add more sources by extending the `SourcesEnum` and implementing `IMangaRepository` that contains the required methods for the new source.\n\n**Q: I'm facing issues with a specific source. What should I do?**</br>\nA: Ensure you have the latest version of Enma. If the issue persists, please raise an issue on our GitHub repository detailing the problem.\n\n**Q: How often is Enma updated?**</br>\nA: Enma is updated regularly as new sources are added or when there are significant changes to existing sources.\n\n## Contributing\n\nWe welcome contributions! If you'd like to contribute:\n\n1. Fork the repository.\n2. Make your changes.\n3. Submit a pull request.\n\nEnsure you follow the coding standards and write tests for new features.\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Enma is a Python library designed to fetch manga and doujinshi data from various sources.",
    "version": "2.2.1",
    "project_urls": {
        "Homepage": "https://github.com/AlexandreSenpai/Enma"
    },
    "split_keywords": [
        "tags",
        "hentai",
        "nhentai",
        "nhentai.net",
        "api",
        "nsfw",
        "erohoshi",
        "manganato",
        "doujinshi",
        "manga",
        "scrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a2c252db57a0edda5e4415dab8a27d1af7aad6be6fcddea0af82c0ae62245409",
                "md5": "309097b93725eb63bed20534d26e0a9a",
                "sha256": "3fcacdeb127bf02af8670f75e0e19969a2a5599f257636ba0f87f76a3fd7add6"
            },
            "downloads": -1,
            "filename": "Enma-2.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "309097b93725eb63bed20534d26e0a9a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15000,
            "upload_time": "2023-12-19T04:30:50",
            "upload_time_iso_8601": "2023-12-19T04:30:50.787098Z",
            "url": "https://files.pythonhosted.org/packages/a2/c2/52db57a0edda5e4415dab8a27d1af7aad6be6fcddea0af82c0ae62245409/Enma-2.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-19 04:30:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AlexandreSenpai",
    "github_project": "Enma",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "enma"
}
        
Elapsed time: 0.16496s