The smd API reference

smd is a tool to search and download manga from online manga reading web sites.

smd.create_config_folder() → None

Creates the application is configuration folder, if it doesn’t exists.

smd.download(downloaders: List[smd.downloader.Downloader], manga: str, chapter_selectors: str, tryall: bool) → bool

Downloads the given manga using one of the given downloaders.

Parameters:
  • downloaders – the list of downloaders.
  • manga – the manga name.
  • chapter_selectors – the comma-separated list of chapters to download.
  • tryall – when True if a downloader fail, then tries other downloaders.
Returns:

True if the download succeeded, False otherwise.

smd.filter_downloaders(lang: str, downloaders: List[smd.downloader.Downloader]) → List[smd.downloader.Downloader]

Selects from the given list, the downloaders with the given language.

Parameters:
  • lang – the language of the downloaders to select.
  • downloaders – a list of downloaders.
Returns:

a list of downloaders with the given language.

smd.get_args_parser() → argparse.ArgumentParser

Creates an arguments parser for the program is command line interface.

Parameters:version – the application is version number.
Returns:the arguments parser.
smd.keyboard_interrupt(function: Callable) → Callable

Makes the decorated function to handle keyboard interrupt gracefully.

smd.list_downloaders(downloaders: List[smd.downloader.Downloader]) → None

Prints the list of the given downloaders.

Parameters:downloaders – a list of downloaders.
smd.resume(downloaders: List[smd.downloader.Downloader], mangas: Union[List[str], str]) → None

Resumes a previously canceled manga download.

Parameters:downloaders

the supported downloaders. :param mangas: a list of paths to manga folders or a path to a folder

where the manga folders are stored.
smd.select_downloader(downloaders: List[smd.downloader.Downloader]) → smd.downloader.Downloader

Lets the user choose one downloader from the give list, keeps asking if the user enters invalid option.

Parameters:downloaders – a list of downloaders.
Returns:the selected downloader.
smd.select_lang(langs: List[str]) → str

Lets the user select a language from the given list, keeps asking if the user enters invalid option.

Parameters:langs – the list of languages.
Returns:the selected language.
smd.set_site(site: str, downloaders: List[smd.downloader.Downloader]) → None

Sets the downloader of the given site as the preferred.

Parameters:
  • site – the site name (same as smd.downloader.Downloader.name)
  • downloaders – the list of supported downloaders.

Shows copyright notice.

smd.update(downloaders: List[smd.downloader.Downloader], mangas: Union[List[str], str]) → None

Updates a previously downloaded manga.

Parameters:
  • downloaders – a list of supported downloaders.
  • mangas – a list of paths to manga folders or a path to a folder where the manga folders are stored.

smd.downloader

This module provides the downloaders able to grab content from the supported sites.

class smd.downloader.Downloader(name: str, lang: str, site_url: str)

Abstract class base of all manga downloaders.

download(manga_name: str, chapter_selectors: str) → bool

Searches for the given manga and, if found, chapters specified in chapter_selectors are downloaded.

Parameters:
  • manga_name – the manga to search and download.
  • chapter_selectors – a string specifying the chapters to download.
Returns:

True if the manga was downloaded successfully, False otherwise.

download_img(url: str, name: str) → str

Receives an image URL and a filename (without a file extension) and downloads the image, detects image format and save it to the given filename plus the proper extension.

Parameters:
  • url – the URL of the image.
  • name – the name to use for the saved image (without file extension)
Returns:

the file name with file extension of the downloaded image.

get_bytes(url: str, data: dict = None, method: str = 'GET', xhr: bool = False) → bytes

Retrieves data from given URL.

Parameters:
  • url – the URL to retrieve.
  • data – the data to send with the request.
  • method – the method to use to request the URL (POST/GET).
  • xhr – if True set the header ‘X-Requested-With’ to ‘XMLHttpRequest’
Returns:

the response data.

Raises:
  • ConnectionResetError – if the connection is reset more than five times.
  • ValueError – if method is not GET or POST.
get_chapters(manga_url: str) → List[Chapter]

Extracts the manga chapters from the given manga URL.

Parameters:manga_url – the URL of a manga.
Returns:the list of chapters of the given manga.
get_image(image_url: str) → str

If needed, child classes must override this method to extracts the image link from the given URL.

Parameters:image_url – the image URL or an URL to a page where the image link can be extracted.
Returns:the image URL.
get_images(chapter_url: str) → List[str]

Extracts the images links from a chapter URL.

Parameters:chapter_url – the URL of a manga chapter.
Returns:list of image URLs for the given chapter, or a list of URLs where the images can be extracted using get_image().
get_json(*args, **kargs) → Any

Request json data from the given url, the given parameters are passed to get_str() method.

Returns:the response data object.
get_str(*args, **kargs) → str

Calls get_bytes() with the given parameters and returns the response bytes decoded.

resume(manga: smd.utils.Manga) → int

Continues with the (unfinished) download of the given manga.

Parameters:manga – the manga to continue downloading.
Returns:the number of resumed mangas.
search(manga: str) → List[Manga]

Searches for mangas matching the given text.

Parameters:manga – a frase or manga title to search.
Returns:a list of mangas.
update(manga: smd.utils.Manga) → int

Downloads new available chapters of the given manga.

Parameters:manga – the manga to update.
Returns:the number of updated mangas.
class smd.downloader.HeavenManga

Downloads manga from heavenmanga.com.

get_chapters(manga_url: str) → List[Chapter]

Extracts the manga chapters from the given manga URL.

Parameters:manga_url – the URL of a manga.
Returns:the list of chapters of the given manga.
get_image(image_url: str) → str

If needed, child classes must override this method to extracts the image link from the given URL.

Parameters:image_url – the image URL or an URL to a page where the image link can be extracted.
Returns:the image URL.
get_images(chapter_url: str) → List[str]

Extracts the images links from a chapter URL.

Parameters:chapter_url – the URL of a manga chapter.
Returns:list of image URLs for the given chapter, or a list of URLs where the images can be extracted using get_image().
search(manga: str) → List[Manga]

Searches for mangas matching the given text.

Parameters:manga – a frase or manga title to search.
Returns:a list of mangas.
class smd.downloader.MangaAll

Downloads manga from mangaall.net.

get_chapters(manga_url: str) → List[Chapter]

Extracts the manga chapters from the given manga URL.

Parameters:manga_url – the URL of a manga.
Returns:the list of chapters of the given manga.
get_image(image_url: str) → str

If needed, child classes must override this method to extracts the image link from the given URL.

Parameters:image_url – the image URL or an URL to a page where the image link can be extracted.
Returns:the image URL.
get_images(chapter_url: str) → List[str]

Extracts the images links from a chapter URL.

Parameters:chapter_url – the URL of a manga chapter.
Returns:list of image URLs for the given chapter, or a list of URLs where the images can be extracted using get_image().
search(manga: str) → List[Manga]

Searches for mangas matching the given text.

Parameters:manga – a frase or manga title to search.
Returns:a list of mangas.
class smd.downloader.MangaDoor

Downloads manga from mangadoor.com.

get_chapters(manga_url: str) → List[Chapter]

Extracts the manga chapters from the given manga URL.

Parameters:manga_url – the URL of a manga.
Returns:the list of chapters of the given manga.
get_image(image_url: str) → str

If needed, child classes must override this method to extracts the image link from the given URL.

Parameters:image_url – the image URL or an URL to a page where the image link can be extracted.
Returns:the image URL.
get_images(chapter_url: str) → List[str]

Extracts the images links from a chapter URL.

Parameters:chapter_url – the URL of a manga chapter.
Returns:list of image URLs for the given chapter, or a list of URLs where the images can be extracted using get_image().
search(manga: str) → List[Manga]

Searches for mangas matching the given text.

Parameters:manga – a frase or manga title to search.
Returns:a list of mangas.
class smd.downloader.MangaHere

Downloads manga from www.mangahere.cc.

get_chapters(manga_url: str) → List[Chapter]

Extracts the manga chapters from the given manga URL.

Parameters:manga_url – the URL of a manga.
Returns:the list of chapters of the given manga.
get_image(image_url: str) → str

If needed, child classes must override this method to extracts the image link from the given URL.

Parameters:image_url – the image URL or an URL to a page where the image link can be extracted.
Returns:the image URL.
get_images(chapter_url: str) → List[str]

Extracts the images links from a chapter URL.

Parameters:chapter_url – the URL of a manga chapter.
Returns:list of image URLs for the given chapter, or a list of URLs where the images can be extracted using get_image().
search(manga: str) → List[Manga]

Searches for mangas matching the given text.

Parameters:manga – a frase or manga title to search.
Returns:a list of mangas.
class smd.downloader.MangaNelo

Downloads manga from manganelo.com.

get_chapters(manga_url: str) → List[Chapter]

Extracts the manga chapters from the given manga URL.

Parameters:manga_url – the URL of a manga.
Returns:the list of chapters of the given manga.
get_images(chapter_url: str) → List[str]

Extracts the images links from a chapter URL.

Parameters:chapter_url – the URL of a manga chapter.
Returns:list of image URLs for the given chapter, or a list of URLs where the images can be extracted using get_image().
search(manga: str) → List[Manga]

Searches for mangas matching the given text.

Parameters:manga – a frase or manga title to search.
Returns:a list of mangas.
class smd.downloader.MangaReader

Downloads manga from www.mangareader.net.

get_chapters(manga_url: str) → List[Chapter]

Extracts the manga chapters from the given manga URL.

Parameters:manga_url – the URL of a manga.
Returns:the list of chapters of the given manga.
get_image(image_url: str) → str

If needed, child classes must override this method to extracts the image link from the given URL.

Parameters:image_url – the image URL or an URL to a page where the image link can be extracted.
Returns:the image URL.
get_images(chapter_url: str) → List[str]

Extracts the images links from a chapter URL.

Parameters:chapter_url – the URL of a manga chapter.
Returns:list of image URLs for the given chapter, or a list of URLs where the images can be extracted using get_image().
search(manga: str) → List[Manga]

Searches for mangas matching the given text.

Parameters:manga – a frase or manga title to search.
Returns:a list of mangas.
class smd.downloader.NineManga(site: str)

Downloads manga from ninemanga.com.

get_chapters(manga_url: str) → List[Chapter]

Extracts the manga chapters from the given manga URL.

Parameters:manga_url – the URL of a manga.
Returns:the list of chapters of the given manga.
get_image(image_url: str) → str

If needed, child classes must override this method to extracts the image link from the given URL.

Parameters:image_url – the image URL or an URL to a page where the image link can be extracted.
Returns:the image URL.
get_images(chapter_url: str) → List[str]

Extracts the images links from a chapter URL.

Parameters:chapter_url – the URL of a manga chapter.
Returns:list of image URLs for the given chapter, or a list of URLs where the images can be extracted using get_image().
search(manga: str) → List[Manga]

Searches for mangas matching the given text.

Parameters:manga – a frase or manga title to search.
Returns:a list of mangas.
smd.downloader.get_downloaders() → List[Downloader]

Creates a list with instances of all supported downloaders.

Returns:the list of all supported downloaders.

smd.utils

This module provides utility functions and classes.

class smd.utils.Chapter(path: str, title: str, url: str)

Class representing a chapter folder.

static from_folder(path: str) → smd.utils.Chapter

Creates a Chapter instance from a folder path.

Parameters:path – the path to the chapter folder.
Returns:the created Chapter instance.
class smd.utils.Config(path: str)

Class to manage the configuration of smd

exists() → bool

Checks if the configuration file exists.

Returns:True if the configuration file exists, False otherwise.
load() → List[str]

Loads the configuration from disk.

Returns:a list with the loaded configuration files.
reset() → None

Resets all configuration values to the defaults.

save() → None

Saves the configuration to disk.

class smd.utils.ConsoleFilter(name='')

A filter to avoid showing exceptions stack traces text in user’s terminal.

static filter(record: logging.LogRecord) → bool

Removes exception stack traces information.

class smd.utils.Manga(path: str, title: str, url: str, site: str)

Class representing a manga folder.

chapters() → Iterator[Chapter]

Returns an iterator that yields chapters found in the manga folder

static from_folder(path: str) → smd.utils.Manga

Creates a Manga instance from a folder path.

Parameters:path – the path to the manga folder.
Returns:the created Manga instance.
get_new_chapter_path() → str

Generates a nonexistent chapter path. :return: a path to a chapter folder that don’t already exists.

class smd.utils.MetaFolder(path: str)

Abstract class representing a meta data folder.

data_file

The path to the meta data file.

static from_folder(path: str) → smd.utils.MetaFolder

Creates a MetaFolder instance from a folder path.

Parameters:path – path to a folder.
Returns:the created instance.
classmethod is_valid(path: str) → bool

Checks whether the given path is a valid MetaFolder or not.

Parameters:path – path to a folder.
Returns:True if the given folder is valid, False otherwise.
smd.utils.die(msg: str, status: int = 1) → NoReturn

Shows a message and terminates the program execution.

Parameters:
  • msg – the message to show before terminating the application.
  • status – the exit code.
smd.utils.get_mangas(path: str) → List[Manga]

Gets all mangas found in the given folder.

Parameters:path – path to a folder.
Returns:the list of mangas found.
smd.utils.get_text(tag: bs4.Tag) → str

Extracts the text from a BeautifulSoup tag.

Parameters:tag – the tag to extract text from.
Returns:the tag text without \n and with trailing white spaces removed.
smd.utils.mkdir(dirname: str, basename: str) → str

Tries to create a new folder basename in the folder dirname if the name of the new folder is invalid or already exists ask the user to enter a new one.

Parameters:
  • dirname – the parent directory of the new folder.
  • basename – the name of the folder.
Returns:

the path of the new created folder.

smd.utils.persistent_operation(function: Callable) → Callable

Makes the decorated function to excecute again on KeyboardInterrupt or SystemExit exceptions.

smd.utils.random_ua() → str

Generates a random User-Agent HTTP header.

smd.utils.select_chapters(chapters: List[Chapter], selectors_str: str) → List[Chapter]

Selects the chapters specified in the given selectors.

Parameters:
  • chapters – a list of chapters.
  • selectors – a string of comma-separated selectors.
Returns:

a list of selected chapters.

smd.utils.select_mangas(mangas: List[Manga], list_header: str = 'Found:', prompt_msg: str = 'Select a manga', multiple: bool = True) → List[Manga]

Lets the user select a manga from the given list, keeps asking if the user enters invalid option numbers.

Parameters:
  • mangas – a list of mangas.
  • list_header – the header message to show on top of the list.
  • prompt_msg – the message prompt.
  • multiple – if True allows to select multiple choices.
Returns:

the selected manga (or mangas).