kmahon37 / plex-dvr-waker

Plex DVR Waker is a simple command-line tool for waking the computer before the next scheduled recording.
MIT License
8 stars 0 forks source link

[BUG] An item with the same key has already been added #1

Closed peterfarrant closed 4 years ago

peterfarrant commented 4 years ago

Hi - this is probably me rather than a bug - I suspect it is caused by the fact I have Plex installed on Drive D rather than my small OS drive C

I installed and ran the add-task command and not a lot happened. Had a look and then added the --plexdata to point to my non default Plex App Data location This seemed to be OK

D:\PlexDvrWaker>dotnet PlexDvrWaker.dll add-task --sync --plexdata=D:\PlexAppData --verbose
2019-09-28T15:20:12     Creating/updating DVR sync task: Plex DVR Waker\DVR sync
2019-09-28T15:20:12     DVR sync task scheduled for every 15 minutes
DVR sync task scheduled for every 15 minutes

I then tried to list the scheduled recordings andf it wasn't happy!

D:\PlexDvrWaker>dotnet PlexDvrWaker.dll list

Unhandled Exception: System.IO.FileNotFoundException: Unable to find the Plex library database file.
   at PlexDvrWaker.Plex.DataAdapter..ctor(String plexDataPath) in C:\Users\Kris\Documents\Code\GitHub\plex-dvr-waker\Plex\DataAdapter.cs:line 34
   at PlexDvrWaker.Program.RunList(ListOptions options) in C:\Users\Kris\Documents\Code\GitHub\plex-dvr-waker\Program.cs:line 98
   at PlexDvrWaker.Program.Main(String[] args) in C:\Users\Kris\Documents\Code\GitHub\plex-dvr-waker\Program.cs:line 29

I added --plex location to the command and got the 'An item with the same key...' message

D:\PlexDvrWaker>dotnet PlexDvrWaker.dll list --plexdata=d:\PlexAppData

Unhandled Exception: System.ArgumentException: An item with the same key has already been added. Key: plex://show/5cffa2d21c9336001d998104
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at PlexDvrWaker.Plex.DataAdapter.LoadSubscriptions() in C:\Users\Kris\Documents\Code\GitHub\plex-dvr-waker\Plex\DataAdapter.cs:line 146
   at PlexDvrWaker.Plex.DataAdapter.GetScheduledRecordings() in C:\Users\Kris\Documents\Code\GitHub\plex-dvr-waker\Plex\DataAdapter.cs:line 55
   at PlexDvrWaker.Plex.DataAdapter.PrintScheduledRecordings() in C:\Users\Kris\Documents\Code\GitHub\plex-dvr-waker\Plex\DataAdapter.cs:line 82
   at PlexDvrWaker.Program.RunList(ListOptions options) in C:\Users\Kris\Documents\Code\GitHub\plex-dvr-waker\Program.cs:line 100
   at PlexDvrWaker.Program.Main(String[] args) in C:\Users\Kris\Documents\Code\GitHub\plex-dvr-waker\Program.cs:line 29

Any suggestions?

Desktop (please complete the following information):

kmahon37 commented 4 years ago

Looks like I need to handle the FileNotFoundException error better. It looks like I need to validate the path first thing (for all commands) so that it doesn't "appear to work".

Just a few days ago I found where Plex stores its settings in the Registry, and I am working on a fix where you won't have to pass in the "plex data path" anymore. Since you are not using the default location, can you verify that you have the following Windows registry setting and value? This should be the same value that is in the Plex UI settings under "Settings > General", then click the "Show Advanced" button".

[Computer\HKEY_CURRENT_USER\Software\Plex, Inc.\Plex Media Server]
"LocalAppDataPath"="d:\PlexAppData"

For the "item with same key" issue, I think it may be because you have duplicate shows/series in your recording schedule (that's just a guess). I have a solution in mind, but want to make sure I won't accidentally be excluding something.

kmahon37 commented 4 years ago

I think I've fixed both your issues. You will no longer need to supply the --plexdata argument because I am now loading the settings from the Windows registry.

Fixed in v1.1.0