mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-07-16 19:50:48 +08:00
2.6.0
- refactor - add config.ini for later update
This commit is contained in:
@@ -19,8 +19,8 @@ coverage.xml
|
||||
.pytest_cache
|
||||
.hypothesis
|
||||
|
||||
src/tests
|
||||
src/conf/const_dev.py
|
||||
autobangumi/tests
|
||||
autobangumi/conf/const_dev.py
|
||||
config/bangumi.json/config/bangumi.json
|
||||
/docs
|
||||
/.github
|
||||
|
||||
19
.gitignore
vendored
19
.gitignore
vendored
@@ -162,14 +162,19 @@ cython_debug/
|
||||
#.idea/
|
||||
|
||||
# Custom
|
||||
/src/conf/const_dev.py
|
||||
/autobangumi/conf/const_dev.py
|
||||
/config
|
||||
/src/tester.py
|
||||
/src/config
|
||||
/autobangumi/tester.py
|
||||
/autobangumi/config
|
||||
|
||||
/src/parser/analyser/tmdb_parser.py
|
||||
/autobangumi/parser/analyser/tmdb_parser.py
|
||||
|
||||
/src/run_debug.sh
|
||||
/src/debug_run.sh
|
||||
/src/__version__.py
|
||||
/autobangumi/run_debug.sh
|
||||
/autobangumi/debug_run.sh
|
||||
/autobangumi/__version__.py
|
||||
/data/
|
||||
|
||||
/autobangumi/conf/config_dev.ini
|
||||
|
||||
test.*
|
||||
.run
|
||||
@@ -17,7 +17,7 @@ ENV TZ=Asia/Shanghai \
|
||||
WORKDIR /src
|
||||
|
||||
COPY --from=build --chmod=777 /install /usr/local
|
||||
COPY --chmod=755 ./src /src
|
||||
COPY --chmod=755 autobangumi /src
|
||||
|
||||
RUN apk add --no-cache \
|
||||
curl \
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import logging
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
from conf import settings
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
11
autobangumi/conf/__init__.py
Normal file
11
autobangumi/conf/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from .setting import settings
|
||||
from .parse import parse
|
||||
from .log import setup_logger
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
from conf import const
|
||||
from autobangumi.conf import const
|
||||
|
||||
|
||||
class Settings(dict):
|
||||
@@ -58,6 +58,100 @@ ENV_TO_ATTR = {
|
||||
"AB_REFRESH_RSS": ("refresh_rss", lambda e: e.lower() in ("true", "1", "t")),
|
||||
}
|
||||
|
||||
DOWNLOADER_DEFAULT = {
|
||||
"Host": "localhost:8080",
|
||||
"Username": "admin",
|
||||
"Password": "adminadmin",
|
||||
"DownloadPath": "/downloads/Bangumi/",
|
||||
"Filter": r"720|\d+-\d+/",
|
||||
}
|
||||
|
||||
DOWNLOADER_ENV ={
|
||||
"AB_DOWNLOADER_HOST": "Host",
|
||||
"AB_DOWNLOADER_USERNAME": "Username",
|
||||
"AB_DOWNLOADER_PASSWORD": "Password",
|
||||
"AB_DOWNLOAD_PATH": "DownloadPath",
|
||||
"AB_NOT_CONTAIN": "Filter"
|
||||
}
|
||||
|
||||
DEFAULT_ENV = {
|
||||
"AB_INTERVAL_TIME": "SleepTime",
|
||||
"AB_RENAME_FREQ": "RenameFreq",
|
||||
"AB_RSS_COLLECTOR": "EnableParser",
|
||||
"AB_RENAME": "EnableRenamer",
|
||||
"AB_EP_COMPLETE": "SeasonCollect",
|
||||
}
|
||||
|
||||
DEFAULT_DEFAULT = {
|
||||
"SleepTime": 7200,
|
||||
"RenameFreq": 20,
|
||||
"EnableParser": True,
|
||||
"EnableRenamer": True,
|
||||
"SeasonCollect": False,
|
||||
}
|
||||
|
||||
|
||||
PARSER_ENV = {
|
||||
"AB_RSS": "URL",
|
||||
"AB_NOT_CONTAIN": "Filter",
|
||||
"AB_LANGUAGE": "Language",
|
||||
}
|
||||
|
||||
PARSER_DEFAULT = {
|
||||
"URL": "",
|
||||
"Filter": r"720|\d+-\d+/",
|
||||
"Language": "zh",
|
||||
}
|
||||
|
||||
TMDB_ENV = {
|
||||
"AB_ENABLE_TMDB": "EnableTMDB",
|
||||
"AB_LANGUAGE": "Language",
|
||||
}
|
||||
|
||||
TMDB_DEFAULT = {
|
||||
"EnableTMDB": False,
|
||||
"Language": "zh",
|
||||
}
|
||||
|
||||
|
||||
RENAME_ENV = {
|
||||
"AB_METHOD": "RenameMethod",
|
||||
}
|
||||
|
||||
RENAME_DEFAULT = {
|
||||
"RenameMethod": "pn",
|
||||
}
|
||||
|
||||
NETWORK_ENV = {
|
||||
"AB_WEBUI_PORT": "WebUIPort",
|
||||
"AB_HTTP_PROXY": "HTTPProxy",
|
||||
"AB_SOCKS": "Socks",
|
||||
}
|
||||
|
||||
NETWORK_DEFAULT = {
|
||||
"WebUIPort": 7892,
|
||||
"HTTPProxy": "",
|
||||
"Socks": "",
|
||||
}
|
||||
|
||||
ENV_DICT = {
|
||||
"DEFAULT": DEFAULT_ENV,
|
||||
"DOWNLOADER": DOWNLOADER_ENV,
|
||||
"PARSER": PARSER_ENV,
|
||||
"TMDB": TMDB_ENV,
|
||||
"RENAME": RENAME_ENV,
|
||||
"NETWORK": NETWORK_ENV,
|
||||
}
|
||||
|
||||
DEFAULT_DICT = {
|
||||
"DEFAULT": DEFAULT_DEFAULT,
|
||||
"DOWNLOADER": DOWNLOADER_DEFAULT,
|
||||
"PARSER": PARSER_DEFAULT,
|
||||
"TMDB": TMDB_DEFAULT,
|
||||
"RENAME": RENAME_DEFAULT,
|
||||
"NETWORK": NETWORK_DEFAULT,
|
||||
}
|
||||
|
||||
|
||||
class BCOLORS:
|
||||
@staticmethod
|
||||
@@ -1,5 +1,5 @@
|
||||
import logging
|
||||
from conf import settings
|
||||
from autobangumi.conf import settings
|
||||
|
||||
|
||||
def setup_logger():
|
||||
46
autobangumi/conf/setting.py
Normal file
46
autobangumi/conf/setting.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from pydantic import BaseSettings
|
||||
from configparser import ConfigParser
|
||||
import os
|
||||
|
||||
from .const import ENV_DICT, DEFAULT_DICT
|
||||
|
||||
config = ConfigParser()
|
||||
|
||||
|
||||
def get_attr_from_env(env_dict: dict, default_dict: dict):
|
||||
"""Transforms env-strings to python."""
|
||||
conf = {
|
||||
attr if isinstance(attr, str) else attr[0]: os.environ[env]
|
||||
for env, attr in env_dict.items()
|
||||
if env in os.environ
|
||||
}
|
||||
for key, value in default_dict.items():
|
||||
if key not in conf:
|
||||
conf[key] = value
|
||||
return conf
|
||||
|
||||
|
||||
def init_config():
|
||||
for section, env_dict in ENV_DICT.items():
|
||||
config[section] = get_attr_from_env(env_dict, DEFAULT_DICT[section])
|
||||
with open("config/config.ini", "w") as f:
|
||||
config.write(f)
|
||||
|
||||
|
||||
if os.path.isfile("config/config_dev.ini"):
|
||||
config.read("config/config_dev.ini")
|
||||
elif os.path.isfile("config/config.ini"):
|
||||
config.read("config/config.ini")
|
||||
else:
|
||||
init_config()
|
||||
|
||||
|
||||
class Setting(BaseSettings):
|
||||
DEFAULT = config["DEFAULT"]
|
||||
DOWNLOADER = config["DOWNLOADER"]
|
||||
PARSER = config["PARSER"]
|
||||
RENAME = config["RENAME"]
|
||||
NETWORK = config["NETWORK"]
|
||||
|
||||
|
||||
settings = Setting()
|
||||
@@ -2,14 +2,18 @@ import re
|
||||
import logging
|
||||
import os
|
||||
|
||||
from downloader import getClient
|
||||
from downloader.exceptions import ConflictError
|
||||
from autobangumi.downloader import getClient
|
||||
from autobangumi.downloader.exceptions import ConflictError
|
||||
|
||||
from conf import settings
|
||||
from autobangumi.conf import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
DOWNLOADER = settings.DOWNLOADER
|
||||
DEBUG = settings.DEBUG
|
||||
|
||||
|
||||
class DownloadClient:
|
||||
def __init__(self):
|
||||
self.client = getClient()
|
||||
@@ -22,16 +26,16 @@ class DownloadClient:
|
||||
"rss_refresh_interval": 30,
|
||||
}
|
||||
self.client.prefs_init(prefs=prefs)
|
||||
if settings.download_path == "":
|
||||
if DOWNLOADER["DownloadPath"] == "":
|
||||
prefs = self.client.get_app_prefs()
|
||||
settings.download_path = os.path.join(prefs["save_path"], "Bangumi")
|
||||
DOWNLOADER["DownloadPath"] = os.path.join(prefs["save_path"], "Bangumi")
|
||||
|
||||
def set_rule(self, info: dict, rss_link):
|
||||
official_name, raw_name, season, group = info["official_title"], info["title_raw"], info["season"], info["group"]
|
||||
rule = {
|
||||
"enable": True,
|
||||
"mustContain": raw_name,
|
||||
"mustNotContain": settings.not_contain,
|
||||
"mustNotContain": DOWNLOADER["Filter"],
|
||||
"useRegex": True,
|
||||
"episodeFilter": "",
|
||||
"smartFilter": False,
|
||||
@@ -39,11 +43,11 @@ class DownloadClient:
|
||||
"affectedFeeds": [rss_link],
|
||||
"ignoreDays": 0,
|
||||
"lastMatch": "",
|
||||
"addPaused": settings.dev_debug,
|
||||
"addPaused": DEBUG["Enable"],
|
||||
"assignedCategory": "Bangumi",
|
||||
"savePath": str(
|
||||
os.path.join(
|
||||
settings.download_path,
|
||||
DOWNLOADER["Path"],
|
||||
re.sub(settings.rule_name_re, " ", official_name).strip(),
|
||||
f"Season {season}",
|
||||
)
|
||||
@@ -130,8 +134,6 @@ class DownloadClient:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from conf.const_dev import DEV_SETTINGS
|
||||
settings.init(DEV_SETTINGS)
|
||||
put = DownloadClient()
|
||||
put.rss_feed()
|
||||
|
||||
@@ -2,9 +2,9 @@ import os.path
|
||||
import re
|
||||
import logging
|
||||
|
||||
from conf import settings
|
||||
from network import RequestContent
|
||||
from core import DownloadClient
|
||||
from autobangumi.conf import settings
|
||||
from autobangumi.network import RequestContent
|
||||
from .download_client import DownloadClient
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
SEARCH_KEY = ["group", "title_raw", "season_raw", "subtitle", "source", "dpi"]
|
||||
@@ -4,10 +4,10 @@ import re
|
||||
import os.path
|
||||
from pathlib import PurePath, PureWindowsPath
|
||||
|
||||
from .download_client import DownloadClient
|
||||
|
||||
from conf import settings
|
||||
from core import DownloadClient
|
||||
from parser import TitleParser
|
||||
from autobangumi.conf import settings
|
||||
from autobangumi.parser import TitleParser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -4,10 +4,10 @@ import time
|
||||
from qbittorrentapi import Client, LoginFailed
|
||||
from qbittorrentapi.exceptions import Conflict409Error
|
||||
|
||||
from conf import settings
|
||||
from ab_decorator import qb_connect_failed_wait
|
||||
from autobangumi.conf import settings
|
||||
from autobangumi.ab_decorator import qb_connect_failed_wait
|
||||
|
||||
from downloader.exceptions import ConflictError
|
||||
from .exceptions import ConflictError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -26,9 +26,9 @@ class QbDownloader:
|
||||
break
|
||||
except LoginFailed:
|
||||
logger.debug(
|
||||
f"Can't login qBittorrent Server {host} by {username}, retry in {settings.connect_retry_interval}"
|
||||
f"Can't login qBittorrent Server {host} by {username}, retry in {5} seconds."
|
||||
)
|
||||
time.sleep(settings.connect_retry_interval)
|
||||
time.sleep(5)
|
||||
|
||||
@qb_connect_failed_wait
|
||||
def prefs_init(self, prefs):
|
||||
@@ -44,7 +44,7 @@ class QbDownloader:
|
||||
|
||||
def torrents_add(self, urls, save_path, category):
|
||||
return self._client.torrents_add(
|
||||
is_paused=settings.dev_debug,
|
||||
is_paused=settings.DEBUG["enable"],
|
||||
urls=urls,
|
||||
save_path=save_path,
|
||||
category=category,
|
||||
@@ -92,14 +92,3 @@ class QbDownloader:
|
||||
|
||||
def get_torrent_path(self, hash):
|
||||
return self._client.torrents_info(hashes=hash)[0].save_path
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
from conf.const_dev import DEV_SETTINGS
|
||||
except ModuleNotFoundError:
|
||||
logger.debug("Please copy `const_dev.py` to `const_dev.py` to use custom settings")
|
||||
settings.init(DEV_SETTINGS)
|
||||
client = QbDownloader(settings.host_ip, settings.user_name, settings.password)
|
||||
path = client.get_torrent_path("39adad0d0c82ebb3971810a7592e03138b7345d2")
|
||||
print(path)
|
||||
6
autobangumi/network/__init__.py
Normal file
6
autobangumi/network/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from .request_contents import RequestContent
|
||||
from .notification import PostNotification
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import requests
|
||||
|
||||
from conf import settings
|
||||
from autobangumi.conf import settings
|
||||
|
||||
|
||||
class PostNotification:
|
||||
@@ -7,7 +7,7 @@ import logging
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from conf import settings
|
||||
from autobangumi.conf import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -15,13 +15,13 @@ logger = logging.getLogger(__name__)
|
||||
class RequestURL:
|
||||
def __init__(self):
|
||||
self.session = requests.session()
|
||||
if settings.http_proxy is not None:
|
||||
if settings.NETWORK["HTTP"] is not None:
|
||||
self.session.proxies = {
|
||||
"https": settings.http_proxy,
|
||||
"http": settings.http_proxy,
|
||||
"https": settings.NETWORK["HTTP"],
|
||||
"http": settings.NETWORK["HTTP"],
|
||||
}
|
||||
elif settings.socks is not None:
|
||||
socks_info = settings.socks.split(",")
|
||||
elif settings.NETWORK["Socks"] is not None:
|
||||
socks_info = settings.NETWORK["Socks"].split(",")
|
||||
socks.set_default_proxy(socks.SOCKS5, addr=socks_info[0], port=int(socks_info[1]), rdns=True,
|
||||
username=socks_info[2], password=socks_info[3])
|
||||
socket.socket = socks.socksocket
|
||||
@@ -40,7 +40,7 @@ class RequestURL:
|
||||
logger.debug(f"URL: {url}")
|
||||
logger.debug(e)
|
||||
logger.warning("ERROR with Connection.Please check DNS/Connection settings")
|
||||
time.sleep(settings.connect_retry_interval)
|
||||
time.sleep(5)
|
||||
times += 1
|
||||
|
||||
def get_content(self, url, content="xml"):
|
||||
@@ -53,11 +53,3 @@ class RequestURL:
|
||||
self.session.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
a = RequestURL()
|
||||
socks.set_default_proxy(socks.SOCKS5, "192.168.30.2", 19990, True, username="abc", password="abc")
|
||||
socket.socket = socks.socksocket
|
||||
b = a.get_url('https://www.themoviedb.org').text
|
||||
print(b)
|
||||
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import re
|
||||
import time
|
||||
|
||||
from network import RequestContent
|
||||
from conf import settings
|
||||
from autobangumi.network import RequestContent
|
||||
|
||||
|
||||
class BgmAPI:
|
||||
@@ -18,9 +14,4 @@ class BgmAPI:
|
||||
contents = self._request.get_json(url)["list"]
|
||||
if contents.__len__() == 0:
|
||||
return None
|
||||
return contents[0]["name"], contents[0]["name_cn"]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
BGM = BgmAPI()
|
||||
print(BGM.search("辉夜大小姐"))
|
||||
return contents[0]["name"], contents[0]["name_cn"]
|
||||
9
mian.py
Normal file
9
mian.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from autobangumi.conf.setting import setting
|
||||
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(setting.DOWNLOADER["HOST"])
|
||||
@@ -1,14 +1,14 @@
|
||||
anyio
|
||||
beautifulsoup4
|
||||
lxml
|
||||
certifi==2022.6.15
|
||||
certifi
|
||||
charset-normalizer
|
||||
click==8.1.3
|
||||
click
|
||||
fastapi
|
||||
h11==0.13.0
|
||||
idna==3.3
|
||||
h11
|
||||
idna
|
||||
pydantic==1.9.1
|
||||
PySocks==1.7.1
|
||||
PySocks
|
||||
qbittorrent-api
|
||||
requests
|
||||
six==1.16.0
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import app
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
@@ -1,13 +0,0 @@
|
||||
from .conf import settings, Settings
|
||||
from .const import BCOLORS
|
||||
# from .const_dev import DEV_SETTINGS
|
||||
from .parse import parse
|
||||
from .log import setup_logger
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
|
||||
from network.request import RequestURL
|
||||
from network.notification import PostNotification
|
||||
from conf import settings
|
||||
|
||||
|
||||
@dataclass
|
||||
class TorrentInfo:
|
||||
name: str
|
||||
torrent_link: str
|
||||
|
||||
|
||||
class RequestContent:
|
||||
def __init__(self):
|
||||
self._req = RequestURL()
|
||||
|
||||
# Mikanani RSS
|
||||
def get_torrents(self, _url: str) -> [TorrentInfo]:
|
||||
soup = self._req.get_content(_url)
|
||||
torrent_titles = [item.title.string for item in soup.find_all("item")]
|
||||
torrent_urls = [item.get("url") for item in soup.find_all("enclosure")]
|
||||
torrents = []
|
||||
for _title, torrent_url in zip(torrent_titles, torrent_urls):
|
||||
if re.search(settings.not_contain, _title) is None:
|
||||
torrents.append(TorrentInfo(_title, torrent_url))
|
||||
return torrents
|
||||
|
||||
def get_torrent(self, _url) -> TorrentInfo:
|
||||
soup = self._req.get_content(_url)
|
||||
item = soup.find("item")
|
||||
enclosure = item.find("enclosure")
|
||||
return TorrentInfo(item.title.string, enclosure["url"])
|
||||
|
||||
# API JSON
|
||||
def get_json(self, _url) -> dict:
|
||||
return self._req.get_content(_url, content="json")
|
||||
|
||||
def close_session(self):
|
||||
self._req.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
r = RequestContent()
|
||||
rss_url = "https://mikanani.me/RSS/Bangumi?bangumiId=2739&subgroupid=203"
|
||||
titles = r.get_torrents(rss_url)
|
||||
print(settings.not_contain)
|
||||
for title in titles:
|
||||
print(title.name, title.torrent_link)
|
||||
Reference in New Issue
Block a user