在 yaml 文件中的大写字母前添加 space(flexget 配置)

Adding space before capital letters in yaml file (flexget config)

我对 FlexGet Configuration 有一些问题。

我想重命名和移动一些电影。

例子

例如电影 "ElPatriota"(目前无法重命名)在搜索此标题时不带空格时无法在 TheMovieDataBase (tmdb) 中找到。

所以我需要先将它重命名为"El Patriota",然后才能在tmdb中查找并将其移动到他正确的目录。

我研究了什么

我看到这个函数使用 regular-expression,但我不知道如何在我的配置中实现它,或者它是否适合我。

re.sub(r"(\w)([A-Z])", r" ", "WordWordWord")
'Word Word Word'

FlexGet 配置 YAML

这是相关配置的一部分:

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

关于 search-terms

构造的假设

根据您的评论,我假设 file-name 作为搜索输入的替换步骤是:

    set:
      title: "{{title|replace('4K','[]')|replace('BD1080','[]')|replace('M1080','[]')}}"  

所以不同的search-terms(设置titles)是备选方案(由|分隔,如布尔或):

title|replace('4K','[]')|replace('BD1080','[]')|replace('M1080','[]')

另请参阅 FlexGet 文档:

正则表达式作为解决方案

进一步假设您可以使用 regular-expression 来替换标题。 然后 regex-substitution 在 lower-case 和 upper-case 字母之间添加 space 即可:

Step Value
Input ElPatriotaM1080.www.url.com.mkv
Wanted El Patriota M1080.www.url.com.mkv
Regex substitute ([a-z])([A-Z]) by
Output El Patriota M1080.www.url.com.mkv

Manipulatereplace 通过正则表达式

manipulate 插件与动作 replace 相符 Example 4:

You can control how the regex hits are output using </code>, <code>, etc in format.

manipulate:
  - title:
      replace:            
        regexp: '(.*)/(.*)/(.*)'
        format: '..'

⚠️ 注意:正则表达式匹配默认是ignore-case 由于正则表达式是 case-sensitive(取决于不同的 upper-case 和 lower-case 字符),必须禁用操作 replace-by-regex (IGNORE and UNICODE) 的默认 regex-flags明确地通过禁用 inline-flag i 包围正则表达式,例如 (?-i:<regex>).

配置片段

在这种情况下,它看起来像是将 lower-case(第一组 ([a-z]) 并通过引用插入 </code>)与 upper-case(第二组 <code>([A-Z]) 并通过引用 </code>) 插入 space 之间。</p> <p>另外禁用 <code>i 我们需要配置:(?-i:([a-z])([A-Z])).

manipulate:
  - title:
      replace:            
        regexp: '(?-i:([a-z])([A-Z]))'
        format: ' '

或者,不捕获但使用 正 look-ahead 作为 (?=[A-Z]) 然后插入 space (使用 switched-off ignore-case 标志):

manipulate:
  - title:
      replace:            
        regexp: '(?-i:(?=[A-Z]))'
        format: ' '

纯演示 Python

纯 Python 中的工作演示展示了如何替换 file-names。 它改编自 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' ', old_name, flags=flags)
print(f"Regex 2 (I on ): '{new_name}'")
new_name = re.sub(regex_2_no_ignore, r' ', 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'

两个regex-approaches(1+2)的效果几乎一样:space插入在upper-case字母之前。但是,ignore-case 标志(无论是“I on”还是“I off”)对结果产生了意想不到的影响。