Skip to content

CDN

Builds nhentai CDN image URLs. Host is selected randomly from the pool on each call.

nhentai.cdn.CDN

Builds nhentai CDN image URLs with random host selection for load balancing.

get_image_url(media_id: int, page: int, ext: str = 'webp') -> str

Full-resolution page URL.

Source code in nhentai/cdn.py
def get_image_url(self, media_id: int, page: int, ext: str = "webp") -> str:
    """Full-resolution page URL."""
    host = random.choice(self._image_hosts)
    return f"https://{host}/galleries/{media_id}/{page}.{ext}"

get_thumb_url(media_id: int, page: int, ext: str = 'webp') -> str

Thumbnail URL for a specific page.

Source code in nhentai/cdn.py
def get_thumb_url(self, media_id: int, page: int, ext: str = "webp") -> str:
    """Thumbnail URL for a specific page."""
    host = random.choice(self._thumb_hosts)
    return f"https://{host}/galleries/{media_id}/{page}t.{ext}"

get_cover_url(media_id: int, ext: str = 'webp') -> str

Cover image URL.

Source code in nhentai/cdn.py
def get_cover_url(self, media_id: int, ext: str = "webp") -> str:
    """Cover image URL."""
    host = random.choice(self._thumb_hosts)
    return f"https://{host}/galleries/{media_id}/cover.{ext}"

ext_from_type(t: str) -> str staticmethod

Convert nhentai page type code (j/p/w/g) to file extension.

Source code in nhentai/cdn.py
@staticmethod
def ext_from_type(t: str) -> str:
    """Convert nhentai page type code (``j``/``p``/``w``/``g``) to file extension."""
    return EXT_MAP.get(t, "jpg")