- fix rename bug
- temp save
This commit is contained in:
EstrellaXD
2023-03-14 21:22:55 +08:00
parent 2745047924
commit 34216245f7
56 changed files with 86 additions and 101 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
run: |
cd src
pytest test/test_raw_parser.py

22
.gitignore vendored
View File

@@ -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/

View File

@@ -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 \

16
main.py
View File

@@ -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()

View File

@@ -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

View File

@@ -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",
]
)

18
src/main.py Normal file
View File

@@ -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()

View File

@@ -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...")

View File

@@ -1,5 +1,5 @@
from .config import settings, VERSION
from .log import setup_logger, LOG_PATH
from .config import settings, VERSION
TMDB_API = "32b19d6a05b512190a056fa4e747cbbc"

View File

@@ -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)

View File

@@ -1,5 +1,6 @@
import logging
from module.conf import settings
from .config import settings
LOG_PATH = "data/log.txt"

View File

@@ -0,0 +1,2 @@
from .download_client import DownloadClient
from .api_func import APIProcess

View File

@@ -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

View File

@@ -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()

View File

@@ -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)
from .qb_downloader import QbDownloader
return QbDownloader(host, username, password)

View File

@@ -0,0 +1,2 @@
from .eps_complete import FullSeasonGet
from .renamer import Renamer

View File

@@ -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"]

View File

@@ -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:

View File

@@ -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酱推送"""

View File

@@ -3,6 +3,7 @@ from dataclasses import dataclass
from bs4 import BeautifulSoup
from .request_url import RequestURL
from module.conf import settings
import re

View File

@@ -0,0 +1 @@
from .rss_analyser import RSSAnalyser

View File

@@ -1,6 +1,5 @@
import re
import logging
from module.network import RequestContent
from module.parser import TitleParser

View File