示例#1
0
 def build_anime_meta(self, hash_str: str):
     """尝试通过 hash 生成一个 AnimeMetaInfo"""
     try:
         engine, detail_page_url = b16decode(hash_str.upper()).decode("utf-8").split("|")
         meta = AnimeMetaInfo()
         meta.engine = engine
         meta.detail_page_url = detail_page_url
         logger.debug(f"Build AnimeMetaInfo from hash {hash_str}")
         logger.debug(f"engine: {engine} detail_page_url: {detail_page_url}")
         return meta
     except Exception:
         return
示例#2
0
    def parse_one_page(self, keyword: str, page: int):
        url = f"{self._base_url}/vodsearch/{keyword}----------{page}---.html"
        resp = self.get(url)
        if resp.status_code != 200:
            return [], ""
        if "请输入验证码" in resp.text:
            logger.error(
                "We are blocked by K1080P, need to enter the verification code."
            )
            return [], ""

        ret = []
        meta_list = self.xpath(
            resp.text,
            "//ul[@class='stui-vodlist__media col-pd clearfix']//li")
        for meta in meta_list:
            anime = AnimeMetaInfo()
            cover_url = meta.xpath("./div[@class='thumb']/a/@data-original")[0]
            if not cover_url.startswith("http"):
                cover_url = self._base_url + cover_url
            anime.cover_url = cover_url
            anime.title = meta.xpath("./div[@class='detail']/h3/a/text()")[0]
            anime.detail_page_url = meta.xpath(
                "./div[@class='detail']/h3/a/@href")[
                    0]  # /voddetail/414362.html
            desc = meta.xpath(
                "./div[@class='detail']//span[contains(text(),'简介')]/parent::p/text()"
            )
            anime.desc = desc[0] if desc else "无简介"
            anime.category = meta.xpath(
                "./div[@class='detail']//span[contains(text(),'类型')]/parent::p/text()"
            )[0]
            ret.append(anime)
        return ret, resp.text
示例#3
0
    def parse_one_page(self, keyword: str, page: int):
        """处理一页的所有番剧摘要信息, 同时返回当前页面的 HTML"""
        logger.info(f"Searching for: {keyword}, page: {page}")
        resp = self.get(self._search_api,
                        params={
                            'query': keyword,
                            'page': page
                        })
        if resp.status_code != 200 or "0纪录" in resp.text:
            logger.info(f"No search result for {keyword}")
            return [], ""

        ret = []
        anime_meta_list = self.xpath(
            resp.text,
            '//div[@class="cell blockdiff2"] | //div[@class="cell blockdiff"]')
        for meta in anime_meta_list:
            anime = AnimeMetaInfo()
            anime.title = meta.xpath(
                './/a[@class="cell_imform_name"]/text()')[0]
            anime.cover_url = "https:" + meta.xpath(
                './/a[@class="cell_poster"]/img/@src')[0]
            anime.category = meta.xpath(
                '//div[@class="cell_imform_kv"][7]/span[2]/text()')[0]
            anime.detail_page_url = meta.xpath("a/@href")[
                0]  # "/detail/20170172"
            ret.append(anime)
        return ret, resp.text
示例#4
0
    def search(self, keyword: str):
        logger.info(f"Searching for: {keyword}")
        resp = self.get(self._search_api, params={"limit": "100", "key": keyword, "page": "1"}, headers=self._headers)
        if resp.status_code != 200 or resp.json()["data"]["total"] == 0:
            logger.warning(f"Response error: {resp.status_code} {self._search_api}")
            return

        anime_meta_list = resp.json().get("data").get("items")
        for meta in anime_meta_list:
            anime = AnimeMetaInfo()
            anime.title = meta["name"]
            anime.cover_url = meta["pic"]
            anime.category = meta["type"]
            anime.detail_page_url = meta["id"]
            yield anime
示例#5
0
    def search(self, keyword: str):
        logger.info(f"Searching for: {keyword}")
        resp = self.post(self._search_api, data={"userid": "", "key": keyword})
        if resp.status_code != 200:
            logger.warning(
                f"Response error: {resp.status_code} {self._search_api}")
            return

        anime_meta_list = resp.json().get("data")
        for meta in anime_meta_list:
            anime = AnimeMetaInfo()
            anime.title = meta["videoName"]
            anime.cover_url = meta["videoImg"]
            anime.category = meta["videoClass"]
            anime.detail_page_url = meta["videoId"]
            yield anime
示例#6
0
    def parse_one_page(self, keyword: str, page: int):
        logger.info(f"Searching for {keyword}, page {page}")
        resp = self.get(self._search_api + "/" + keyword,
                        params={"page": page})
        if resp.status_code != 200:
            logger.warning(
                f"Response error: {resp.status_code} {self._search_api}")
            return [], ""

        anime_meta_list = self.xpath(resp.text, '//div[@class="lpic"]//li')
        ret = []
        for meta in anime_meta_list:
            anime = AnimeMetaInfo()
            anime.title = " ".join(meta.xpath(".//h2/a/@title"))
            anime.cover_url = meta.xpath("./a/img/@src")[0]
            anime.category = " ".join(meta.xpath("./span[2]/a/text()"))
            anime.desc = meta.xpath("./p/text()")[0]
            anime.detail_page_url = meta.xpath("./a/@href")[
                0]  # /show/5031.html
            ret.append(anime)
        return ret, resp.text
示例#7
0
 def search(self, keyword: str):
     payload = {
         "service": "App.Vod.Search",
         "search": keyword,
         "page": 1,
         "perpage": 50,
         "versionCode": 60,
     }
     payload.update(self.encrypt())
     resp = self.post(self._api, data=payload)
     if resp.status_code != 200:
         return
     data = resp.json()
     data = list(filter(lambda x: x["type"] == "vod", data["data"]))[0]
     for item in data["videos"]:
         anime = AnimeMetaInfo()
         anime.title = item["vod_name"]
         anime.category = item["vod_type"]
         anime.cover_url = item["vod_pic"]
         anime.desc = item["vod_keywords"] + " 豆瓣评分:" + item["vod_douban_score"]
         anime.detail_page_url = str(item["vod_id"])  # 详情页id参数
         yield anime
示例#8
0
    def search(self, keyword: str):
        logger.info(f"Searching for: {keyword}")
        resp = self.get(self._search_api,
                        params={
                            "kw": keyword,
                            "per_page": 100,
                            "page": 1
                        })  # 取前 100 条结果
        if resp.status_code != 200 or resp.json()["code"] != 1:
            logger.warning(
                f"Response error: {resp.status_code} {self._search_api}")
            return

        data = resp.json()
        anime_meta_list = data.get("data").get("data") if data else []
        for meta in anime_meta_list:
            anime = AnimeMetaInfo()
            anime.title = meta["name"]
            anime.cover_url = meta["pic"]
            anime.category = meta["type"]
            anime.detail_page_url = str(meta["vid"])
            anime.desc = meta["label"]
            yield anime