62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING
|
|
from bs4 import BeautifulSoup
|
|
import httpx
|
|
import requests
|
|
from data.path_constant import DOWNLOAD_DIR
|
|
from data.webtoon_request import get_bomtoon_headers
|
|
from downloaders.downloader import Downloader
|
|
|
|
|
|
class Bomtoon(Downloader):
|
|
def __init__(self, webtoon_id):
|
|
super().__init__(webtoon_id)
|
|
|
|
self.headers = get_bomtoon_headers()
|
|
|
|
def _fetch_information(self, url):
|
|
res = requests.get(url, headers=self.headers)
|
|
|
|
if res.status_code == 200:
|
|
soup = BeautifulSoup(res.content, 'html.parser')
|
|
title = soup.find('title')
|
|
if title:
|
|
self.title = title.get_text().split('-')[0].strip()
|
|
|
|
author = soup.find('meta', attrs={'name': 'author'})
|
|
if author:
|
|
self.author = author.get('content')
|
|
|
|
description = soup.find('meta', attrs={'property': 'og:description'})
|
|
if description:
|
|
self.description = description.get('content')
|
|
|
|
tags = soup.find('meta', attrs={'name': 'keywords'})
|
|
if tags:
|
|
tags_list = tags.get('content').split(',')
|
|
if '連載' in tags_list[0]:
|
|
self.tag = tags_list[1]
|
|
else:
|
|
self.tag = tags_list[0]
|
|
|
|
self.thumbnail_url = ""
|
|
self.thumbnail_name = self.webtoon_id + '.jpg'
|
|
else:
|
|
print(f"fetch_information: {res.status_code}")
|
|
|
|
|
|
def _fetch_episode_information(self):
|
|
pass
|
|
|
|
|
|
def _get_episode_image_urls(self, episode_index) -> list[str]:
|
|
pass
|
|
|
|
async def _download_image(
|
|
self,
|
|
episode_path: Path,
|
|
url: str,
|
|
image_no: int
|
|
) -> None:
|
|
pass |