diff --git a/AutoBangumi2.0/Dockerfile b/AutoBangumi2.0/Dockerfile index eed0d858..56a81695 100644 --- a/AutoBangumi2.0/Dockerfile +++ b/AutoBangumi2.0/Dockerfile @@ -5,6 +5,9 @@ COPY requirements.txt . RUN pip install -r requirements.txt +ENV TZ=Asia/Shanghai +ENV TIME=1800 + COPY ./app /app CMD [ "python3", "/app/docker_main.py"] \ No newline at end of file diff --git a/AutoBangumi2.0/app/collect_bangumi_info.py b/AutoBangumi2.0/app/collect_bangumi_info.py index 5f27941a..2d66e01e 100644 --- a/AutoBangumi2.0/app/collect_bangumi_info.py +++ b/AutoBangumi2.0/app/collect_bangumi_info.py @@ -1,5 +1,4 @@ # -*- coding: UTF-8 -*- -import os import sys import time diff --git a/AutoBangumi2.0/app/docker_main.py b/AutoBangumi2.0/app/docker_main.py index f1f4b0c5..224977e7 100644 --- a/AutoBangumi2.0/app/docker_main.py +++ b/AutoBangumi2.0/app/docker_main.py @@ -4,21 +4,39 @@ from collect_bangumi_info import CollectRSS from auto_set_rule import SetRule from rename_qb import QbittorrentRename import json -import qbittorrentapi + +config_path = "/config/config.json" +info_path = "/config/bangumi.json" sleep_time = os.environ["TIME"] + +def create_config(): + if not os.path.exists(config_path): + config = { + "host_ip": "192.168.31.10:8181", + "user_name": "admin", + "password": "adminadmin", + "method": "pn", + "rss_link": "https://mikanani.me/RSS/MyBangumi?token=qTxKo48gH1SrFNy8X%2fCfQUoeElNsgKNWFNzNieKwBH8%3d", + "download_path": "/downloads/Bangumi" + } + with open(config_path,"w") as c: + json.dump(config, c, indent=4, separators=(',', ': '), ensure_ascii=False) + if not os.path.exists(info_path): + bangumi_info = [{"title":"simple","season":""}] + with open(info_path) as i: + json.dump(bangumi_info, i, indent=4, separators=(',', ': '), ensure_ascii=False) + print(f"[{time.strftime('%X')}] 请填入配置参数") + quit() + + if __name__ == "__main__": - """qb = qbittorrentapi.Client(username='admin', password='adminadmin', host='192.168.31.10', port=8181) - try: - qb.auth_log_in() - except qbittorrentapi.LoginFailed as e: - print(e) - qb.rss_add_feed(url="")""" + create_config() + with open(config_path) as f: + config = json.load(f) while True: - with open("/config/config.json") as f: - config = json.load(f) - with open("/config/bangumi.json") as f: + with open(info_path) as f: info = json.load(f) CollectRSS(config, info).run() SetRule(config, info).run() diff --git a/AutoBangumi2.0/app/rename_qb.py b/AutoBangumi2.0/app/rename_qb.py index 41ab7439..ca5169ff 100644 --- a/AutoBangumi2.0/app/rename_qb.py +++ b/AutoBangumi2.0/app/rename_qb.py @@ -53,8 +53,8 @@ class QbittorrentRename: def rename(self): if self.path_name != self.new_name: - self.qbt_client.torrents_rename_file(torrent_hash=self.hash, old_path=self.name, new_path=self.new_name) - print(f'{self.name} >> {self.new_name}') + self.qbt_client.torrents_rename_file(torrent_hash=self.hash, old_path=self.path_name, new_path=self.new_name) + sys.stdout.write(f"[{time.strftime('%X')}] {self.path_name} >> {self.new_name}") self.count += 1 else: return @@ -63,6 +63,7 @@ class QbittorrentRename: self.name = None self.hash = None self.new_name = None + self.path_name = None def print_result(self): sys.stdout.write(f"[{time.strftime('%X')}] 已完成对{self.torrent_count}个文件的检查" + '\n') diff --git a/test/bangumi.json b/test/bangumi.json new file mode 100644 index 00000000..f6a2d0cb --- /dev/null +++ b/test/bangumi.json @@ -0,0 +1,6 @@ +[ + { + "title": "simple", + "season": "" + } +] \ No newline at end of file diff --git a/test/config.json b/test/config.json new file mode 100644 index 00000000..5bed0cb7 --- /dev/null +++ b/test/config.json @@ -0,0 +1,8 @@ +{ + "host_ip": "127.0.0.1:8080", + "user_name": "admin", + "password": "adminadmin", + "method": "pn", + "rss_link": "https://mikanani.me/RSS/MyBangumi?token=qTxKo48gH1SrFNy8X%2fCfQUoeElNsgKNWFNzNieKwBH8%3d", + "download_path": "/downloads/Bangumi" +} \ No newline at end of file diff --git a/test/test.py b/test/test.py index 85f2681c..4803ef1d 100644 --- a/test/test.py +++ b/test/test.py @@ -1,30 +1,27 @@ -import re +import json +import os -import requests -from bs4 import BeautifulSoup +config_path = "config.json" +info_path = "bangumi.json" +def create_config(): + if not os.path.exists(config_path): + config = { + "host_ip": "127.0.0.1:8080", + "user_name": "admin", + "password": "adminadmin", + "method": "pn", + "rss_link": "https://mikanani.me/RSS/MyBangumi?token=qTxKo48gH1SrFNy8X%2fCfQUoeElNsgKNWFNzNieKwBH8%3d", + "download_path": "/downloads/Bangumi" + } + with open(config_path,"w") as c: + json.dump(config, c, indent=4, separators=(',', ': '), ensure_ascii=False) + if not os.path.exists(info_path): + bangumi_info = [{"title": "simple","season": ""}] + with open(info_path, "w") as i: + json.dump(bangumi_info, i, indent=4, separators=(',', ': '), ensure_ascii=False) + print("请填入配置参数") + quit() -episode_rules = [r'(.*)\[(\d{1,3}|\d{1,3}\.\d{1,2})(?:v\d{1,2})?(?:END)?\](.*)', - r'(.*)\[E(\d{1,3}|\d{1,3}\.\d{1,2})(?:v\d{1,2})?(?:END)?\](.*)', - r'(.*)\[第(\d*\.*\d*)话(?:END)?\](.*)', - r'(.*)\[第(\d*\.*\d*)話(?:END)?\](.*)', - r'(.*)第(\d*\.*\d*)话(?:END)?(.*)', - r'(.*)第(\d*\.*\d*)話(?:END)?(.*)', - r'(.*)- (\d{1,3}|\d{1,3}\.\d{1,2})(?:v\d{1,2})?(?:END)? (.*)'] - - -name = "[NC-Raws] 小书痴的下克上:为了成为图书管理员不择手段!第三季 / Honzuki no Gekokujou S3 - 32 (Baha 1920x1080 AVC AAC MP4)" -parrten = r'\[|\]|\u3010|\u3011|\★|\*|\(|\)|\(|\)' -for i in range(2): - n = re.split(parrten, name) - try: - name = re.sub(f'\[{n[1]}\]|【{n[1]}】|★{n[1]}★', '', name) - except: - name = name -for rule in episode_rules: - matchObj = re.match(rule, name, re.I) - if matchObj is not None: - new_name = re.sub(r'\[|\]', '', f'{matchObj.group(1)}') - new_name = re.split(r'/', new_name)[-1].strip() - print(new_name) +create_config() \ No newline at end of file