mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-08 05:00:34 +08:00
fix bugs
This commit is contained in:
2
.idea/Bangumi_Auto_Rename.iml
generated
2
.idea/Bangumi_Auto_Rename.iml
generated
@@ -2,7 +2,7 @@
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (2)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (2)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
@@ -1 +1,41 @@
|
||||
import qbittorrentapi
|
||||
import qbittorrentapi
|
||||
import json
|
||||
import os
|
||||
|
||||
with open("config.json") as f:
|
||||
info = json.load(f)
|
||||
|
||||
with open("bangumi.json") as f:
|
||||
bangumi_info = json.load(f)
|
||||
rss_link = info["rss_link"]
|
||||
host_ip = "192.168.31.10:8181"
|
||||
user_name = "admin"
|
||||
password = "adminadmin"
|
||||
|
||||
|
||||
def set_rule(bangumi_name, season):
|
||||
qb = qbittorrentapi.Client(host=host_ip, username=user_name, password=password)
|
||||
try:
|
||||
qb.auth_log_in()
|
||||
except qbittorrentapi.LoginFailed as e:
|
||||
print(e)
|
||||
rule = {
|
||||
'enable': False,
|
||||
'mustContain': bangumi_name,
|
||||
'mustNotContain': '720',
|
||||
'useRegx': True,
|
||||
'episodeFilter': '',
|
||||
'smartFilter': False,
|
||||
'previouslyMatchedEpisodes': [],
|
||||
'affectedFeeds': [rss_link],
|
||||
'ignoreDays': 0,
|
||||
'lastMatch': '',
|
||||
'addPaused': False,
|
||||
'assignedCategory': 'Bangumi',
|
||||
'savePath': os.path.join('/downloads', bangumi_name, season)
|
||||
}
|
||||
qb.rss_set_rule(rule_name=bangumi_name, rule_def=rule)
|
||||
|
||||
if __name__ == "__main__":
|
||||
for info in bangumi_info:
|
||||
set_rule(info["title"], info["season"])
|
||||
@@ -1,41 +1,58 @@
|
||||
[
|
||||
{
|
||||
"title": "Kawaii dake ja Nai Shikimori-san "
|
||||
"title": "simple",
|
||||
"season": ""
|
||||
},
|
||||
{
|
||||
"title": "Kakkou no Iinazuke "
|
||||
"title": "Kawaii dake ja Nai Shikimori-san",
|
||||
"season": ""
|
||||
},
|
||||
{
|
||||
"title": "SPYxFAMILY "
|
||||
"title": "Kakkou no Iinazuke",
|
||||
"season": ""
|
||||
},
|
||||
{
|
||||
"title": "Love Live!虹咲学园 学园偶像同好会 S02 "
|
||||
"title": "SPYxFAMILY",
|
||||
"season": ""
|
||||
},
|
||||
{
|
||||
"title": "CUE!"
|
||||
"title": "Love Live!虹咲学园 学园偶像同好会",
|
||||
"season": "S02"
|
||||
},
|
||||
{
|
||||
"title": "Kaguya-sama wa Kokurasetai S03 "
|
||||
"title": "CUE!",
|
||||
"season": ""
|
||||
},
|
||||
{
|
||||
"title": "Shokei Shoujo no Virgin Road "
|
||||
"title": "Kaguya-sama wa Kokurasetai",
|
||||
"season": "S03"
|
||||
},
|
||||
{
|
||||
"title": "Kakkou no Iikagen "
|
||||
"title": "Shokei Shoujo no Virgin Road",
|
||||
"season": ""
|
||||
},
|
||||
{
|
||||
"title": "Summer Time Rendering"
|
||||
"title": "Kakkou no Iikagen",
|
||||
"season": ""
|
||||
},
|
||||
{
|
||||
"title": "Paripi Koumei "
|
||||
"title": "Summer Time Rendering",
|
||||
"season": ""
|
||||
},
|
||||
{
|
||||
"title": "Tate no Yuusha no Nariagari S02 "
|
||||
"title": "Paripi Koumei",
|
||||
"season": ""
|
||||
},
|
||||
{
|
||||
"title": "Shijou Saikyou no Daimaou "
|
||||
"title": "Tate no Yuusha no Nariagari",
|
||||
"season": "S02"
|
||||
},
|
||||
{
|
||||
"title": "Yuusha, Yamemasu "
|
||||
"title": "Shijou Saikyou no Daimaou",
|
||||
"season": ""
|
||||
},
|
||||
{
|
||||
"title": "Yuusha, Yamemasu",
|
||||
"season": ""
|
||||
}
|
||||
]
|
||||
@@ -33,7 +33,7 @@ for a in item:
|
||||
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].lstrip()
|
||||
new_name = re.split(r'/', new_name)[-1].strip()
|
||||
if new_name not in bangumi_title:
|
||||
bangumi_title.append(new_name)
|
||||
|
||||
@@ -44,13 +44,20 @@ had_data = []
|
||||
for data in bangumi_info:
|
||||
had_data.append(data["title"])
|
||||
|
||||
season_rules = r'S\d'
|
||||
season_rules = r'(.*)(S.\d)'
|
||||
for title in bangumi_title:
|
||||
a = re.match(season_rules, title, re.I)
|
||||
if a is not None:
|
||||
title = a.group(1).strip()
|
||||
season = a.group(2).strip()
|
||||
else:
|
||||
season = ''
|
||||
if title not in had_data:
|
||||
bangumi_info.append({
|
||||
"title": title
|
||||
"title": title,
|
||||
"season": season
|
||||
})
|
||||
print(f"add {title}")
|
||||
print(f"add {title} {season}")
|
||||
|
||||
|
||||
with open("bangumi.json", 'w', encoding='utf8') as f:
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import re
|
||||
name = "Tate no Yuusha no Nariagari S02 "
|
||||
name = "Tate no Yuusha no Nariagari S02"
|
||||
|
||||
season_rules = r'S(\d{0,3}|\d{1,3}\.\d{1,2})'
|
||||
a = re.match(season_rules, name)
|
||||
print(a)
|
||||
season_rules = r'(.*)(S.\d)'
|
||||
a = re.match(season_rules, name, re.I)
|
||||
if a is not None:
|
||||
print(a.group(1))
|
||||
print(a.group(2))
|
||||
else:
|
||||
print(name)
|
||||
@@ -1,4 +1,3 @@
|
||||
import argparse
|
||||
import re
|
||||
import io
|
||||
import sys
|
||||
@@ -12,6 +11,7 @@ password = environ['PASSWORD']
|
||||
method = environ['METHOD']
|
||||
delay_time = environ['TIME']
|
||||
|
||||
|
||||
# Episode Regular Expression Matching Rules
|
||||
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)?\](.*)',
|
||||
@@ -23,10 +23,6 @@ episode_rules = [r'(.*)\[(\d{1,3}|\d{1,3}\.\d{1,2})(?:v\d{1,2})?(?:END)?\](.*)',
|
||||
# Suffixs of files we are going to rename
|
||||
suffixs = ['mp4', 'mkv', 'avi', 'mov', 'flv', 'rmvb', 'ass', 'idx']
|
||||
sys.stdout = io.TextIOWrapper(buffer=sys.stdout.buffer, encoding='utf8')
|
||||
parser = argparse.ArgumentParser(description='Regular Expression Match')
|
||||
parser.add_argument('--hash', default='',
|
||||
help='The torrent Hash value.')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
class QbittorrentRename:
|
||||
@@ -47,6 +43,7 @@ class QbittorrentRename:
|
||||
|
||||
def rename_normal(self, idx):
|
||||
self.name = self.recent_info[idx].name
|
||||
self.hash = self.recent_info[idx].hash
|
||||
file_name = self.name
|
||||
for rule in episode_rules:
|
||||
matchObj = re.match(rule, file_name, re.I)
|
||||
@@ -55,6 +52,7 @@ class QbittorrentRename:
|
||||
|
||||
def rename_pn(self, idx):
|
||||
self.name = self.recent_info[idx].name
|
||||
self.hash = self.recent_info[idx].hash
|
||||
n = re.split(r'\[|\]', self.name)
|
||||
file_name = self.name.replace(f'[{n[1]}]', '')
|
||||
for rule in episode_rules:
|
||||
@@ -62,36 +60,43 @@ class QbittorrentRename:
|
||||
if matchObj is not None:
|
||||
self.new_name = re.sub(r'\[|\]', '', f'{matchObj.group(1)} E{matchObj.group(2)}.{n[-1]}')
|
||||
|
||||
def rename_hash(self, torrent_hash):
|
||||
self.hash = torrent_hash
|
||||
def rename(self):
|
||||
try:
|
||||
self.qbt_client.torrents_rename_file(torrent_hash=self.hash, old_path=self.name, new_path=self.new_name)
|
||||
self.count += 1
|
||||
print(f'{self.name} >> {self.new_name}')
|
||||
self.count += 1
|
||||
except:
|
||||
return
|
||||
|
||||
def clear_info(self):
|
||||
self.name = None
|
||||
self.hash = None
|
||||
self.new_name = None
|
||||
|
||||
def print_result(self):
|
||||
sys.stdout.write(f"-----已完成对{self.torrent_count}个文件的检查,已对其中{self.count}个文件进行重命名-----" + '\n')
|
||||
sys.stdout.write("------------------------完成------------------------" + '\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
def rename_app(self):
|
||||
if self.method not in ['pn', 'normal', 'hash']:
|
||||
if self.method not in ['pn', 'normal']:
|
||||
print('error method')
|
||||
elif self.method == 'normal':
|
||||
for i in range(0, self.torrent_count + 1):
|
||||
try:
|
||||
self.rename_normal(i)
|
||||
self.rename()
|
||||
self.clear_info()
|
||||
except:
|
||||
sys.stdout.write(f"-----已完成对{i + 1}个文件的检查,已对其中{self.count}个文件进行重命名-----" + '\n')
|
||||
sys.stdout.write("------------------------完成------------------------" + '\n')
|
||||
sys.stdout.flush()
|
||||
self.print_result()
|
||||
elif self.method == 'pn':
|
||||
for i in range(0, self.torrent_count + 1):
|
||||
try:
|
||||
self.rename_pn(i)
|
||||
self.rename()
|
||||
self.clear_info()
|
||||
except:
|
||||
sys.stdout.write(f"-----已完成对{i + 1}个文件的检查,已对其中{self.count}个文件进行重命名-----" + '\n')
|
||||
sys.stdout.write("------------------------完成------------------------" + '\n')
|
||||
sys.stdout.flush()
|
||||
elif self.method == 'hash':
|
||||
self.rename_hash(args.hash)
|
||||
self.print_result()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
37
rename_qb.py
37
rename_qb.py
@@ -1,4 +1,3 @@
|
||||
import argparse
|
||||
import re
|
||||
import io
|
||||
import sys
|
||||
@@ -25,10 +24,6 @@ episode_rules = [r'(.*)\[(\d{1,3}|\d{1,3}\.\d{1,2})(?:v\d{1,2})?(?:END)?\](.*)',
|
||||
# Suffixs of files we are going to rename
|
||||
suffixs = ['mp4', 'mkv', 'avi', 'mov', 'flv', 'rmvb', 'ass', 'idx']
|
||||
sys.stdout = io.TextIOWrapper(buffer=sys.stdout.buffer, encoding='utf8')
|
||||
parser = argparse.ArgumentParser(description='Regular Expression Match')
|
||||
parser.add_argument('--hash', default='',
|
||||
help='The torrent Hash value.')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
class QbittorrentRename:
|
||||
@@ -49,6 +44,7 @@ class QbittorrentRename:
|
||||
|
||||
def rename_normal(self, idx):
|
||||
self.name = self.recent_info[idx].name
|
||||
self.hash = self.recent_info[idx].hash
|
||||
file_name = self.name
|
||||
for rule in episode_rules:
|
||||
matchObj = re.match(rule, file_name, re.I)
|
||||
@@ -57,6 +53,7 @@ class QbittorrentRename:
|
||||
|
||||
def rename_pn(self, idx):
|
||||
self.name = self.recent_info[idx].name
|
||||
self.hash = self.recent_info[idx].hash
|
||||
n = re.split(r'\[|\]', self.name)
|
||||
file_name = self.name.replace(f'[{n[1]}]', '')
|
||||
for rule in episode_rules:
|
||||
@@ -64,36 +61,42 @@ class QbittorrentRename:
|
||||
if matchObj is not None:
|
||||
self.new_name = re.sub(r'\[|\]', '', f'{matchObj.group(1)} E{matchObj.group(2)}.{n[-1]}')
|
||||
|
||||
def rename_hash(self, torrent_hash):
|
||||
self.hash = torrent_hash
|
||||
def rename(self):
|
||||
try:
|
||||
self.qbt_client.torrents_rename_file(torrent_hash=self.hash, old_path=self.name, new_path=self.new_name)
|
||||
self.count += 1
|
||||
print(f'{self.name} >> {self.new_name}')
|
||||
self.count += 1
|
||||
except:
|
||||
return
|
||||
|
||||
def clear_info(self):
|
||||
self.name = None
|
||||
self.hash = None
|
||||
self.new_name = None
|
||||
|
||||
def print_result(self):
|
||||
print(f"-----已完成对{self.torrent_count}个文件的检查,已对其中{self.count}个文件进行重命名-----")
|
||||
print("------------------------完成------------------------")
|
||||
|
||||
def rename_app(self):
|
||||
if self.method not in ['pn', 'normal', 'hash']:
|
||||
if self.method not in ['pn', 'normal']:
|
||||
print('error method')
|
||||
elif self.method == 'normal':
|
||||
for i in range(0, self.torrent_count + 1):
|
||||
try:
|
||||
self.rename_normal(i)
|
||||
self.rename()
|
||||
self.clear_info()
|
||||
except:
|
||||
print(f"-----已完成对{i + 1}个文件的检查,已对其中{self.count}个文件进行重命名-----")
|
||||
print("------------------------完成------------------------")
|
||||
quit()
|
||||
self.print_result()
|
||||
elif self.method == 'pn':
|
||||
for i in range(0, self.torrent_count + 1):
|
||||
try:
|
||||
self.rename_pn(i)
|
||||
self.rename()
|
||||
self.clear_info()
|
||||
except:
|
||||
print(f"-----已完成对{i + 1}个文件的检查,已对其中{self.count}个文件进行重命名-----")
|
||||
print("------------------------完成------------------------")
|
||||
quit()
|
||||
elif self.method == 'hash':
|
||||
self.rename_hash(args.hash)
|
||||
self.print_result()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user