add search method to kisscartoon

master
Vishnunarayan K I 2018-08-30 21:53:25 +05:30
parent 2f81c2281d
commit b46078677d
2 changed files with 35 additions and 4 deletions

View File

@ -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(

View File

@ -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]