diff --git a/README.md b/README.md index 456013e..472b9fa 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ Yeah. Me too! That's why this tool exists. - Animesimple - Animerush - Watchmovie +- Nyaa.si - twist.moe - requires Node.js - Kissanime - requires Node.js - Kisscartoon - requires Node.js diff --git a/anime_downloader/config.py b/anime_downloader/config.py index 132aee1..9270b61 100644 --- a/anime_downloader/config.py +++ b/anime_downloader/config.py @@ -19,6 +19,7 @@ DEFAULT_CONFIG = { 'file_format': '{anime_title}/{anime_title}_{ep_no}', 'provider': 'twist.moe', 'external_downloader': '', + 'aria2c_for_torrents': False, }, 'watch': { 'quality': '1080p', diff --git a/anime_downloader/sites/init.py b/anime_downloader/sites/init.py index b143b41..f426257 100644 --- a/anime_downloader/sites/init.py +++ b/anime_downloader/sites/init.py @@ -20,7 +20,8 @@ ALL_ANIME_SITES = [ ('ryuanime', 'ryuanime', 'RyuAnime'), ('erairaws', 'erai-raws', 'EraiRaws'), ('watchmovie','watchmovie','WatchMovie'), - ('animekisa','animekisa','AnimeKisa') + ('animekisa','animekisa','AnimeKisa'), + ('nyaa','nyaa','Nyaa') ] diff --git a/anime_downloader/sites/nyaa.py b/anime_downloader/sites/nyaa.py new file mode 100644 index 0000000..0aaa574 --- /dev/null +++ b/anime_downloader/sites/nyaa.py @@ -0,0 +1,28 @@ +import re + +from anime_downloader.sites.anime import Anime, AnimeEpisode, SearchResult +from anime_downloader.sites import helpers + +class Nyaa(Anime, sitename = 'nyaa'): + sitename = 'nyaa' + url = f'https://{sitename}.si' + @classmethod + def search(cls,query): + rex = r'(magnet:)+[^"]*' + search_results = helpers.soupify(helpers.get(f"https://nyaa.si/?f=2&c=1_2&q={query}&s=seeders&o=desc")) + + search_results = [ + SearchResult( + title = i.select("a:not(.comments)")[1].get("title") + ' | '+ i.find_all('td',class_ = 'text-center')[1].text, + url = i.find_all('a',{'href':re.compile(rex)})[0].get('href')) + for i in search_results.select("tr.default,tr.success") + ] + + return search_results + + def _scrape_episodes(self): + return [self.url] #the magnet has all episodes making this redundant + +class NyaaEpisode(AnimeEpisode, sitename='nyaa'): + def _get_sources(self): + return [('no_extractor', self.url,)] diff --git a/anime_downloader/util.py b/anime_downloader/util.py index 423a871..bb7ed60 100644 --- a/anime_downloader/util.py +++ b/anime_downloader/util.py @@ -194,6 +194,10 @@ def format_filename(filename, episode): def format_command(cmd, episode, file_format, path): + from anime_downloader.config import Config + if not Config._CONFIG['dl']['aria2c_for_torrents'] and episode.url.startswith('magnet:?xt=urn:btih:'): + return ['open',episode.url] + cmd_dict = { '{aria2}': 'aria2c {stream_url} -x 12 -s 12 -j 12 -k 10M -o ' '{file_format}.mp4 --continue=true --dir={download_dir}' @@ -203,7 +207,7 @@ def format_command(cmd, episode, file_format, path): rep_dict = { - 'stream_url': episode.source().stream_url, + 'stream_url': episode.source().stream_url if not episode.url.startswith('magnet:?xt=urn:btih:') else episode.url, 'file_format': file_format, 'download_dir': os.path.abspath(path), 'referer': episode.source().referer, @@ -231,6 +235,20 @@ def eval_in_node(js: str): output = subprocess.check_output(['node', '-e', js]) return output.decode('utf-8') +def open_magnet(magnet): + if sys.platform.startswith('linux'): + subprocess.Popen(['xdg-open', magnet], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + elif sys.platform.startswith('win32'): + os.startfile(magnet) + elif sys.platform.startswith('cygwin'): + os.startfile(magnet) + elif sys.platform.startswith('darwin'): + subprocess.Popen(['open', magnet], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + else: + subprocess.Popen(['xdg-open', magnet], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) def external_download(cmd, episode, file_format, path=''): @@ -242,13 +260,16 @@ def external_download(cmd, episode, file_format, path=''): logger.debug('formatted cmd: ' + ' '.join(cmd)) - p = subprocess.Popen(cmd) - return_code = p.wait() + if cmd[0] == 'open': #for torrents + open_magnet(cmd[1]) + else: + p = subprocess.Popen(cmd) + return_code = p.wait() - if return_code != 0: - # Sleep for a while to make sure downloader exits correctly - time.sleep(2) - sys.exit(1) + if return_code != 0: + # Sleep for a while to make sure downloader exits correctly + time.sleep(2) + sys.exit(1) def make_dir(path):