Initial commit: Add webtoon downloader
This commit is contained in:
99
main.py
Normal file
99
main.py
Normal file
@@ -0,0 +1,99 @@
|
||||
import argparse
|
||||
|
||||
from converter.converter import WebtoonConverter
|
||||
from data.kakao_cookie import COOKIE_NAME, COOKIES, TASK_TYPE, URL_TYPE
|
||||
from data.special_list import KAKAO_1, KAKAO_3, KAKAO_7, KAKAO_PAY, WEBTOON_NOT_PROCESSED, KAKAO_ONLY_MAIN_ACCOUNT
|
||||
from data.path_constant import DOWNLOAD_DIR, DOWNLOAD_LIST_TXT
|
||||
from downloaders.bomtoon import Bomtoon
|
||||
from downloaders.kakao_webtoon import KakaoWebtoon
|
||||
from prerequisite import get_download_list
|
||||
from downloaders.webtoon_com import Webtoon
|
||||
|
||||
DOWNLOAD_WEBTOON = True
|
||||
CONVERT_ALL = False
|
||||
|
||||
valid_cookies = []
|
||||
new_webtoons = []
|
||||
|
||||
def set_valid_cookie():
|
||||
global valid_cookies
|
||||
for cookie in COOKIES:
|
||||
if cookie.name == COOKIE_NAME:
|
||||
print(cookie.name)
|
||||
valid_cookies.append(cookie)
|
||||
|
||||
def get_kakao_urls(inputs):
|
||||
result = []
|
||||
if '1' in inputs:
|
||||
result += KAKAO_1
|
||||
if '3' in inputs:
|
||||
result += KAKAO_3
|
||||
if '7' in inputs:
|
||||
result += KAKAO_7
|
||||
if 'm' in inputs:
|
||||
result += KAKAO_ONLY_MAIN_ACCOUNT
|
||||
if 'p' in inputs:
|
||||
result += KAKAO_PAY
|
||||
return result
|
||||
|
||||
def download():
|
||||
if len(valid_cookies) > 0:
|
||||
url_list = get_download_list(DOWNLOAD_LIST_TXT)
|
||||
|
||||
for url in url_list:
|
||||
webtoon = None
|
||||
if 'tw.kakaowebtoon.com' in url:
|
||||
webtoon_id = url.split('/')[-1]
|
||||
for cookie in valid_cookies:
|
||||
if webtoon_id in get_kakao_urls(URL_TYPE):
|
||||
webtoon = KakaoWebtoon(webtoon_id, cookie)
|
||||
webtoon.download_webtoon(url, DOWNLOAD_DIR)
|
||||
elif DOWNLOAD_WEBTOON and 'www.webtoons.com' in url:
|
||||
webtoon_id = url.split('=')[1]
|
||||
webtoon = Webtoon(webtoon_id)
|
||||
webtoon.download_webtoon(url, DOWNLOAD_DIR)
|
||||
elif 'www.bomtoon.tw' in url:
|
||||
webtoon_id = url.split('/')[-1]
|
||||
webtoon = Bomtoon(webtoon_id)
|
||||
webtoon.download_webtoon(url, DOWNLOAD_DIR)
|
||||
if webtoon is not None and webtoon.new_webtoon != "":
|
||||
new_webtoons.append(webtoon.new_webtoon)
|
||||
print(new_webtoons)
|
||||
|
||||
def convert():
|
||||
for webtoon_path in DOWNLOAD_DIR.iterdir():
|
||||
if len(new_webtoons) > 0:
|
||||
if webtoon_path.is_dir() and webtoon_path.name in new_webtoons:
|
||||
print(webtoon_path)
|
||||
converter = WebtoonConverter(webtoon_path)
|
||||
converter.do_convert()
|
||||
elif webtoon_path.is_dir() and CONVERT_ALL and webtoon_path.name not in WEBTOON_NOT_PROCESSED:
|
||||
print(webtoon_path)
|
||||
converter = WebtoonConverter(webtoon_path)
|
||||
converter.do_convert()
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Run download or convert")
|
||||
parser.add_argument('function', nargs='?', choices=['download', 'convert'], help="Function to run")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.function == 'download':
|
||||
download()
|
||||
elif args.function == 'convert':
|
||||
convert()
|
||||
else:
|
||||
download()
|
||||
convert()
|
||||
|
||||
if __name__ == "__main__":
|
||||
set_valid_cookie()
|
||||
|
||||
task = TASK_TYPE
|
||||
|
||||
if 'd' in task:
|
||||
download()
|
||||
if 'c' in task:
|
||||
convert()
|
||||
print('MyWebtoon')
|
||||
|
||||
Reference in New Issue
Block a user