diff --git a/.idea/Bangumi_Auto_Rename.iml b/.idea/Bangumi_Auto_Rename.iml index d9f760d3..25a1b778 100644 --- a/.idea/Bangumi_Auto_Rename.iml +++ b/.idea/Bangumi_Auto_Rename.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index e863a931..37b833f1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/auto_bangumi/app.py b/auto_bangumi/app.py index a31fe604..a6841ace 100644 --- a/auto_bangumi/app.py +++ b/auto_bangumi/app.py @@ -49,7 +49,7 @@ def show_info(): logger.info(" /_/ \_\__,_|\__\___/|____/ \__,_|_| |_|\__, |\__,_|_| |_| |_|_|") logger.info(" __/ | ") logger.info(" |___/ ") - logger.info("Version 2.4.9 Author: EstrellaXD Twitter: https://twitter.com/Estrella_Pan") + logger.info("Version 2.4.10 Author: EstrellaXD Twitter: https://twitter.com/Estrella_Pan") logger.info("GitHub: https://github.com/EstrellaXD/Auto_Bangumi/") logger.info("Starting AutoBangumi...") @@ -84,7 +84,7 @@ def run(): download_client.add_rules(bangumi_data["bangumi_info"]) if bangumi_data["first_run"]: logger.info(f"Waiting for downloading torrents...") - time.sleep(600) + time.sleep(settings.first_sleep) bangumi_data["first_run"] = False save_data_file(bangumi_data) renamer.run() @@ -94,6 +94,5 @@ def run(): raise e logger.exception(e) - if __name__ == "__main__": run() diff --git a/auto_bangumi/const.py b/auto_bangumi/const.py index f17eedd3..528caa7c 100644 --- a/auto_bangumi/const.py +++ b/auto_bangumi/const.py @@ -17,7 +17,8 @@ DEFAULT_SETTINGS = { "remove_bad_torrent": False, "dev_debug": False, "data_version": 3.1, - "enable_eps_complete": False + "enable_eps_complete": False, + "first_sleep": 600 } ENV_TO_ATTR = { @@ -36,7 +37,8 @@ ENV_TO_ATTR = { lambda e: e.lower() in ("true", "1", "t") ), "AB_SEASON_ONE": ("season_one_tag", lambda e: e.lower() in ("true", "1", "t")), - "AB_REMOVE_BAD_BT": ("remove_bad_torrent", lambda e: e.lower() in ("true", "1", "t")) + "AB_REMOVE_BAD_BT": ("remove_bad_torrent", lambda e: e.lower() in ("true", "1", "t")), + "AB_FIRST_SLEEP": "first_sleep" } FULL_SEASON_SUPPORT_GROUP = ["Lilith-Raws"] diff --git a/resource/anidb.py b/resource/anidb.py index 8902216b..4ea62aa3 100644 --- a/resource/anidb.py +++ b/resource/anidb.py @@ -1,8 +1,11 @@ #! /usr/bin/python import re +import time + import requests from bs4 import BeautifulSoup from utils import json_config +from const import BCOLORS header = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ApplewebKit/537.36 (KHtml, like Gecko) Chrome/80.0.3987.163 Safari/537.36', @@ -26,7 +29,7 @@ def get_list(year, season): return ids -def get_title(id): +def get_title_legecy(id): url = "https://anidb.net/anime/%s" % id soup = BeautifulSoup(get_html(url), "lxml") titles = soup.find("div", id="tab_2_pane") @@ -63,14 +66,42 @@ def get_title(id): t_dic["kana"] = v[i].text return t_dic + +def get_title(id): + url = f"http://api.anidb.net:9001/httpapi?request=anime&client=autobangumi&clientver=1&protover=1&aid={id}" + req = requests.get(url) + soup = BeautifulSoup(req.text, "xml") + titles = soup.titles.find_all("title") + all_title_info = { + "id": id, + "main": None, + "en": None, + "zh-Hans": None, + "zh-Hant": None, + "ja": None, + "other": [] + } + for title in titles: + if title["type"] == "main": + all_title_info["main"] = title.string + elif title["type"] == "official": + if title["xml:lang"] in ["en", "zh-Hant", "zh-Hans", "ja"]: + all_title_info[title["xml:lang"]] = title.string + else: + break + elif title["type"] == "synonym": + all_title_info["other"].append(title.string) + else: + break + return all_title_info + + if __name__ == "__main__": - print("start") - # 年份,季度 - id_list = (get_list(2022, 1)) - for i in id_list: - url = f"http://api.anidb.net:9001/httpapi?request=anime&client=autobangumi&clientver=1&protover=1&aid={i}" - req = requests.get(url) - soup = BeautifulSoup(req.text, "xml") - titles = soup.find("titles")["official"] - for item in titles: - print(item) + ids = get_list(2022, 2) + json = [] + for id in ids: + data = get_title(id) + print(data) + time.sleep(2.5) + json.append(data) + json_config.save("season_summer.json", json)