diff --git a/.dockerignore b/.dockerignore index 3d5cb7ed..e597ba6b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -19,8 +19,8 @@ coverage.xml .pytest_cache .hypothesis -module/tests -module/conf/const_dev.py +src/module/tests +src/module/conf/const_dev.py config/bangumi.json/config/bangumi.json /docs /.github diff --git a/.github/workflows/dev-latest.yml b/.github/workflows/dev-latest.yml index 2071149a..da55a6dc 100644 --- a/.github/workflows/dev-latest.yml +++ b/.github/workflows/dev-latest.yml @@ -12,7 +12,7 @@ jobs: uses: actions/checkout@v3 - name: Create Version info run: | - echo "VERSION = '2.6.0-beta'" > module/conf/version.py + echo "VERSION = '2.6.0-beta'" > module/__version__.py - name: Set up QEMU uses: docker/setup-qemu-action@v2 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d25d4aad..caa3c847 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v3 - name: Create Version info run: | - echo "version='$GITHUB_REF_NAME'" > module/conf/version.py + echo "version='$GITHUB_REF_NAME'" > src/module/__version__.py - name: Docker meta id: meta uses: docker/metadata-action@v4 diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 94a59282..03b0584a 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -17,17 +17,18 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Python 3.10 + - name: Set up Python 3.11 uses: actions/setup-python@v3 with: - python-version: "3.10" + python-version: "3.11" - name: Install dependencies run: | python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt; fi pip install pytest - mkdir config - name: Test - run: pytest test/test_raw_parser.py \ No newline at end of file + run: | + cd src + pytest test/test_raw_parser.py \ No newline at end of file diff --git a/.gitignore b/.gitignore index d2eda412..770d221f 100644 --- a/.gitignore +++ b/.gitignore @@ -162,21 +162,19 @@ cython_debug/ #.idea/ # Custom -/module/conf/const_dev.py -/config -/module/tester.py -/module/config +/src/test.py -/module/parser/analyser/tmdb_parser.py +/src/module/parser/analyser/tmdb_parser.py -/module/run_debug.sh -/module/debug_run.sh -/module/__version__.py -/data/ +/src/module/run_debug.sh +/src/module/debug_run.sh +/src/module/__version__.py +/src/data/ -/module/conf/config_dev.ini +/src/module/conf/config_dev.ini test.* .run -/module/conf/version.py -/templates/ + +/src/templates/ +/src/config/ diff --git a/Dockerfile b/Dockerfile index 9035d817..cc6fddc1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ ENV TZ=Asia/Shanghai \ WORKDIR /app COPY --from=build --chmod=777 /install /usr/local -COPY --chmod=755 . /app +COPY --chmod=755 src/. /app RUN apk add --no-cache \ curl \ diff --git a/main.py b/main.py deleted file mode 100644 index 29fffaab..00000000 --- a/main.py +++ /dev/null @@ -1,16 +0,0 @@ -from module import app -from module import api - -import multiprocessing - -if __name__ == "__main__": - num_processes = 2 - processes = [] - p1 = multiprocessing.Process(target=app.run) - p2 = multiprocessing.Process(target=api.run) - process_list = [p1, p2] - for p in process_list: - p.start() - processes.append(p) - for p in processes: - p.join() \ No newline at end of file diff --git a/module/core/__init__.py b/module/core/__init__.py deleted file mode 100644 index 4ba677f3..00000000 --- a/module/core/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .download_client import DownloadClient -from .eps_complete import FullSeasonGet -from .renamer import Renamer -from .rss_analyser import RSSAnalyser -from .api_func import APIProcess diff --git a/setup.py b/setup.py deleted file mode 100644 index dafa12a7..00000000 --- a/setup.py +++ /dev/null @@ -1,27 +0,0 @@ -# coding:utf-8 - -from setuptools import setup, find_packages - -setup( - name="auto_bangumi", # 包名字 - version="2.4.0b4", # 包版本 - description="一个全自动追番整理下载工具", - long_description=""" - 本项目是基于 Mikan Project、qBittorrent 的全自动追番整理下载工具。 - 只需要在 Mikan Project 上订阅番剧,就可以全自动追番。 - 并且整理完成的名称和目录可以直接被 Plex、Jellyfin 等媒体库软件识别, - 无需二次刮削。""", # 简单描述 - author="EstrellaXD", # 作者 - author_email="estrellaxd05@gmail.com", # 作者邮箱 - url="https://github.com/EstrellaXD/Auto_Bangumi", # 包的主页 - packages=find_packages(where=".", exclude=("tests",), include=('*',)), - package_data={"auto_bangumi.RssFilter": ["*.json"]}, - package_dir={"auto_bangumi": "auto_bangumi"}, - install_requires= [ - "qbittorrent-api", - "bs4", - "requests", - "lxml", - "zhconv", - ] -) diff --git a/src/main.py b/src/main.py new file mode 100644 index 00000000..1b22df76 --- /dev/null +++ b/src/main.py @@ -0,0 +1,18 @@ +from module import app +from module import api + +import multiprocessing + +if __name__ == "__main__": + # num_processes = 2 + # processes = [] + # p1 = multiprocessing.Process(target=app.run) + # p2 = multiprocessing.Process(target=api.run) + # process_list = [p1, p2] + # for p in process_list: + # p.start() + # processes.append(p) + # for p in processes: + # p.join() + app.run() + diff --git a/module/__init__.py b/src/module/__init__.py similarity index 100% rename from module/__init__.py rename to src/module/__init__.py diff --git a/module/ab_decorator/__init__.py b/src/module/ab_decorator/__init__.py similarity index 100% rename from module/ab_decorator/__init__.py rename to src/module/ab_decorator/__init__.py diff --git a/module/api.py b/src/module/api.py similarity index 100% rename from module/api.py rename to src/module/api.py diff --git a/module/app.py b/src/module/app.py similarity index 92% rename from module/app.py rename to src/module/app.py index 9d10ea1c..6904f384 100644 --- a/module/app.py +++ b/src/module/app.py @@ -5,8 +5,9 @@ import logging from module.conf import settings, setup_logger, LOG_PATH, DATA_PATH, VERSION from module.utils import json_config -from module.core import RSSAnalyser, DownloadClient, Renamer, FullSeasonGet - +from module.core import DownloadClient +from module.manager import Renamer, FullSeasonGet +from module.rss import RSSAnalyser logger = logging.getLogger(__name__) @@ -28,8 +29,8 @@ def load_data_file(): bangumi_data = json_config.load(DATA_PATH) if bangumi_data["data_version"] != settings.program.data_version or bangumi_data["rss_link"] != settings.rss_parser.link: bangumi_data = { - "rss_link": settings.rss_link, - "data_version": settings.data_version, + "rss_link": settings.rss_parser.link, + "data_version": settings.program.data_version, "bangumi_info": [] } logger.info("Rebuilding data information...") diff --git a/module/conf/__init__.py b/src/module/conf/__init__.py similarity index 100% rename from module/conf/__init__.py rename to src/module/conf/__init__.py index c67557ea..a3b86de5 100644 --- a/module/conf/__init__.py +++ b/src/module/conf/__init__.py @@ -1,5 +1,5 @@ -from .config import settings, VERSION from .log import setup_logger, LOG_PATH +from .config import settings, VERSION TMDB_API = "32b19d6a05b512190a056fa4e747cbbc" diff --git a/module/conf/config.py b/src/module/conf/config.py similarity index 86% rename from module/conf/config.py rename to src/module/conf/config.py index 56a88c43..9090f1c4 100644 --- a/module/conf/config.py +++ b/src/module/conf/config.py @@ -5,6 +5,10 @@ from dataclasses import dataclass from .const import DEFAULT_SETTINGS, ENV_TO_ATTR +try: + from ..__version__ import VERSION +except ImportError: + VERSION = "DEV_VERSION" class ConfLoad(dict): @@ -29,7 +33,7 @@ class Settings: self.load(path) def load(self, path: str | None): - if isinstance(path, dict): + if path is None: conf = DEFAULT_SETTINGS elif os.path.isfile(path): with open(path, "r") as f: @@ -58,15 +62,13 @@ class Settings: json.dump(settings, f, indent=4) return settings -try: - from .version import VERSION - if os.path.isdir("config"): - CONFIG_PATH = "config/config.json" - else: - CONFIG_PATH = None -except ImportError: - VERSION = "DEV_VERSION" + +if os.path.isdir("config") and VERSION == "DEV_VERSION": CONFIG_PATH = "config/config_dev.json" +elif os.path.isdir("config") and VERSION != "DEV_VERSION": + CONFIG_PATH = "config/config.json" +else: + CONFIG_PATH = None settings = Settings(CONFIG_PATH) diff --git a/module/conf/const.py b/src/module/conf/const.py similarity index 100% rename from module/conf/const.py rename to src/module/conf/const.py diff --git a/module/conf/log.py b/src/module/conf/log.py similarity index 94% rename from module/conf/log.py rename to src/module/conf/log.py index c110a67d..b8516603 100644 --- a/module/conf/log.py +++ b/src/module/conf/log.py @@ -1,5 +1,6 @@ import logging -from module.conf import settings + +from .config import settings LOG_PATH = "data/log.txt" diff --git a/module/conf/logging.conf b/src/module/conf/logging.conf similarity index 100% rename from module/conf/logging.conf rename to src/module/conf/logging.conf diff --git a/module/conf/parse.py b/src/module/conf/parse.py similarity index 100% rename from module/conf/parse.py rename to src/module/conf/parse.py diff --git a/src/module/core/__init__.py b/src/module/core/__init__.py new file mode 100644 index 00000000..596ca235 --- /dev/null +++ b/src/module/core/__init__.py @@ -0,0 +1,2 @@ +from .download_client import DownloadClient +from .api_func import APIProcess diff --git a/module/core/api_func.py b/src/module/core/api_func.py similarity index 94% rename from module/core/api_func.py rename to src/module/core/api_func.py index 2c137014..9c48d242 100644 --- a/module/core/api_func.py +++ b/src/module/core/api_func.py @@ -1,6 +1,8 @@ import re -from module.core import FullSeasonGet, DownloadClient, RSSAnalyser +from module.core import DownloadClient +from module.manager import FullSeasonGet +from module.rss import RSSAnalyser from module.utils import json_config from module.conf import DATA_PATH diff --git a/module/core/download_client.py b/src/module/core/download_client.py similarity index 96% rename from module/core/download_client.py rename to src/module/core/download_client.py index 9fa21879..6d92b47d 100644 --- a/module/core/download_client.py +++ b/src/module/core/download_client.py @@ -3,7 +3,6 @@ import logging import os from module.downloader import getClient -from module.downloader.exceptions import ConflictError from module.conf import settings @@ -115,8 +114,3 @@ class DownloadClient: def get_torrent_path(self, hashes): return self.client.get_torrent_path(hashes) - -if __name__ == "__main__": - put = DownloadClient() - put.rss_feed() - diff --git a/module/core/download_fliter.py b/src/module/core/download_fliter.py similarity index 100% rename from module/core/download_fliter.py rename to src/module/core/download_fliter.py diff --git a/module/downloader/__init__.py b/src/module/downloader/__init__.py similarity index 71% rename from module/downloader/__init__.py rename to src/module/downloader/__init__.py index 08bbffbc..2dd7a157 100644 --- a/module/downloader/__init__.py +++ b/src/module/downloader/__init__.py @@ -7,5 +7,5 @@ def getClient(): password = settings.downloader.password # TODO 多下载器支持 # 从 settings 里读取下载器名称,然后返回对应 Client - from module.downloader.qb_downloader import QbDownloader - return QbDownloader(host, username, password) \ No newline at end of file + from .qb_downloader import QbDownloader + return QbDownloader(host, username, password) diff --git a/module/downloader/aria2_downloader.py b/src/module/downloader/aria2_downloader.py similarity index 100% rename from module/downloader/aria2_downloader.py rename to src/module/downloader/aria2_downloader.py diff --git a/module/downloader/exceptions.py b/src/module/downloader/exceptions.py similarity index 100% rename from module/downloader/exceptions.py rename to src/module/downloader/exceptions.py diff --git a/module/downloader/qb_downloader.py b/src/module/downloader/qb_downloader.py similarity index 100% rename from module/downloader/qb_downloader.py rename to src/module/downloader/qb_downloader.py diff --git a/module/downloader/tr_downloader.py b/src/module/downloader/tr_downloader.py similarity index 100% rename from module/downloader/tr_downloader.py rename to src/module/downloader/tr_downloader.py diff --git a/src/module/manager/__init__.py b/src/module/manager/__init__.py new file mode 100644 index 00000000..410f242f --- /dev/null +++ b/src/module/manager/__init__.py @@ -0,0 +1,2 @@ +from .eps_complete import FullSeasonGet +from .renamer import Renamer \ No newline at end of file diff --git a/module/core/eps_complete.py b/src/module/manager/eps_complete.py similarity index 98% rename from module/core/eps_complete.py rename to src/module/manager/eps_complete.py index 87c2a3c9..b6ce13cf 100644 --- a/module/core/eps_complete.py +++ b/src/module/manager/eps_complete.py @@ -5,7 +5,7 @@ import logging from module.conf import settings from module.network import RequestContent -from .download_client import DownloadClient +from module.core.download_client import DownloadClient logger = logging.getLogger(__name__) SEARCH_KEY = ["group", "title_raw", "season_raw", "subtitle", "source", "dpi"] diff --git a/module/core/renamer.py b/src/module/manager/renamer.py similarity index 90% rename from module/core/renamer.py rename to src/module/manager/renamer.py index 7cd681f2..8a5d44cf 100644 --- a/module/core/renamer.py +++ b/src/module/manager/renamer.py @@ -1,14 +1,13 @@ import logging import os.path import re -import os.path from pathlib import PurePath, PureWindowsPath -from .download_client import DownloadClient +from module.core.download_client import DownloadClient from module.conf import settings from module.parser import TitleParser -from ..network import PostNotification, ServerChanNotification +from module.network import PostNotification, ServerChanNotification logger = logging.getLogger(__name__) @@ -54,7 +53,6 @@ class Renamer: return path_name, season, folder_name, suffix, download_path def run(self): - notification = ServerChanNotification() recent_info, torrent_count = self.get_torrent_info() rename_count = 0 for info in recent_info: @@ -67,10 +65,9 @@ class Renamer: try: new_name = self._renamer.download_parser(name, folder_name, season, suffix, settings.bangumi_manage.rename_method) if path_name != new_name: - old_name = info.content_path.replace(info.save_path, "") + old_name = os.path.basename(info.content_path) self.client.rename_torrent_file(torrent_hash, new_name, old_name, new_name) rename_count += 1 - notification.send_msg(f"《{name[:10]}》缓存成功", f"[Auto Bangumi]《{name}》缓存成功") else: continue except Exception as e: diff --git a/module/core/repath.py b/src/module/manager/repath.py similarity index 100% rename from module/core/repath.py rename to src/module/manager/repath.py diff --git a/module/models/__init__.py b/src/module/models/__init__.py similarity index 100% rename from module/models/__init__.py rename to src/module/models/__init__.py diff --git a/module/models/api.py b/src/module/models/api.py similarity index 100% rename from module/models/api.py rename to src/module/models/api.py diff --git a/module/models/bangumi.py b/src/module/models/bangumi.py similarity index 100% rename from module/models/bangumi.py rename to src/module/models/bangumi.py diff --git a/module/network/__init__.py b/src/module/network/__init__.py similarity index 100% rename from module/network/__init__.py rename to src/module/network/__init__.py diff --git a/module/network/notification.py b/src/module/network/notification.py similarity index 76% rename from module/network/notification.py rename to src/module/network/notification.py index 834f9a68..50860b90 100644 --- a/module/network/notification.py +++ b/src/module/network/notification.py @@ -19,6 +19,20 @@ class PostNotification: return response.status_code == 200 +class TelegramNotification: + def __init__(self): + self.token = settings.notification_token + self.notification_url = f"https://api.telegram.org/bot{self.token}/sendMessage" + + def send_msg(self, title: str, desp: str) -> bool: + if not settings.notification_enable: + return False + data = { + "chat_id": settings.notification_chat_id, + "text": f"{title}\n{desp}", + } + + class ServerChanNotification: """Server酱推送""" diff --git a/module/network/request_contents.py b/src/module/network/request_contents.py similarity index 99% rename from module/network/request_contents.py rename to src/module/network/request_contents.py index 6a0bfbf6..497c89c1 100644 --- a/module/network/request_contents.py +++ b/src/module/network/request_contents.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from bs4 import BeautifulSoup from .request_url import RequestURL + from module.conf import settings import re diff --git a/module/network/request_url.py b/src/module/network/request_url.py similarity index 100% rename from module/network/request_url.py rename to src/module/network/request_url.py diff --git a/module/parser/__init__.py b/src/module/parser/__init__.py similarity index 100% rename from module/parser/__init__.py rename to src/module/parser/__init__.py diff --git a/module/parser/analyser/__init__.py b/src/module/parser/analyser/__init__.py similarity index 100% rename from module/parser/analyser/__init__.py rename to src/module/parser/analyser/__init__.py diff --git a/module/parser/analyser/bgm_parser.py b/src/module/parser/analyser/bgm_parser.py similarity index 100% rename from module/parser/analyser/bgm_parser.py rename to src/module/parser/analyser/bgm_parser.py diff --git a/module/parser/analyser/raw_parser.py b/src/module/parser/analyser/raw_parser.py similarity index 100% rename from module/parser/analyser/raw_parser.py rename to src/module/parser/analyser/raw_parser.py diff --git a/module/parser/analyser/rename_parser.py b/src/module/parser/analyser/rename_parser.py similarity index 100% rename from module/parser/analyser/rename_parser.py rename to src/module/parser/analyser/rename_parser.py diff --git a/module/parser/analyser/tmdb_parser.py b/src/module/parser/analyser/tmdb_parser.py similarity index 100% rename from module/parser/analyser/tmdb_parser.py rename to src/module/parser/analyser/tmdb_parser.py diff --git a/module/parser/fuzz_match.py b/src/module/parser/fuzz_match.py similarity index 100% rename from module/parser/fuzz_match.py rename to src/module/parser/fuzz_match.py diff --git a/module/parser/title_parser.py b/src/module/parser/title_parser.py similarity index 100% rename from module/parser/title_parser.py rename to src/module/parser/title_parser.py diff --git a/src/module/rss/__init__.py b/src/module/rss/__init__.py new file mode 100644 index 00000000..9650cb6c --- /dev/null +++ b/src/module/rss/__init__.py @@ -0,0 +1 @@ +from .rss_analyser import RSSAnalyser \ No newline at end of file diff --git a/module/core/rss_analyser.py b/src/module/rss/rss_analyser.py similarity index 99% rename from module/core/rss_analyser.py rename to src/module/rss/rss_analyser.py index aa611e30..9060e27b 100644 --- a/module/core/rss_analyser.py +++ b/src/module/rss/rss_analyser.py @@ -1,6 +1,5 @@ import re import logging - from module.network import RequestContent from module.parser import TitleParser diff --git a/module/setID.sh b/src/module/setID.sh similarity index 100% rename from module/setID.sh rename to src/module/setID.sh diff --git a/module/utils/__init__.py b/src/module/utils/__init__.py similarity index 100% rename from module/utils/__init__.py rename to src/module/utils/__init__.py diff --git a/module/utils/json_config.py b/src/module/utils/json_config.py similarity index 100% rename from module/utils/json_config.py rename to src/module/utils/json_config.py diff --git a/run.sh b/src/run.sh similarity index 100% rename from run.sh rename to src/run.sh diff --git a/test/__init__.py b/src/test/__init__.py similarity index 100% rename from test/__init__.py rename to src/test/__init__.py diff --git a/test/test_raw_parser.py b/src/test/test_raw_parser.py similarity index 100% rename from test/test_raw_parser.py rename to src/test/test_raw_parser.py