[summary] Get click url and download url from episode url >>> type(get_anime_episode("/watch/kimetsu-no-yaiba/1")) Args: episode_endpoint (str): [Endpoint of episode] Raises: e: [description] Returns: [list]: [List of download and w
(episode_endpoint: str)
| 123 | |
| 124 | |
| 125 | def get_anime_episode(episode_endpoint: str) -> list: |
| 126 | """[summary] |
| 127 | |
| 128 | Get click url and download url from episode url |
| 129 | |
| 130 | >>> type(get_anime_episode("/watch/kimetsu-no-yaiba/1")) |
| 131 | <class 'list'> |
| 132 | |
| 133 | Args: |
| 134 | episode_endpoint (str): [Endpoint of episode] |
| 135 | |
| 136 | Raises: |
| 137 | e: [description] |
| 138 | |
| 139 | Returns: |
| 140 | [list]: [List of download and watch url] |
| 141 | """ |
| 142 | |
| 143 | episode_page_url = f"{BASE_URL}{episode_endpoint}" |
| 144 | |
| 145 | response = httpx.get( |
| 146 | url=episode_page_url, headers={"User-Agent": UserAgent().chrome}, timeout=10 |
| 147 | ) |
| 148 | response.raise_for_status() |
| 149 | |
| 150 | soup = BeautifulSoup(response.text, "html.parser") |
| 151 | |
| 152 | url = soup.find("iframe", {"id": "playerframe"}) |
| 153 | if url is None or isinstance(url, NavigableString): |
| 154 | msg = f"Could not find url and download url from {episode_endpoint}" |
| 155 | raise RuntimeError(msg) |
| 156 | |
| 157 | episode_url = url["src"] |
| 158 | if not isinstance(episode_url, str): |
| 159 | msg = f"Could not find url and download url from {episode_endpoint}" |
| 160 | raise RuntimeError(msg) |
| 161 | download_url = episode_url.replace("/embed/", "/playlist/") + ".m3u8" |
| 162 | |
| 163 | return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"] |
| 164 | |
| 165 | |
| 166 | if __name__ == "__main__": |
no test coverage detected