更新代码

This commit is contained in:
EstrellaXD
2022-05-16 12:04:36 +08:00
parent 584a419712
commit fbbb40703f
4 changed files with 50 additions and 54 deletions

View File

@@ -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" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.10 (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

2
.idea/misc.xml generated
View File

@@ -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" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (2)" project-jdk-type="Python SDK" />
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -28,10 +28,11 @@ 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 Qbtorrent_Rename:
def __init__(self, method):
class QbittorrentRename:
def __init__(self, rename_method):
self.qbt_client = qbittorrentapi.Client(host=host_ip, username=user_name, password=password)
try:
self.qbt_client.auth_log_in()
@@ -44,70 +45,59 @@ class Qbtorrent_Rename:
self.count = 0
self.rename_count = 0
self.torrent_count = len(self.recent_info)
self.method = method
self.method = rename_method
def rename(self, idx):
def rename_normal(self, idx):
self.name = self.recent_info[idx].name
if self.method == "pn":
n = re.split(r'\[|\]', self.name)
file_name = self.name.replace(f'[{n[1]}]', '')
else:
file_name = self.name
file_name = self.name
for rule in episode_rules:
matchObj = re.match(rule, file_name, re.I)
if matchObj is not None:
if self.method == 'normal':
self.new_name = f'{matchObj.group(1)} E{matchObj.group(2)} {matchObj.group(3)}'
elif self.method == 'pn':
new_name = f'{matchObj.group(1)} E{matchObj.group(2)}.mp4'
new_name = new_name.replace('[', '')
self.new_name = new_name.replace(']', '')
self.new_name = f'{matchObj.group(1)} E{matchObj.group(2)} {matchObj.group(3)}'
def qb_rename(self, idx, torrent_hash=''):
self.rename(idx)
if torrent_hash == '':
self.hash = self.recent_info[idx].hash
else:
self.hash = torrent_hash
def rename_pn(self, idx):
self.name = self.recent_info[idx].name
n = re.split(r'\[|\]', self.name)
file_name = self.name.replace(f'[{n[1]}]', '')
for rule in episode_rules:
matchObj = re.match(rule, file_name, re.I)
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
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}')
except:
return
self.new_name = None
def rename_app(self):
if self.method not in ['pn', 'normal', 'hash']:
print('error method')
elif self.method == 'normal':
for i in range(0, self.torrent_count + 1):
try:
self.rename_normal(i)
except:
print(f"-----已完成对{i + 1}个文件的检查,已对其中{self.count}个文件进行重命名-----")
print("------------------------完成------------------------")
quit()
elif self.method == 'pn':
for i in range(0, self.torrent_count + 1):
try:
self.rename_pn(i)
except:
print(f"-----已完成对{i + 1}个文件的检查,已对其中{self.count}个文件进行重命名-----")
print("------------------------完成------------------------")
quit()
elif self.method == 'hash':
self.rename_hash(args.hash)
def app():
args = parser.parse_args()
if method not in ['hash', 'pn', 'normal']:
print("Not a correct method")
quit()
qb = Qbtorrent_Rename(method=method)
if method == 'hash':
torrent_hash = args.hash
try:
qb.qb_rename(0, torrent_hash)
except:
print('error')
quit()
elif method == 'pn':
for i in range(0, qb.torrent_count + 1):
try:
qb.qb_rename(i)
except:
print(f"-----已完成对{i + 1}个文件的检查,已对其中{qb.count}个文件进行重命名-----")
print("------------------------完成------------------------")
quit()
else:
for i in range(0, qb.torrent_count + 1):
try:
qb.qb_rename(i)
except:
print(f"-----已完成对{i + 1}个文件的检查,已对其中{qb.count}个文件进行重命名-----")
print("------------------------完成------------------------")
quit()
if __name__ == "__main__":
app()
rename = QbittorrentRename(method)
rename.rename_app()