Cloudbox / autoscan

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

Base Directory Path Normalization #150

Closed bluggy closed 2 years ago

bluggy commented 2 years ago

I'm trying to perform a simple configuration as follows using inotify to communicate changes to plex. Plex resides on a different machine and uses an NFS mount to access the media.

minimum-age: 30s
scan-delay: 15s
scan-stats: 15m

triggers:
  inotify:
    - priority: 0
      paths:
        - path: /media/Movies/

targets:
  plex:
    - url: http://plex.lan:32400
      token: XXXXXXXXXXXXXXXXXXXX

However this simple configuration results in a "No target libraries found" problem. I've enabled the debug output and it appears there is discrepancy in the path between what inotify is reporting (i.e., "/media/Movies") and the path stored internally in the Plex library configuration (i.e., "/media/Movies/"). I investigated the code a bit and it appears that Autoscan is checking to see if the Plex library path is a prefix to the path reported by inotify (via the strings.HasPrefix function here) to determine any matching libraries. However, due to the trailing "/" in the Plex library path, this check fails, since "/media/Movies/" is not a prefix of "/media/Movies". I would have expected Autoscan to normalize the path before the comparison instead of failing in this way.

Mar  6 23:18:43 INF Initialised processor anchors=[] min_age=30s
Mar  6 23:18:43 WRN Webhooks running without authentication
Mar  6 23:18:43 INF Initialised triggers bernard=0 inotify=1 lidarr=0 manual=1 radarr=0 sonarr=0
Mar  6 23:18:43 INF Starting server on port 3030
Mar  6 23:18:43 DBG Plex version: 1.25.6.5577-c8bd13540 target=plex url=http://plex.lan:32400
Mar  6 23:18:43 DBG Retrieved libraries libraries=[{"ID":1,"Name":"Movies","Path":"/media/Movies/"}] target=plex url=http://plex.lan:32400
Mar  6 23:18:43 INF Initialised targets autoscan=0 emby=0 jellyfin=0 plex=1
Mar  6 23:18:43 INF Initialised version=" (@)"
Mar  6 23:18:43 INF Processor started
Mar  6 23:19:33 INF Scan moved to processor path=/media/Movies trigger=inotify
Mar  6 23:20:13 WRN No target libraries found error="/media/Movies: failed determining libraries" target=plex url=http://plex.lan:32400

When looking in the Plex User Interface, it doesn't present the path with a trailing "/", thus it likely normalizes the path itself with the trailing "/". The only work-around I've been able to think of (and which does work) is to add a "rewrite" rule to explicitly check for a missing "/" for the path and to add one as part of the rewrite. However, this doesn't seem like a scale-able solution if many paths are involved.

targets:
  plex:
    - url: http://plex.lan:32400
      token: XXXXXXXXXXXXXXXXXXXX
      rewrite:
        - from: /media/Movies$
          to: /media/Movies/

Am I doing something wrong here or is this just a case that was not yet encountered?

m-rots commented 2 years ago

This issue has been brought up a couple of times on our Discord server as well, but we're keeping the behaviour as is. Generally speaking we want to avoid people scanning their entire library accidentally. Moreover, a manual scan of an entire library can be done in the Plex UI as well.