From b46078677dda3a40b816162e94f3163d980aa0f0 Mon Sep 17 00:00:00 2001 From: Vishnunarayan K I Date: Thu, 30 Aug 2018 21:53:25 +0530 Subject: [PATCH] add search method to kisscartoon --- anime_downloader/cli.py | 4 +-- anime_downloader/sites/kisscartoon.py | 35 +++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/anime_downloader/cli.py b/anime_downloader/cli.py index a057a24..7225182 100644 --- a/anime_downloader/cli.py +++ b/anime_downloader/cli.py @@ -64,7 +64,7 @@ def cli(): @click.option( '--provider', help='The anime provider (website) for search.', - type=click.Choice(['9anime', 'kissanime', 'twist.moe', 'animepahe']) + type=click.Choice(['9anime', 'kissanime', 'twist.moe', 'animepahe', 'kisscartoon']) ) @click.option( '--external-downloader', '-xd', @@ -171,7 +171,7 @@ def dl(ctx, anime_url, episode_range, url, player, skip_download, quality, @click.option( '--provider', help='The anime provider (website) for search.', - type=click.Choice(['9anime', 'kissanime', 'twist.moe']) + type=click.Choice(['9anime', 'kissanime', 'twist.moe', 'kisscartoon']) ) @click.option( diff --git a/anime_downloader/sites/kisscartoon.py b/anime_downloader/sites/kisscartoon.py index c276cfe..ecc9599 100644 --- a/anime_downloader/sites/kisscartoon.py +++ b/anime_downloader/sites/kisscartoon.py @@ -1,9 +1,14 @@ from anime_downloader.sites.kissanime import KissAnime -from anime_downloader.sites.anime import BaseEpisode +from anime_downloader.sites.anime import BaseEpisode, SearchResult from anime_downloader.sites.exceptions import NotFoundError -from anime_downloader.const import desktop_headers +from anime_downloader.const import desktop_headers, get_random_header import requests +from bs4 import BeautifulSoup +import cfscrape +import logging + +scraper = cfscrape.create_scraper() class KisscartoonEpisode(BaseEpisode): @@ -37,6 +42,32 @@ class KissCartoon(KissAnime): sitename = 'kisscartoon' _episodeClass = KisscartoonEpisode + @classmethod + def search(cls, query): + headers = get_random_header() + headers['referer'] = 'http://kisscartoon.ac/' + res = scraper.get( + 'http://kisscartoon.ac/Search/', + params={ + 's': query, + }, + headers=headers, + ) + logging.debug('Result url: {}'.format(res.url)) + + soup = BeautifulSoup(res.text, 'html.parser') + ret = [] + for res in soup.select_one('.listing').find_all('a'): + res = SearchResult( + title=res.text.strip('Watch '), + url=res.get('href'), + poster='', + ) + logging.debug(res) + ret.append(res) + + return ret + def _scarpe_episodes(self, soup): ret = soup.find('div', {'class': 'listing'}).find_all('a') ret = [str(a['href']) for a in ret]