From 3d7bcf927cde542d7165cbdfd60554d74e1a2962 Mon Sep 17 00:00:00 2001 From: Mathhew Date: Wed, 23 Sep 2020 09:34:14 +0800 Subject: [PATCH 1/4] Refine location_rule with title #314 --- core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core.py b/core.py index 0ae674d..b447aa1 100755 --- a/core.py +++ b/core.py @@ -197,7 +197,8 @@ def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON print(conf.location_rule()) location_rule = eval(conf.location_rule().replace("actor","'多人作品'")) if 'title' in conf.location_rule() and len(title) > 100: - location_rule = eval(conf.location_rule().replace("title",'number')) + shorttitle = title[0:100] + "..." + location_rule = location_rule.replace(title, shorttitle) # 返回处理后的json_data json_data['title'] = title From 0f16ddc19806a565917e2020bb45275496c4051a Mon Sep 17 00:00:00 2001 From: Mathhew Date: Wed, 23 Sep 2020 09:44:14 +0800 Subject: [PATCH 2/4] Fix folder name --- core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core.py b/core.py index b447aa1..3b00200 100755 --- a/core.py +++ b/core.py @@ -197,7 +197,7 @@ def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON print(conf.location_rule()) location_rule = eval(conf.location_rule().replace("actor","'多人作品'")) if 'title' in conf.location_rule() and len(title) > 100: - shorttitle = title[0:100] + "..." + shorttitle = title[0:100] location_rule = location_rule.replace(title, shorttitle) # 返回处理后的json_data From cc2d44b728f231fb6d1e567eeee7944050a827f2 Mon Sep 17 00:00:00 2001 From: Mathhew Date: Fri, 25 Sep 2020 11:49:15 +0800 Subject: [PATCH 3/4] Add max_title_len config default value is 50 --- config.py | 10 ++++++++++ core.py | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 6389444..1ad6fee 100644 --- a/config.py +++ b/config.py @@ -50,6 +50,15 @@ class Config: def location_rule(self) -> str: return self.conf.get("Name_Rule", "location_rule") + + def max_title_len(self) -> int: + """ + Maximum title length + """ + try: + return self.conf.getint("Name_Rule", "max_title_len") + except ValueError: + return 50 def update_check(self) -> bool: try: @@ -99,6 +108,7 @@ class Config: conf.add_section(sec3) conf.set(sec3, "location_rule", "actor + '/' + number") conf.set(sec3, "naming_rule", "number + '-' + title") + conf.set(sec3, "max_title_len", "50") sec4 = "update" conf.add_section(sec4) diff --git a/core.py b/core.py index 3b00200..1cd379e 100755 --- a/core.py +++ b/core.py @@ -196,8 +196,9 @@ def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON if 'actor' in conf.location_rule() and len(actor) > 100: print(conf.location_rule()) location_rule = eval(conf.location_rule().replace("actor","'多人作品'")) - if 'title' in conf.location_rule() and len(title) > 100: - shorttitle = title[0:100] + maxlen = conf.max_title_len() + if 'title' in conf.location_rule() and len(title) > maxlen: + shorttitle = title[0:maxlen] location_rule = location_rule.replace(title, shorttitle) # 返回处理后的json_data From 8873a4a7bd3615377574fc8c622a2e5a0f8f482f Mon Sep 17 00:00:00 2001 From: Mathhew Date: Fri, 25 Sep 2020 16:45:16 +0800 Subject: [PATCH 4/4] Update config.ini --- config.ini | 1 + config.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config.ini b/config.ini index 1f391a7..117eec9 100644 --- a/config.ini +++ b/config.ini @@ -16,6 +16,7 @@ retry=3 [Name_Rule] location_rule=actor+'/'+number naming_rule=number+'-'+title +max_title_len= 50 [update] update_check=1 diff --git a/config.py b/config.py index 1ad6fee..9a95199 100644 --- a/config.py +++ b/config.py @@ -57,7 +57,7 @@ class Config: """ try: return self.conf.getint("Name_Rule", "max_title_len") - except ValueError: + except: return 50 def update_check(self) -> bool: