[英]Adding space before capital letters in yaml file (flexget config)
我在使用FlexGet配置时遇到了一些问题。
我想重命名和移动一些电影。
例如电影"ElPatriota"
(目前无法重命名)在TheMovieDataBase (tmdb)中搜索不带空格的标题时无法找到。
所以我需要先将它重命名为"El Patriota"
,然后才能在tmdb上查找并将其移动到他的正确目录。
我看到这个 function 使用正则表达式,但我不知道如何在我的配置上实现它,或者它是否适合我。
re.sub(r"(\w)([A-Z])", r"\1 \2", "WordWordWord")
'Word Word Word'
这是相关配置的一部分:
move movies:
priority: 3
template:
- movies-metainfo
- telegram
filesystem:
path: /downloads/
recursive: yes
retrieve: files
regexp: '.*\.(avi|mkv|mp4)$'
seen: local
regexp:
reject:
- \b(duo|tri|quadri|tetra|penta)logy\b: {from: title}
- s\d{2}(e\d{2,})?: {from: title}
require_field:
- tmdb_name
- movie_name
accept_all: yes
tmdb_lookup:
language: es
set:
title: "{{title|replace('4K','[]')|replace('BD1080','[]')|replace('M1080','[]')}}"
move:
to: "/media/Peliculas/"
rename: "{{tmdb_name|replace('/','_')|replace(':',' -')|replace(',','')|replace('?','')}}"
along:
extensions:
- sub
- srt
subdirs:
- Subs
clean_source: 50
根据您的评论,我假设文件名替换步骤作为搜索输入是:
set:
title: "{{title|replace('4K','[]')|replace('BD1080','[]')|replace('M1080','[]')}}"
所以不同的搜索词(设置title
s)是替代品(由|
分隔,如 boolean OR):
title|replace('4K','[]')|replace('BD1080','[]')|replace('M1080','[]')
另请参阅 FlexGet 文档:
进一步假设您可以使用正则表达式来替换标题。 然后正则表达式替换在小写字母和大写字母之间添加一个空格就可以了:
步 | 价值 |
---|---|
输入 | ElPatriotaM1080.www.url.com.mkv |
通缉 | El Patriota M1080.www.url.com.mkv |
正则表达式 | 将([az])([AZ]) 替换为\1 \2 |
Output | El Patriota M1080.www.url.com.mkv |
Manipulate
和replace
适当的manipulate
插件与示例 4中所示的操作replace
:
您可以使用
\1
、\2
等格式控制正则表达式命中output 的方式。manipulate: - title: replace: regexp: '(.*)/(.*)/(.*)' format: '\2.\1.\3'
⚠️ 注意:正则表达式匹配默认忽略大小写由于正则表达式区分大小写(取决于不同的大小写字符),操作替换为正则表达式的默认正则表达式标志(IGNORE 和 UNICODE)必须通过用禁用的内联标志包围正则表达式来明确禁用i
喜欢(?-i:<regex>)
。
在这种情况下,它看起来像是将小写字母(第一组([az])
并通过引用插入\1
)与大写字母(第二组([AZ])
并通过引用插入\2
)之间的空格分开.
另外禁用i
我们需要配置: (?-i:([az])([AZ]))
。
manipulate:
- title:
replace:
regexp: '(?-i:([a-z])([A-Z]))'
format: '\1 \2'
或者,不捕获但以(?=[AZ])
的形式进行正向预测,然后插入一个空格(关闭 ignore-case 标志):
manipulate:
- title:
replace:
regexp: '(?-i:(?=[A-Z]))'
format: ' '
纯 Python 中的工作演示展示了如何替换文件名。 它改编自How to replace camelCasing in all files in a folder using Python or c#? :
import re
old_name = 'ElPatriotaM1080.www.url.com.mkv'
print(f"Given: '{old_name}'")
flags=re.I # default for FlexGet's replace-plugin: ignore-case
regex_1 = '(?=[A-Z])'
regex_1_no_ignore = '(?-i:(?=[A-Z]))'
new_name = re.sub(regex_1, ' ', old_name, flags=flags)
print(f"Regex 1 (I on ): '{new_name}'")
new_name = re.sub(regex_1_no_ignore, ' ', old_name, flags=flags)
print(f"Regex 1 (I off): '{new_name}'")
regex_2 = r'([a-z])([A-Z])'
regex_2_no_ignore = r'(?-i:([a-z])([A-Z]))'
new_name = re.sub(regex_2, r'\1 \2', old_name, flags=flags)
print(f"Regex 2 (I on ): '{new_name}'")
new_name = re.sub(regex_2_no_ignore, r'\1 \2', old_name, flags=flags)
print(f"Regex 2 (I off): '{new_name}'")
印刷:
Given: 'ElPatriotaM1080.www.url.com.mkv'
Regex 1 (I on ): ' E l P a t r i o t a M1080. w w w. u r l. c o m. m k v'
Regex 1 (I off): ' El Patriota M1080.www.url.com.mkv'
Regex 2 (I on ): 'E lP at ri ot aM1080.w ww.u rl.c om.m kv'
Regex 2 (I off): 'El Patriota M1080.www.url.com.mkv'
两种正则表达式方法 (1+2) 具有几乎相同的效果:在大写字母之前插入空格。 然而,忽略大小写标志(无论是“I on”还是“I off”)对结果有意想不到的影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.