From f945d5ebb9ca5898981ff003b00ab81c437a540f Mon Sep 17 00:00:00 2001 From: sqkkyzx Date: Thu, 29 Feb 2024 17:48:22 +0800 Subject: [PATCH] Added a retry mechanism for user inputs and improved the prompt when an input format is incorrect. --- .idea/.gitignore | 8 +++++++ .idea/inspectionProfiles/Project_Default.xml | 11 +++++++++ .../inspectionProfiles/profiles_settings.xml | 6 +++++ .idea/misc.xml | 7 ++++++ .idea/modules.xml | 8 +++++++ .idea/plex_localization_zhcn.iml | 16 +++++++++++++ .idea/vcs.xml | 6 +++++ plex_localization_zhcn.py | 23 +++++++++++++++---- requirements.txt | 2 ++ 9 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/plex_localization_zhcn.iml create mode 100644 .idea/vcs.xml create mode 100644 requirements.txt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..22cdf9b --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..db8786c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4eb1f8c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/plex_localization_zhcn.iml b/.idea/plex_localization_zhcn.iml new file mode 100644 index 0000000..7b40359 --- /dev/null +++ b/.idea/plex_localization_zhcn.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/plex_localization_zhcn.py b/plex_localization_zhcn.py index f8516db..0522a78 100644 --- a/plex_localization_zhcn.py +++ b/plex_localization_zhcn.py @@ -127,7 +127,15 @@ def select_library(self, index=None): echo = [f"{library[0]}> {library[2]} <{library[3]}>" for library in libraries.values()] - index = index if index else int(input("\n" + "\n".join(echo) + "\n请选择库:")) + if index: + pass + else: + while True: + try: + index = int(input("\n" + "\n".join(echo) + "\n请选择库:")) + break + except ValueError: + print("格式不正确,需要输入整数数字。") action_key, action_type = index, libraries[index][1] @@ -211,9 +219,16 @@ def operate_item(self, rating_key): def loop_all(self, library_id: int = None, thread_count: int = None): """选择媒体库并遍历其中的每一个媒体。""" - if not thread_count: - thread_count = input("\n请输入运行的线程数(输入整数数字,默认为2):") - thread_count = int(thread_count if thread_count else 2) + + if thread_count: + pass + else: + while True: + try: + thread_count = int(input("\n请输入运行的线程数(输入整数数字,默认为2):")) + break + except ValueError: + print("格式不正确,需要输入整数数字。") if library_id == 999: libraries = self.list_libraries().values() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2eb2a7e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pypinyin>=0.50.0 +requests>=2.31.0 \ No newline at end of file