Sonarr version (exact version): 2.0.0.4951
OS: Windows 10 x64
Description of issue:
Hey Guys - First of all, thanks again for all the hard work that is done on Sonarr. What a fantastic application!
As I have a rather large library, scanning for Plex & Kodi take a long time. I’ve found that in Plex, even having the option to perform a “Partial” scan doesn’t really seem to be accurate. Therefore, I’m implementing custom scripts for both Plex and Kodi which upon a show’s download will automatically update their libraries with just that specific show series. I’m starting with Plex as it seems to be a bit easier and have already configured & tested this feature with Radarr without error.
I basically modified the PowerShell script I use for Radarr (found base script on their wiki) to use Sonarr variables and paths to come up with the below. When testing it by temporarily setting the variable “$sonarr_series_path” to a static path, it imported the new episode into Plex and analyzed it correctly, but also attempted to analyze 3 other random shows plus threw an error about the datasource.
Below is the script I’m using plus the echo received when testing using a static path to a series. I’ve already verified that all paths defined in variables are correct. Any suggestions for how to fix the analyzing of additional shows + error?
Script I’m Testing to Import Series From Sonarr Into Plex
## Import Sonarr Series Into Plex Library
# This script will add the series or episode to plex and scan the destination folder (it will not scan the entire library)
#
# Sonarr Configuration: In Settings / Connect, add a Custom Script with the program being "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe"
# and the Parameters being "-ExecutionPolicy Bypass "D:\Scripts\MediaScripts\SonarrPlexImport.ps1""
#
# Define Variables
# Original Variable commented out for testing
#$sonarr_series_path = $env:sonarr_series_path
# Static Path for Testing Script
$sonarr_series_path = "D:\Media\TV Shows\Outlaw Tech"
#PSQlite location
Import-Module "D:\Scripts\PowerShell Modules\PSSQLite\PSSQLite"
#set file locations
$logfile = "D:\Logs\Sonarr\sonarrpleximport.log"
$database = "E:\Plex Database\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db"
$plexscanner = "C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe"
#set your plex library ID
$libraryid = 4
#If you have multiple root folders and library IDs you can set them like so
#If ($sonarr_series_path -like '*Movies Release\*' ) { $libraryid = 19 }
#Scan the series folder
& "$plexscanner" --scan --refresh --section $libraryid --directory $sonarr_series_path
write-output """$plexscanner"" --scan --refresh --section $libraryid --directory $sonarr_series_path" | add-content $logfile
sleep 20
#Query the plex db for the item ID
$likeseriespath = $sonarr_series_path + "%"
$query = "SELECT mi.metadata_item_id FROM media_parts mp LEFT JOIN media_items mi on mp.media_item_id=mi.id WHERE mp.file LIKE '$likeseriespath'"
$itemid = Invoke-SqliteQuery -Query $query -DataSource $database
$itemid = $itemid.metadata_item_id
#Analyze the ItemID
& "$plexscanner" --analyze --item $itemid
write-output """$plexscanner"" --analyze --item $itemid" | add-content $logfile
sleep 20
#Analyze deeply the item ID
& "$plexscanner" --analyze-deeply --item $itemid
write-output """$plexscanner"" --analyze-deeply --item $itemid" | add-content $logfile
Echoed in Console When Testing
PS D:\- App Cache -\MediaScripts> .\SonarrPlexImport.ps1
GUI: Scanning Outlaw Tech
GUI: Scanning Outlaw Tech Season 1 Episode 1
GUI: Scanning Outlaw Tech Season 1 Episode 2
GUI: Scanning Outlaw Tech Season 1 Episode 3
GUI: Scanning Outlaw Tech Season 1 Episode 4
GUI: Scanning Outlaw Tech Season 1 Episode 5
GUI: Matching 'Child Genius Us'
GUI: Requesting metadata for 'Child Genius Us'
GUI: Matching 'I Believe In'
GUI: Requesting metadata for 'I Believe In'
GUI: Matching 'Masters of Time Independent Watchmakers'
GUI: Requesting metadata for 'Masters of Time Independent Watchmakers'
GUI: Matching 'National Geographic Chasing Ufos'
GUI: Requesting metadata for 'National Geographic Chasing Ufos'
GUI: Requesting metadata for 'Outlaw Tech'
GUI: Background media analysis on Outlaw Tech S01 E05
GUI:
New-Object : Exception calling ".ctor" with "1" argument(s): "Unable to load DLL 'SQLite.Interop.dll': The specified
module could not be found. (Exception from HRESULT: 0x8007007E)"
At D:\Scripts\PowerShell Modules\PSSQLite\PSSQLite\Invoke-SqliteQuery.ps1:411 char:25
+ ... $conn = New-Object System.Data.SQLite.SQLiteConnection -ArgumentL ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
The property 'ParseViaFramework' cannot be found on this object. Verify that the property exists and can be set.
At D:\- App Cache -\PowerShell Modules\PSSQLite\PSSQLite\Invoke-SqliteQuery.ps1:412 char:17
+ $conn.ParseViaFramework = $true #Allow UNC paths, tha ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Invoke-SqliteQuery : You cannot call a method on a null-valued expression.
At D:\- App Cache -\MediaScripts\SonarrPlexImport.ps1:26 char:11
+ $itemid = Invoke-SqliteQuery -Query $query -DataSource $database
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-SqliteQuery
Error: the required argument for option '--item' is missing.
Plex Media Scanner (c) 2010-2014 Plex Development Team.
-h, --help Display this message.
-v, --verbose Show more output.
-p, --progress Show special progress output.
--log-file-suffix Specify suffix for log file.
Actions:
-r, --refresh Refresh the metadata.
-a, --analyze Analyze media information.
--analyze-deeply Fully read and perform deep media analysis.
-b, --index Generate a media index file.
-s, --scan Scan for new media.
-i, --info Get information.
-l, --list List.
-g, --generate Regenerate thumbnails/fanart.
-t, --tree Show a section tree.
-w, --reset Delete all media out of a section.
-n, --add-section <name> --type <type:1,2,8> --agent <identifier> --location <path> --lang <code> Add a new section.
-D, --del-section Delete a section.
Items to which actions apply:
-c, --section A library section ID.
-o, --item An item ID.
-d, --directory A directory path.
-f, --file A file.
Modifiers to actions:
-x, --force Force an operation (e.g. refresh).
--no-thumbs Do not regenerate thumbs when analyzing.
--chapter-thumbs-only Only generate chapter thumbnails during generate pass
--thumbOffset <percent> Percent offset into video for thumbnail image generated during media analysis.
--artOffset <percent> Percent offset into video for fanart image generated during media analysis.
Error: the required argument for option '--item' is missing.
Plex Media Scanner (c) 2010-2014 Plex Development Team.
-h, --help Display this message.
-v, --verbose Show more output.
-p, --progress Show special progress output.
--log-file-suffix Specify suffix for log file.
Actions:
-r, --refresh Refresh the metadata.
-a, --analyze Analyze media information.
--analyze-deeply Fully read and perform deep media analysis.
-b, --index Generate a media index file.
-s, --scan Scan for new media.
-i, --info Get information.
-l, --list List.
-g, --generate Regenerate thumbnails/fanart.
-t, --tree Show a section tree.
-w, --reset Delete all media out of a section.
-n, --add-section <name> --type <type:1,2,8> --agent <identifier> --location <path> --lang <code> Add a new section.
-D, --del-section Delete a section.
Items to which actions apply:
-c, --section A library section ID.
-o, --item An item ID.
-d, --directory A directory path.
-f, --file A file.
Modifiers to actions:
-x, --force Force an operation (e.g. refresh).
--no-thumbs Do not regenerate thumbs when analyzing.
--chapter-thumbs-only Only generate chapter thumbnails during generate pass
--thumbOffset <percent> Percent offset into video for thumbnail image generated during media analysis.
--artOffset <percent> Percent offset into video for fanart image generated during media analysis.
Again, the same script with slightly different variables, paths, and library ID worked flawlessly for Radarr.
Any suggestions?