cjmanca / plex-credits-detect

Augments plex's built in intro detection, additionally detecting credits.
MIT License
113 stars 5 forks source link

PlexDB Unhandled exception. System.InvalidCastException: Specified cast is not valid. #20

Closed andreaalloway closed 2 years ago

andreaalloway commented 2 years ago

I ran the script for the first time against my plex server and I'm encountering this error:

plex-credit-detect | Loading global config file: /config/plex-credits-detect/fingerprint.ini
plex-credit-detect | Unhandled exception. System.InvalidCastException: Specified cast is not valid.
plex-credit-detect |    at System.Data.SQLite.SQLiteDataReader.VerifyType(Int32 i, DbType typ)
plex-credit-detect |    at System.Data.SQLite.SQLiteDataReader.GetInt32(Int32 i)
plex-credit-detect |    at plexCreditsDetect.Database.SQLResultInfo.GetInt(String v) in /src/plex-credits-detect/Database/SQLResultInfo.cs:line 37
plex-credit-detect |    at plexCreditsDetect.Database.SQLResultInfo.Get[T](String v) in /src/plex-credits-detect/Database/SQLResultInfo.cs:line 109
plex-credit-detect |    at plexCreditsDetect.Database.PlexDB.GetRootDirectories() in /src/plex-credits-detect/Database/PlexDB.cs:line 630
plex-credit-detect |    at plexCreditsDetect.Database.PlexDB.get_RootDirectories() in /src/plex-credits-detect/Database/PlexDB.cs:line 35
plex-credit-detect |    at plexCreditsDetect.Program.Main(String[] args) in /src/plex-credits-detect/Program.cs:line 31

I'm running the docker image for plex-credits-detect and the plex docker image plexinc/pms-docker Disks are mounted to the Docker images for Plex and plex-credits-detect as: (Using docker-compose)

volumes:
      - /disk1/media/Videos/Movies:/data/movies_1
      - /disk1/media/Videos/TV Shows:/data/tv_1
      - /disk2/media/Videos/Movies:/data/movies_2
      - /disk2/media/Videos/TV Shows:/data/tv_2
      - /disk2/media/Videos_3D/Movies:/data/movies_3d
      - /disk2/media/Videos_3D/TV Shows:/data/tv_3d
      - /disk2/media/Videos_4K/Movies:/data/movies_4K
      - /disk2/media/Videos_4K/TV Shows:/data/tv_4k

The Plex media libraries are named: Movies Movies 3D Movies 4K TV Shows TV Shows 3D TV Shows 4K

My [directories] section is set to the following. Note that the Docker Image for Plex and plex-credits-detect are using the same directory structure

[directories]
/data/movies_1 = /data/movies_1
/data/tv_1 = /data/tv_1
/data/movies_2 = /data/movies_2
/data/tv_2 = /data/tv_2
/data/movies_3d = /data/movies_3d
/data/tv_3d = /data/tv_3d
/data/movies_4K = /data/movies_4K
/data/tv_4k = /data/tv_4k

I've attempted to repair the Plex DB using the instructions at https://support.plex.tv/articles/repair-a-corrupted-database/ No database corruption was detected in the process, I've performed all the steps outlined except the "Low-level database recovery" since I was not seeing an issue.

Plex is also setup with the plex-meta-manager docker image from linuxserver/plex-meta-manager, which may affect the DB structure.

cjmanca commented 2 years ago

Interesting, that's a line checking if a library root directory is available. In both my actual and my test DB, the column is always 0 or 1 (true or false). If you're getting a cast error, then your column is something else.

Could you run this sql command on your plex DB and tell me the output?

SELECT available FROM section_locations where available is null or (available != true and available != false);

andreaalloway commented 2 years ago

Looks like I had a Photo library pointed to a dead location

sqlite> SELECT available FROM section_locations where available is null or (available != true and available != false);
<Returned blank line>

Querying the whole table revealed a Photo library that was pointing to a dead location

sqlite> SELECT * from section_locations;
8|5|/disk2/home/pictures||2022-04-16 13:38:37|2017-05-22 22:48:33|2022-08-07 04:24:44
18|1|/data/movies_1|1|2022-08-07 04:24:15|2022-04-16 20:58:03|2022-08-07 04:24:15
19|1|/data/movies_2|1|2022-08-07 04:24:16|2022-04-16 20:58:03|2022-08-07 04:24:16
20|6|/data/movies_3d|1|2022-08-07 04:24:26|2022-04-16 20:59:20|2022-08-07 04:24:26
21|7|/data/movies_4K|1|2022-08-07 04:24:35|2022-04-16 20:59:45|2022-08-07 04:24:35
22|2|/data/tv_1|1|2022-08-07 04:24:53|2022-04-16 21:01:22|2022-08-07 04:24:53
23|2|/data/tv_2|1|2022-08-07 04:24:58|2022-04-16 21:01:22|2022-08-07 04:24:58
24|8|/data/tv_3d|1|2022-08-07 04:25:08|2022-04-16 21:01:37|2022-08-07 04:25:08
25|9|/data/tv_4k|1|2022-08-07 04:25:17|2022-04-16 21:01:52|2022-08-07 04:25:17

Removing the dead library has fixed the issue

cjmanca commented 2 years ago

Looks like the value the available column was set to was a blank string. I'll put some thought into how to deal with that now that I know it's a possibility