A Python library for searching anime magnet links and torrents, with strong extensibility.
Supports searching anime resources from different sources through a plugin system, and can handle magnet links, file size conversion, and other functions.
Users of the old version should note that the project name has changed, so please reinstall it. Also, due to the refactoring of version 2.0, some APIs may have changed. It is recommended to check the documentation.
- Supports search functionality across multiple resource sites
- Extensible plugin system
- File size unit conversion
- CSV export functionality
- Magnet link handling
- Time format conversion
- Error handling mechanism
Animag can be easily installed using pip:
pip install animag
# Import the Searcher class
from animag import Searcher
# Create a Searcher instance
searcher = Searcher(plugin_name='dmhy',
no_search_errors=True)
# Search for anime (proxy is for demonstration only)
searcher.search("葬送的芙莉莲",
collected=True,
proxies={'http': 'http://localhost:6666',
'https': 'http://localhost:6666'})
# Print the search results
print(searcher.get_animes())
"""
Example output (results from December 22, 2024):
Search completed successfully: 葬送的芙莉莲
[Anime(time='2024/10/20 12:23', title='[7³ACG\u200b] \u200b葬送的芙莉莲/Sousou no Frieren S01 | 01-28 [简繁字幕] BDrip 1080p AV1 OPUS 2.0\u200b\u200b\u200b', size='17.1GB', magnet='magnet:?xt=urn:btih:...
"""
# Convert all results' file sizes to GB
searcher.size_format_all('MB')
# Save results to a CSV file
searcher.save_csv("search_results.csv")
Site | Plugin Parameter Name | Speed | Full Season Search | size | magnet | torrent | Notes |
---|---|---|---|---|---|---|---|
dmhy.org | dmhy | Moderate | ✅ | ✅ | ✅ | ❎ | None |
dmhy.org | dmhy_rss | Very Fast | ❎ | ❎ | ✅ | ❎ | None |
nyaa.si | nyaa | Very Fast | ❎ | ✅ | ✅ | ✅ | None |
nyaa.si | nyaa_rss | Very Fast | ❎ | ✅ | ✅ | ✅ | None |
acg.rip | acgrip | Moderate | ❎ | ✅ | ❎ | ✅ | None |
acg.rip | acgrip_rss | Slow | ❎ | ❎ | ❎ | ✅ | The maximum number of search pages is set to 5, as more will be blocked by the server. You can modify the MAX_PAGE in the module, but it is not recommended to exceed 9. |
www.tokyotosho.info | tokyotosho | Moderate | ❎ | ✅ | ✅ | ✅ | Requires English/Japanese search |
www.tokyotosho.info | tokyotosho_rss | Fast | ❎ | ✅ | ✅ | ✅ | Requires English/Japanese search |
animetosho.org | animetosho | Fast | ❎ | ✅ | ✅ | ✅ | Requires English search |
animetosho.org | animetosho_rss | Fast | ❎ | ✅ | ✅ | ✅ | Requires English search |
All plugins require a proxy to work properly. Ensure that the proxy settings are correctly configured. |
plugin_name
: Plugin name, default: 'dmhy'parser
: Parser option, not required for RSS plugins, default: 'lxml'verify
: Verification option, whether to verify SSL certificates, default: Truetimefmt
: Time format, default: '%Y/%m/%d %H:%M'no_search_errors
: Whether to ignore search errors, default: False
keyword
: Search keywordcollected
: Whether to collect resultsproxies
: Proxy settingssystem_proxy
: Whether to use system proxy**extra_options
: Additional options, which will be merged into the query string during search
The Anime
class is used to represent information about a single anime resource.
time
: Release timetitle
: Titlesize
: File sizemagnet
: Magnet linktorrent
: Torrent linkhash
: Hash value of the magnet link, does not exist if there is no magnet link
size_format()
: Convert file size unitset_timefmt()
: Convert time format
The Searcher
class is the core implementation of the search functionality.
- Initialize search plugins
- Execute search operations
- Process search results
- Export data
search()
: Search for anime resourcesget_anime()
: Get a single anime resourceget_animes()
: Get all anime resourcessize_format_all()
: Batch convert file size unitssave_csv()
: Save search results to a CSV fileset_timefmt()
: Set time format
The library defines various error types:
PluginImportError
: Plugin import errorSearchRequestError
: Search request errorSearchParseError
: Search result parsing errorSizeFormatError
: File size formatting errorTimeFormatError
: Time formatting errorHashExtractError
: Magnet link hash extraction errorSaveCSVError
: CSV save error
Animag supports installing custom search plugins. The plugin class must inherit from the BasePlugin
class and
implement the search()
method.
# myplugin.py
# The file name must be the lowercase plugin name
from animag import BasePlugin, Anime
from typing import List, Optional
class MyPlugin(BasePlugin):
abstract = False # This line must be set, otherwise it will not be recognized as a plugin
def __init__(self,
parser: Optional[str] = None,
verify: Optional[bool] = None,
timefmt: Optional[str] = None):
# Plugin initialization
pass
def search(self, keyword: str,
collected: Optional[bool] = None,
proxies: Optional[dict] = None,
system_proxy: Optional[bool] = None,
**extra_options) -> List[Anime] | None:
# Implement search logic
pass
After installing the custom plugin in the animag/plugins
directory, specify the plugin name as myplugin
when
initializing the searcher. If not installed in this directory, you can manually import the module into the namespace.
from animag import Searcher
searcher = Searcher(plugin_name='myplugin')
Or directly import the plugin module:
import myplugin
from animag import Searcher
searcher = Searcher(plugin_name='myplugin')
The project includes a CLI tool, implemented using the Rich library for beautiful console output, supporting interactive selection.
animag [-h] -s SEARCH [-p PLUGIN] [-c]
-s, --search: Search keyword
-h
,--help
: Show help information-p
,--plugin
: Specify search plugin (default: 'dmhy')-c
,--collected
: Enable full season search mode
# Basic search
animag -s "葬送的芙莉莲"
# Search using a specific plugin
animag -s "葬送的芙莉莲" -p nyaa
# Search for full season
animag -s "葬送的芙莉莲" -c
- The time format must comply with Python's time format string specification.