l3uddz / plex_autoscan

Script to assist sonarr/radarr with plex imports. Will only scan the folder that has been imported, instead of the whole library section.
GNU General Public License v3.0
396 stars 70 forks source link

Plex_autoscan block after a second request #47

Closed laster13 closed 5 years ago

laster13 commented 6 years ago

First of all, I thank you for making your work available. I expose you my problem. (Sorry from my poor english, i'm french)

I created a docker image with rclone plexdrive5 unionfs plex_autoscan that I modified in my dockerfile to work with python3 https://github.com/laster13/plexdrive-rclone

sed -i -e "s/import Queue/import queue/g" threads.py && \
sed -i -e "s/self._waiter_queue = Queue.PriorityQueue()/self._waiter_queue = queue.PriorityQueue()/g" threads.py && \
sed -i -e "s/from urllib import urlencode/from urllib.parse import urlencode/g" gdrive.py && \

Sonarr sends his scan request to plex_autoscan it works.

2018-08-19 18:28:56,292 -     INFO -  AUTOSCAN [112975860950784]: Client '127.0.0.1' scan request for series: '/tv/Ballers/Season 3/Ballers - S03E02 - Bull Rush SDTV.avi', event: 'Download'
 2018-08-19 18:28:56,292 -    DEBUG -     UTILS [112975860950784]: Mapping '/tv/' to '/mnt/Union/TV/'
 2018-08-19 18:28:56,292 -    DEBUG -  AUTOSCAN [112975860950784]: Using section id: 1 for '/mnt/Union/TV/Ballers/Season 3/Ballers - S03E02 - Bull Rush SDTV.avi'
 2018-08-19 18:28:56,296 -     INFO -      PLEX [112975774209792]: Scan request from Sonarr for '/mnt/Union/TV/Ballers/Season 3/Ballers - S03E02 - Bull Rush SDTV.avi', sleeping for 1 seconds...
 2018-08-19 18:28:57,298 -     INFO -      PLEX [112975774209792]: File '/mnt/Union/TV/Ballers/Season 3/Ballers - S03E02 - Bull Rush SDTV.avi' exists on check 1 of 10.
 2018-08-19 18:28:57,298 -    DEBUG -     UTILS [112975774209792]: Using priority 0 for path '/mnt/Union/TV/Ballers/Season 3'
 2018-08-19 18:28:57,298 -    DEBUG -      PLEX [112975774209792]: Waiting for turn in the scan request backlog with priority: 0
 2018-08-19 18:28:57,299 -     INFO -      PLEX [112975774209792]: Scan request is now being processed
 2018-08-19 18:28:57,301 -     INFO -      PLEX [112975774209792]: No 'Plex Media Scanner' processes were found.
 2018-08-19 18:28:57,301 -     INFO -      PLEX [112975774209792]: Starting Plex Scanner
 2018-08-19 18:28:57,302 -    DEBUG -      PLEX [112975774209792]: export LD_LIBRARY_PATH=/usr/lib/plexmediaserver;export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/config/Library/Application\ Support;/usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan --refresh --section 1 --directory '/mnt/Union/TV/Ballers/Season 3'
 2018-08-19 18:28:57,632 -     INFO -     UTILS [112975774209792]: 'GUI: Scanning Ballers Season 3 Episode 1'
 2018-08-19 18:28:57,633 -     INFO -     UTILS [112975774209792]: 'GUI: Scanning Ballers Season 3 Episode 2'
 2018-08-19 18:28:57,788 -     INFO -     UTILS [112975774209792]: "GUI: Requesting metadata for 'Ballers'"
 2018-08-19 18:28:57,851 -     INFO -     UTILS [112975774209792]: 'GUI: Background media analysis on Ballers S03 E02'
 2018-08-19 18:28:58,124 -     INFO -      PLEX [112975774209792]: Finished scan!
 2018-08-19 18:28:58,124 -    DEBUG -      PLEX [112975774209792]: Sleeping 10 seconds before sending analyze request
 2018-08-19 18:29:08,139 -     INFO -      PLEX [112975774209792]: Found row in media_parts where file = '/mnt/Union/TV/Ballers/Season 3/Ballers - S03E02 - Bull Rush SDTV.avi' after 1/5 tries!
 2018-08-19 18:29:08,140 -    DEBUG -      PLEX [112975774209792]: Found metadata_item_id for '/mnt/Union/TV/Ballers/Season 3/Ballers - S03E02 - Bull Rush SDTV.avi': 16
 2018-08-19 18:29:08,140 -    DEBUG -      PLEX [112975774209792]: Found parent_id for '/mnt/Union/TV/Ballers/Season 3/Ballers - S03E02 - Bull Rush SDTV.avi': 13
 2018-08-19 18:29:08,141 -     INFO -      PLEX [112975774209792]: Starting basic analysis of metadata_item(s): 13
 2018-08-19 18:29:08,141 -    DEBUG -      PLEX [112975774209792]: export LD_LIBRARY_PATH=/usr/lib/plexmediaserver;export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/config/Library/Application\ Support;/usr/lib/plexmediaserver/Plex\ Media\ Scanner --analyze --item 13
 2018-08-19 18:29:08,409 -     INFO -     UTILS [112975774209792]: 'GUI: Media analysis on Ballers S03 E01'
 2018-08-19 18:29:10,821 -     INFO -     UTILS [112975774209792]: 'GUI: Media analysis on Ballers S03 E02'
 2018-08-19 18:29:10,933 -     INFO -      PLEX [112975774209792]: Finished basic analysis of metadata_item(s): 13!

On the other hand, if he sends a second request, it blocks at this level

 2018-08-19 18:31:26,558 -     INFO -  AUTOSCAN [112975860950784]: Client '127.0.0.1' scan request for series: '/tv/Ballers/Season 3/Ballers - S03E03 - In the Teeth SDTV.avi', event: 'Download'
 2018-08-19 18:31:26,558 -    DEBUG -     UTILS [112975860950784]: Mapping '/tv/' to '/mnt/Union/TV/'
 2018-08-19 18:31:26,558 -    DEBUG -  AUTOSCAN [112975860950784]: Using section id: 1 for '/mnt/Union/TV/Ballers/Season 3/Ballers - S03E03 - In the Teeth SDTV.avi'
 2018-08-19 18:31:26,559 -     INFO -      PLEX [112975774209792]: Scan request from Sonarr for '/mnt/Union/TV/Ballers/Season 3/Ballers - S03E03 - In the Teeth SDTV.avi', sleeping for 1 seconds...
 2018-08-19 18:31:27,560 -     INFO -      PLEX [112975774209792]: File '/mnt/Union/TV/Ballers/Season 3/Ballers - S03E03 - In the Teeth SDTV.avi' exists on check 1 of 10.
 2018-08-19 18:31:27,561 -    DEBUG -     UTILS [112975774209792]: Using priority 0 for path '/mnt/Union/TV/Ballers/Season 3'
 2018-08-19 18:31:27,561 -    DEBUG -      PLEX [112975774209792]: Waiting for turn in the scan request backlog with priority: 0
Connection to 82.94.168.53 closed by remote host.

my docker-compose

version: '2.1'
services:
  sonarr:
    container_name: sonarr
    image: linuxserver/sonarr
    restart: unless-stopped
    ports:
      - 8989:8989
    depends_on:
      - torrent
    depends_on:
        plex:
           condition: service_healthy
    environment:
      - /etc/localtime:/etc/localtime:ro \
      - TZ=Paris/Europe
      - PUID=0
      - PGID=0
    volumes:
      - /mnt/docker/sonarr/config:/config
      - /mnt/docker/rutorrent/data/torrents:/downloads
      - /mnt/docker/Plex/Union/TV:/tv

  plex:
    container_name: plex
    image: laster13/plexdrive-rclone
    restart: unless-stopped
    ports:
      - 32400:32400
    healthcheck:
        interval: 10s
        timeout: 1s
    cap_add:
      - SYS_ADMIN
      - MKNOD
    devices:
      - /dev/fuse
    security_opt:
      - apparmor:unconfined
    environment:
      - TZ=Paris/Europe
      - PLEX_CLAIM=
      - PLEX_UID=0
      - PLEX_GID=0
    hostname: mail
    volumes:
      - /mnt/docker/Plex/config:/config
      - /dev/shm:/transcode
      - /mnt/docker/Plex/Union:/mnt/Union:shared
      - /mnt/docker/Plex/Pre:/mnt/Pre:shared
      - /mnt/docker/Plex/rclone:/mnt/rclone:shared

  torrent:
    container_name: torrent
    image: xataz/rtorrent-rutorrent
    restart: unless-stopped
    ports:
      - 9080:8080
      - 6881:6881
      - 6881:6881/udp
      - 127.0.0.1:5000:5000
    environment:
      - UID=1001
      - GID=1001
      - WEBROOT=/rutorrent
      - DHT_RTORRENT=on
      - PORT_RTORRENT=6881
    volumes:
      - /mnt/docker/rutorrent/data:/data
      - /mnt/docker/rutorrent/config:/config

if I restart the container it works again

my config.json

  "PLEX_ANALYZE_DIRECTORY": true,
  "PLEX_ANALYZE_TYPE": "basic",
  "PLEX_DATABASE_PATH": "/config/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db",
  "PLEX_EMPTY_TRASH": false,
  "PLEX_EMPTY_TRASH_CONTROL_FILES": [
    "/mnt/Union/mounted.bin"
  ],
  "PLEX_EMPTY_TRASH_MAX_FILES": 100,
  "PLEX_EMPTY_TRASH_ZERO_DELETED": false,
  "PLEX_LD_LIBRARY_PATH": "/usr/lib/plexmediaserver",
  "PLEX_LOCAL_URL": "http://localhost:32400",
  "PLEX_SCANNER": "/usr/lib/plexmediaserver/Plex\\ Media\\ Scanner",
  "PLEX_SECTION_PATH_MAPPINGS": {
    "1": [
      "/TV/"
    ]
  },
  "PLEX_SUPPORT_DIR": "/config/Library/Application\\ Support",
  "PLEX_TOKEN": "xHp7Y92i3Rbiz361GPJR",
  "PLEX_USER": "plex",
  "PLEX_WAIT_FOR_EXTERNAL_SCANNERS": true,
  "RCLONE_RC_CACHE_EXPIRE": {
    "ENABLED": false,
    "FILE_EXISTS_TO_REMOTE_MAPPINGS": {
    },
    "RC_URL": "http://localhost:5572"
  },
  "RUN_COMMAND_BEFORE_SCAN": "",
  "SERVER_ALLOW_MANUAL_SCAN": true,
  "SERVER_FILE_EXIST_PATH_MAPPINGS": {},
  "SERVER_IGNORE_LIST": [
    "/.grab/",
    ".DS_Store",
    "Thumbs.db"
  ],
  "SERVER_IP": "127.0.0.1",
  "SERVER_MAX_FILE_CHECKS": 10,
  "SERVER_PASS": "19b21980d2dd4fc8a2931dc8e6f8f073",
  "SERVER_PATH_MAPPINGS": {
    "/mnt/Union/TV/": [
      "/tv/"
    ]
  },
  "SERVER_PORT": 3467,
  "SERVER_SCAN_DELAY": 1,
  "SERVER_SCAN_FOLDER_ON_FILE_EXISTS_EXHAUSTION": true,
  "SERVER_SCAN_PRIORITIES": {
    "0": [
      "/TV/"
    ]
  },
  "SERVER_USE_SQLITE": false,
  "USE_DOCKER": false,
  "USE_SUDO": true
}

my structure

Docker Data
├── pms-docker
│   ├── config
│   │   ├── Library
|   |   |   └── ...
│   │   │
│   │   ├── .plexdrive
│   │   |   └── ...
|   |   | 
|   |   ├── rclone
|   |   |   └── ...
|   |   |
|   |   ├── plex_autoscan
|   |   |   └── ...
|   |   |
|   |   ├── unionfs_cleaner
|   |   |   └── ...
|   |   |
|   |   ├── plex_dupefinder
|   |       └── ...
|   |   
│   └── transcode
└──

If you can help me, it's been a week that I search without success, I'm at the end of ideas

Thanks

l3uddz commented 5 years ago

Try using python 2. I believe the priority thread lock class I am using is not supported with python 3.

laster13 commented 5 years ago

Thanks it works with python2