The smd API reference¶
smd is a tool to search and download manga from online manga reading web sites.
-
smd.
get_args_parser
(version)¶ Creates an arguments parser for the program is command line interface.
Parameters: version (str) – the application is version number. Return type: argparse.ArgumentParser
-
smd.
show_copyright
()¶ Shows copyright notice.
smd.downloader¶
This module provides the downloaders able to grab content from the supported sites.
-
class
smd.downloader.
Downloader
(name, lang, site_url)¶ Abstract class base of all manga downloaders.
-
download
(manga, chapter_selectors=None)¶ Searches for the given manga and, if found, chapters specified in
chapter_selectors
are downloaded.Parameters: - manga (str) – the manga to download.
- chapter_selectors (str) – a string specifying the chapters to download.
Returns: True
if the manga was downloaded successfully,False
otherwise.
-
download_img
(url, name)¶ 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 (str) – the URL of the image.
- name (str) – the name to use for the saved image (without file extension)
Returns: the file name with file extension of the downloaded image.
Return type: str
-
get
(url, data=None, method='GET', xhr=False, decode=True)¶ Retrieves data from given URL.
Parameters: - url (str) – the URL to retrieve.
- data (dict) – the data to send with the request.
- method (str) – the method to use to request the URL (POST/GET).
- xhr (bool) – if
True
set the header ‘X-Requested-With’ to ‘XMLHttpRequest’ - decode (bool) – if
True
decode the response data.
Returns: the response data.
Raises: ConnectionResetError – if the connection is reset more than five times.
-
get_chapters
(manga_url)¶ Extracts the manga chapters from the given manga URL.
Parameters: manga_url (str) – the URL of a manga. Returns: a list of tuples each one with two strings: the title and URL of a chapter from the given manga.
-
classmethod
get_image
(image_url)¶ If needed, extracts the image link from the given URL.
Parameters: image_url (str) – the image URL or an URL to a page where the image link can be extracted. Returns: the image URL. Return type: str
-
get_images
(chapter_url)¶ Extracts the images links from a chapter URL.
Parameters: chapter_url (str) – 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
(url, data=None, method='GET')¶ Request json data from the given url.
Parameters: - url (str) – the URL to request.
- data (dict) – the data to send in the request.
- method (str) – the method to use for the request.
Returns: the response data object.
-
resume
(manga)¶ Continues with the (unfinished) download of the given manga.
Parameters: manga ( Manga
) – the manga to continue downloading.Returns: the number of resumed mangas. Return type: int
-
search
(manga)¶ Searches for mangas matching the given text.
Parameters: manga (str) – a frase or manga title to search. Returns: a list of tuples each one with two strings: the title and URL of a matched manga.
-
-
class
smd.downloader.
HeavenManga
¶ Downloads manga from heavenmanga.com.
-
get_chapters
(manga_url)¶ Extracts the manga chapters from the given manga URL.
Parameters: manga_url (str) – the URL of a manga. Returns: a list of tuples each one with two strings: the title and URL of a chapter from the given manga.
-
get_image
(image_url)¶ If needed, extracts the image link from the given URL.
Parameters: image_url (str) – the image URL or an URL to a page where the image link can be extracted. Returns: the image URL. Return type: str
-
get_images
(chapter_url)¶ Extracts the images links from a chapter URL.
Parameters: chapter_url (str) – 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)¶ Searches for mangas matching the given text.
Parameters: manga (str) – a frase or manga title to search. Returns: a list of tuples each one with two strings: the title and URL of a matched manga.
-
-
class
smd.downloader.
MangaAll
¶ Downloads manga from mangaall.net.
-
get_chapters
(manga_url)¶ Extracts the manga chapters from the given manga URL.
Parameters: manga_url (str) – the URL of a manga. Returns: a list of tuples each one with two strings: the title and URL of a chapter from the given manga.
-
get_image
(image_url)¶ If needed, extracts the image link from the given URL.
Parameters: image_url (str) – the image URL or an URL to a page where the image link can be extracted. Returns: the image URL. Return type: str
-
get_images
(chapter_url)¶ Extracts the images links from a chapter URL.
Parameters: chapter_url (str) – 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)¶ Searches for mangas matching the given text.
Parameters: manga (str) – a frase or manga title to search. Returns: a list of tuples each one with two strings: the title and URL of a matched manga.
-
-
class
smd.downloader.
MangaDoor
¶ Downloads manga from mangadoor.com.
-
get_chapters
(manga_url)¶ Extracts the manga chapters from the given manga URL.
Parameters: manga_url (str) – the URL of a manga. Returns: a list of tuples each one with two strings: the title and URL of a chapter from the given manga.
-
get_image
(image_url)¶ If needed, extracts the image link from the given URL.
Parameters: image_url (str) – the image URL or an URL to a page where the image link can be extracted. Returns: the image URL. Return type: str
-
get_images
(chapter_url)¶ Extracts the images links from a chapter URL.
Parameters: chapter_url (str) – 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)¶ Searches for mangas matching the given text.
Parameters: manga (str) – a frase or manga title to search. Returns: a list of tuples each one with two strings: the title and URL of a matched manga.
-
-
class
smd.downloader.
MangaHere
¶ Downloads manga from www.mangahere.cc.
-
get_chapters
(manga_url)¶ Extracts the manga chapters from the given manga URL.
Parameters: manga_url (str) – the URL of a manga. Returns: a list of tuples each one with two strings: the title and URL of a chapter from the given manga.
-
get_image
(image_url)¶ If needed, extracts the image link from the given URL.
Parameters: image_url (str) – the image URL or an URL to a page where the image link can be extracted. Returns: the image URL. Return type: str
-
get_images
(chapter_url)¶ Extracts the images links from a chapter URL.
Parameters: chapter_url (str) – 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)¶ Searches for mangas matching the given text.
Parameters: manga (str) – a frase or manga title to search. Returns: a list of tuples each one with two strings: the title and URL of a matched manga.
-
-
class
smd.downloader.
MangaNelo
¶ Downloads manga from manganelo.com.
-
get_chapters
(manga_url)¶ Extracts the manga chapters from the given manga URL.
Parameters: manga_url (str) – the URL of a manga. Returns: a list of tuples each one with two strings: the title and URL of a chapter from the given manga.
-
get_images
(chapter_url)¶ Extracts the images links from a chapter URL.
Parameters: chapter_url (str) – 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)¶ Searches for mangas matching the given text.
Parameters: manga (str) – a frase or manga title to search. Returns: a list of tuples each one with two strings: the title and URL of a matched manga.
-
-
class
smd.downloader.
MangaReader
¶ Downloads manga from www.mangareader.net.
-
get_chapters
(manga_url)¶ Extracts the manga chapters from the given manga URL.
Parameters: manga_url (str) – the URL of a manga. Returns: a list of tuples each one with two strings: the title and URL of a chapter from the given manga.
-
get_image
(image_url)¶ If needed, extracts the image link from the given URL.
Parameters: image_url (str) – the image URL or an URL to a page where the image link can be extracted. Returns: the image URL. Return type: str
-
get_images
(chapter_url)¶ Extracts the images links from a chapter URL.
Parameters: chapter_url (str) – 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)¶ Searches for mangas matching the given text.
Parameters: manga (str) – a frase or manga title to search. Returns: a list of tuples each one with two strings: the title and URL of a matched manga.
-
-
class
smd.downloader.
NineManga
(site)¶ Downloads manga from ninemanga.com.
-
get_chapters
(manga_url)¶ Extracts the manga chapters from the given manga URL.
Parameters: manga_url (str) – the URL of a manga. Returns: a list of tuples each one with two strings: the title and URL of a chapter from the given manga.
-
get_image
(image_url)¶ If needed, extracts the image link from the given URL.
Parameters: image_url (str) – the image URL or an URL to a page where the image link can be extracted. Returns: the image URL. Return type: str
-
get_images
(chapter_url)¶ Extracts the images links from a chapter URL.
Parameters: chapter_url (str) – 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)¶ Searches for mangas matching the given text.
Parameters: manga (str) – a frase or manga title to search. Returns: a list of tuples each one with two strings: the title and URL of a matched manga.
-
-
smd.downloader.
get_downloaders
()¶ Creates a list with instances of all supported downloaders.
Returns: the list of all supported downloaders. Return type: list of Downloader
smd.utils¶
This module provides utility functions and classes.
-
class
smd.utils.
Chapter
(path, title=None, url=None)¶ Class representing a chapter folder.
-
static
from_folder
(path)¶ Creates a
Chapter
instance from a folder path.Parameters: path (str) – the path to the chapter folder. Returns: the created Chapter
instance.
-
classmethod
is_chapter
(chapter_path)¶ Checks whether the given folder is a chapter folder or not.
Parameters: chapter_path (str) – path to a folder. Returns: True
if the given folder is a chapter,False
otherwise.
-
save_data
()¶ Saves chapter meta data.
-
static
-
class
smd.utils.
Config
(path)¶ Class to manage the configuration of
smd
-
exists
()¶ Checks if the configuration file already exists.
Returns: True
if the configuration file exists,False
otherwise.
-
load
()¶ Loads the configuration from disk.
Returns: a list with the loaded configuration files.
-
reset
()¶ Resets all configuration values to the defaults.
-
save
()¶ Saves the configuration to disk.
-
-
class
smd.utils.
ConsoleFilter
¶ A filter to avoid showing exceptions stack traces text in user’s terminal.
-
static
filter
(record)¶ Removes exception stack traces information.
-
static
-
class
smd.utils.
Manga
(path, title=None, url=None, site=None)¶ Class representing a manga folder.
-
chapters
¶ The chapters found in the manga folder
-
chapters_iter
()¶ Returns an iterator that yields chapters found in the manga folder
-
static
from_folder
(path)¶ Creates a
Manga
instance from a folder path.Parameters: path (str) – the path to the manga folder. Returns: the created Manga
instance.
-
classmethod
is_manga
(manga_path)¶ Checks whether the given folder is a manga folder or not.
Parameters: manga_path (str) – path to a folder. Returns: True
if the given folder is a manga,False
otherwise.
-
save_data
()¶ Saves manga meta data.
-
-
smd.utils.
create_config_folder
()¶ Creates the application is configuration folder.
Returns: the path to the configuration folder. Return type: str
-
smd.utils.
die
(msg, status=1)¶ Shows a message and terminates the program execution.
Parameters: - msg (str) – the message to show before terminating the application.
- status (int) – the exit code.
-
smd.utils.
download
(downloaders, manga, chapter_selectors, tryall)¶ Downloads the given manga using one of the given downloaders.
Parameters: - downloaders (list) – the downloaders.
- manga (str) – the manga name.
- chapter_selectors (str) – the chapters to download.
- tryall (bool) – when
True
if a downloader fail, then tries other downloaders.
Returns: True
if the download succeeded,False
otherwise.
-
smd.utils.
filter_downloaders
(lang, downloaders)¶ Selects from the given list, the downloaders with the given language.
Parameters: - lang (str) – the language of the downloaders to select.
- downloaders (list) – a list of downloaders
(
Downloader
).
Returns: a list of downloaders with the given language.
-
smd.utils.
get_mangas
(path)¶ Gets all mangas found in the given folder.
Parameters: path (str) – path to a folder. Returns: the list of mangas found.
-
smd.utils.
get_text
(tag)¶ Extracts the text from a BeautifulSoup tag.
Parameters: tag ( bs4.Tag
) – the tag to extract text from.Returns: the tag text without \n
and with trailing white spaces removed.
-
smd.utils.
keyboard_interrupt
(function)¶ Makes the decorated function to handle keyboard interrupt gracefully.
-
smd.utils.
list_downloaders
(downloaders)¶ Prints the list of the given downloaders (
Downloader
).Parameters: downloaders (list) – a list of downloaders.
-
smd.utils.
mkdir
(dirname, basename)¶ Tries to create a new folder
basename
in the folderdirname
if the name of the new folder is invalid or already exists ask the user to enter a new one.Parameters: - dirname (str) – the parent directory of the new folder.
- basename (str) – the name of the folder.
Returns: the path of the new created folder.
Return type: str
-
smd.utils.
resume
(downloaders, mangas)¶ Resumes a previously canceled manga download.
Parameters: - downloaders (list of
Downloader
) – the supported downloaders. - mangas – a list of paths to manga folders or a path to a folder where the manga folders are stored.
- downloaders (list of
-
smd.utils.
select_chapters
(chapters, selectors)¶ Selects the chapters specified in the given selectors.
Parameters: - chapters – a list of chapters (
Chapter
). - selectors (str) – a string of comma-separated selectors.
Returns: a set of selected chapters.
Return type: set
- chapters – a list of chapters (
-
smd.utils.
select_downloader
(downloaders)¶ Lets the user choose one downloader from the give list, keeps asking if the user enters invalid option.
Parameters: downloaders – a list of downloaders ( Downloader
).Returns: the selected downloader. Return type: Downloader
-
smd.utils.
select_lang
(langs)¶ Lets the user select a language from the given list, keeps asking if the user enters invalid option.
Parameters: langs (list) – the list of languages. Returns: the selected language.
-
smd.utils.
select_manga
(mangas, list_header='Found:', prompt_msg='Select a manga', multiple=False)¶ Lets the user select a manga from the given list, keeps asking if the user enters invalid option numbers.
Parameters: - mangas – a list containing the manga (
Manga
) choices. - list_header (str) – the header message to show on top of the list.
- prompt_msg (str) – the message prompt.
- multiple (bool) – if
True
allows to select multiple choices.
Returns: the selected manga (or mangas).
Return type: Manga
or list ofManga
- mangas – a list containing the manga (
-
smd.utils.
set_site
(site, downloaders)¶ Sets the downloader of the given site as the preferred.
Parameters: - site (str) – the site name (same as
smd.downloader.Downloader.name
) - downloaders – the list of supported downloaders
(
Downloader
).
- site (str) – the site name (same as
-
smd.utils.
update
(downloaders, mangas)¶ Updates a previously downloaded manga.
Parameters: - downloaders (list of
Downloader
) – the supported downloaders. - mangas – a list of paths to manga folders or a path to a folder where the manga folders are stored.
- downloaders (list of