项目作者: ArabCoders

项目描述 :
Plex Lazy scanner.
高级语言: PHP
项目地址: git://github.com/ArabCoders/php_plex.git
创建时间: 2019-10-02T11:36:16Z
项目社区:https://github.com/ArabCoders/php_plex

开源协议:MIT License

下载


Plex Lazy Scanner

The aim of this project is to do partial plex scan instead of doing full scan, this script is mainly for rclone users.

The general idea is by retrieving plex sections and their associated locations. We can monitor changes in rclone cache
via either VFS or the cache backend. After that we then compare the location to our list from plex.

if the filepath matches, then we trigger partial scan, usually within minute or so you could see your updated library.

Configuration.

Configuration is done via ENV variables.

export PP_LOG_TYPE=file; php PHPPlex.php run -vvv

```shell script

string Where your Rclone is mounted must match what is added into plex.

PP_MEDIA_PATH= ‘/mnt/gdrive/‘;

string How is Rclone log stored file or journal?

PP_LOG_TYPE= ‘file’;

string Full path to logfile or service name if log is stored in journalctrl.

PP_LOG_LOCATION = ‘/var/log/rclone.log’;

string Rclone log type (VFS|cache).

PP_LOG_MATCH_TYPE= ‘cache’;

bool Whether to use SSL for plex connection.

PP_PLEX_SSL = false;

int Plex port.

PP_PLEX_PORT = 32400;,

string Plex host or ip.

PP_PLEX_HOST = ‘localhost’;

string Plex Token.

PP_PLEX_TOKEN = ‘X-Token-Token’,

string Plex Scanner Command. it will get passed two variables {section}=(int)sectionId {directory}=(string)directory.

PP_SCANNER_CMD = ‘/usr/lib/plexmediaserver/Plex\ Media\ Scanner —scan —refresh —section {section} —directory {directory}’;

string Those variables required to trigger plex scan.

PP_SCANNER_ENV_LD = ‘/usr/lib/plexmediaserver/lib’;

string Those variables required to trigger plex scan.

PP_SCANNER_ENV_DIR = ‘/var/lib/plexmediaserver/Library/Application Support’;

  1. Requirement.
  2. -------------------
  3. * PHP 7.1+.
  4. * PHP curl extension.
  5. * PHP pnctl extension.
  6. * PHP simplexml extension.
  7. Typical rClone config.
  8. ----------------------
  9. ```ini
  10. [gdrive]
  11. type = drive
  12. scope = drive
  13. token = {}
  14. client_id =
  15. client_secret =
  16. [gcache]
  17. type = cache
  18. remote = gdrive:/gdrive
  19. chunk_size = 128M
  20. info_age = 1d
  21. chunk_total_size = 10G
  22. plex_token =
  23. [gcrypt]
  24. type = crypt
  25. remote = gcache:/crypt
  26. filename_encryption = standard
  27. directory_name_encryption = true
  28. password =
  29. password2 =
  30. [gvfs]
  31. type = crypt
  32. remote = gdrive:/gdrive/crypt
  33. filename_encryption = standard
  34. directory_name_encryption = true
  35. password =
  36. password2 =

Typical rclone mount command.

  • cache backend base.

```shell script
/usr/bin/rclone mount gcrypt: /mnt/gdrive/ \
—allow-other \
—fast-list \
—buffer-size 0M \
—dir-cache-time 100h \
—attr-timeout 100h \
—log-level INFO \
—log-file /var/log/rclone.log \
—timeout 1h \
—umask 002 \
—poll-interval 15s \
—read-only

  1. * VFS cache based
  2. ```shell script
  3. /usr/bin/rclone mount gvfs: /mnt/gdrive/ \
  4. --allow-other \
  5. --fast-list \
  6. --buffer-size 128M \
  7. --vfs-cache-mode minimal \
  8. --vfs-cache-max-age 7h \
  9. --vfs-cache-poll-interval 1m \
  10. --vfs-cache-max-size 10G \
  11. --dir-cache-time 100h \
  12. --attr-timeout 100h \
  13. --syslog \
  14. --log-level INFO \
  15. --timeout 1h \
  16. --umask 002 \
  17. --poll-interval 15s \
  18. --read-only

Installation and Usage

You can use the script via phpplex.phar or by cloning the repository

```shell script
git clone https://github.com/ArabCoders/php_plex.git /opt/php_plex

  1. Assuming you have already modified your edited your ENV, you can run this script in many ways.
  2. * SCREEN
  3. ```shell script
  4. # cloned Repo.
  5. screen -S php_plex php /opt/php_plex/app/PHPPlex.php run -vvv
  6. # Phar
  7. screen -S php_plex php /opt/phphar.phar run -vvv
  • Systemd service.

```shell script
cp /opt/php_plex/example/php_plex.service /etc/systemd/system/
systemctrl enable php_plex.service
systemctrl start php_plex.service

  1. * supervisor
  2. ```shell script
  3. cp ./example/php_plex/php_plex.supervisor.conf /etc/supervisor/conf.d/php_plex.conf
  4. systemctrl restart supervisor

What ever you choose, you should run the script in the same user as plex is running on, otherwise the scanner
would not run.

FAQ

  • i cant see file changes in VFS log messages.

For VFS based cache you need to run rclone with ---log-level DEBUG to be able to see file changes notification.

  • I am not seeing any library updates.

There could be many reasons, but usually it’s one of the following:

  1. the script is not running in same user as plex.
  2. the script isn’t able to read rclone logs.
  3. rclone is not configured to the required --log-level.