Cloudbox / autoscan

Autoscan replaces the default Plex and Emby behaviour for picking up changes on the file system.
MIT License
594 stars 49 forks source link

Multiple rewrites don't work past the first value #212

Closed Kjasi closed 11 months ago

Kjasi commented 11 months ago

I'm running Autoscan and Jellyfin on my NAS through docker, and running Radarr and Sonarr on a separate Windows system.

This makes passing paths interesting, as Radarr will pass a windows path (V:\\Movies\\Alphabetical\\B\\Beetlejuice (1988) [imdbid-tt0094721]) to Autoscan.

Now, I've solved most of the Windows/Unix path issues by using

  radarr:
    - name: radarr
      priority: 2
      rewrite:
        - from: (.*?)\\
          to: $1/

While this DOES convert all the \\ in my path to a unix friendly /, (something I think should be in the base code of the program. Manual scan does this!) this does not fix the drive prefix for the path. My thought was (based on the documentation) I could write a second rewrite variable, which would correct for that:

  radarr:
    - name: radarr
      priority: 2
      rewrite:
        - from: (.*?)\\
          to: $1/
        - from: V:/
          to: /media/

This should kick back /media/Movies/Alphabetical/B/Beetlejuice (1988) [imdbid-tt0094721], but it doesn't. Instead, I get V:/Movies/Alphabetical/B/Beetlejuice (1988) [imdbid-tt0094721] which looks like the second rule isn't even ran.

I tried adding numerous additional variables, (Movies to test, ^V:\ to /media/, A to B) none of which seems to activate, unless it was the first rule. If I swap my rules' order, like:

  radarr:
    - name: radarr
      priority: 2
      rewrite:
        - from: V:\\
          to: /media/
        - from: (.*?)\\
          to: $1/

This produces /media/Movies\\Alphabetical\\B\\Beetlejuice (1988) [imdbid-tt0094721] instead.

With no combination, can I get anything but the first rewrite rule to work. Am I writing the rules wrong, or is this an issue with the program itself?

m-rots commented 11 months ago

Whenever a path comes in, only the first rewrite rule that matches gets applied indeed! I'm not sure whether changing the rewrite rules would be backward-compatible with existing configurations, but this is definitely something to keep in mind for a future version of Autoscan :)

Kjasi commented 11 months ago

How about a tag inside the rule, that makes it additive to any rule before it? By default, it would be false (backwards compatible) but if found, it applies?

This could be

  radarr:
    - name: radarr
      priority: 2
      rewrite:
        - from: V:\\
          to: /media/
        - from: (.*?)\\
          to: $1/
          additive: true

This way, if I had multiple rewrites for multiple drives, they would work as before, but any (and all) additive paths are applied on top of that change?

And since this doesn't apply currently, is there any way I can go about converting from a windows path to a unix path with rewrites?