TechieGuy12 / PlexServerAutoUpdater

Automatically update Plex when running the Plex service.
MIT License
118 stars 10 forks source link

Will the updater wait for recordings to finish? #32

Closed Hossy closed 4 years ago

Hossy commented 5 years ago

Sorry for posting this as an "issue," but I didn't know if you had a forum/discord/etc to ask questions. I love that there's an option to wait until all streams are complete, but I'm wondering if that same option is watching for active recordings (DVR).

TechieGuy12 commented 5 years ago

That is a good question. I am not sure as I would have to find out more about the Plex API. I don't have a DVR myself, so I can't test if that is currently the case.

phantomtypist commented 5 years ago

@Hossy I have a SilicondDust tuner and I can test this in the next few days if you'd like, unless you already did?

Hossy commented 5 years ago

I haven't been able to test it yet, but if it didn't do this latest update, I might be able to test it tomorrow morning.

On Jun 12, 2019 at 10:09 PM, <Jason Kanaris notifications@github.com> wrote:

@Hossy https://github.com/Hossy I have a SilicondDust tuner and I can test this in the next few days if you'd like, unless you already did?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TechieGuy12/PlexServerAutoUpdater/issues/32?email_source=notifications&email_token=AANM5LVMUK5PA7D4KTJLM2DP2G263A5CNFSM4HOCDS5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXSMFHY#issuecomment-501531295, or mute the thread https://github.com/notifications/unsubscribe-auth/AANM5LUJ6CTRVUXSVHDWNDTP2G263ANCNFSM4HOCDS5A .

phantomtypist commented 5 years ago

I have just confirmed that the auto updater cannot tell if a show is being DVR'd and thus will not wait to perform the upgrade. What was interesting is that the auto updater will fail because it can't kill the Plex Media Server.exe processes while Plex is DVR'ing.

TechieGuy12 commented 5 years ago

Thanks for testing. I will see if there is another Plex request I can use to determine if a show is being DVR'd.

Hossy commented 5 years ago

I experienced a somewhat similar problem:

2019-06-13 07:06:12 Stopping Plex Media Server.exe processes.
2019-06-13 07:06:12 Message:
Access is denied

Inner Exception:

Stack Trace:
   at System.Diagnostics.Process.Kill()
   at TE.Plex.MediaServer.StopProcess(String processName)
   at TE.Plex.MediaServer.StopProcesses()
   at TE.Plex.MediaServer.Update()
   at TE.Plex.SilentUpdate.Run()

However, when I logged into the server about 10 minutes later, the Plex Media Server.exe process wasn't running, but all of it's would-be child processes were still there (two Plex Transcoder.exe and nine PlexScriptHost.exe). I also found the PlexService service (https://github.com/cjmurph/PmsService) was stopped, but looking in the Application event logs, it appears that the AutoUpdater stopped it as the PMSService logged a graceful shutdown even though AutoUpdater didn't log it was doing it.

Full log:

2019-06-13 07:05:43 Getting windows user.
2019-06-13 07:05:43 Checking if user is an administrator.
2019-06-13 07:05:43 Initializing the silent update.
2019-06-13 07:05:50 Getting the service user.
2019-06-13 07:05:50 The Plex service is installed. Let's get the user associated with the service.
2019-06-13 07:05:55 The Plex service user: DOMAIN.LOCAL\SVC_ACCOUNT.
2019-06-13 07:05:55 Get the local data folder for Plex.
2019-06-13 07:05:55 Plex local data folder: C:\Users\SVC_ACCOUNT\AppData\Local
2019-06-13 07:05:55 Verify the updates folder is specified.
2019-06-13 07:05:56 Getting ready to download the latest package.
2019-06-13 07:05:56 Checking for the latest version from Plex.
2019-06-13 07:05:56 The update channel is set for Plex Pass.
2019-06-13 07:05:58 Parsing the information from Plex.
2019-06-13 07:05:59 The file, C:\Users\SVC_ACCOUNT\AppData\Local\Plex Media Server\Updates\1.16.0.1220-147963d87\packages\PlexMediaServer-1.16.0.1220-147963d87-x86.exe, exists. Checking to see if the package is valid.
2019-06-13 07:06:05 Checking if the installation package is valid.
2019-06-13 07:06:05 The package is valid. The checksums match.
2019-06-13 07:06:05 Since the package is valid - not downloading again.
2019-06-13 07:06:06 Verify the updates folder, C:\Users\SVC_ACCOUNT\AppData\Local\Plex Media Server\Updates exists.
2019-06-13 07:06:06 Checking to see if updates folder exists.
2019-06-13 07:06:06 Getting the latest update folder.
2019-06-13 07:06:06 Checking for the latest Plex packages folder.
2019-06-13 07:06:06 Get the latest packages file.
2019-06-13 07:06:06 Latest packages file: C:\Users\SVC_ACCOUNT\AppData\Local\Plex Media Server\Updates\1.16.0.1220-147963d87\packages\PlexMediaServer-1.16.0.1220-147963d87-x86.exe
2019-06-13 07:06:08 Checking for server update.
2019-06-13 07:06:08 The server is not in use continuing to perform the update.
2019-06-13 07:06:08 Update is available
2019-06-13 07:06:12 Stopping the Plex Media Server processes.
2019-06-13 07:06:12 Stopping Plex Media Server.exe processes.
2019-06-13 07:06:12 Message:
Access is denied

Inner Exception:

Stack Trace:
   at System.Diagnostics.Process.Kill()
   at TE.Plex.MediaServer.StopProcess(String processName)
   at TE.Plex.MediaServer.StopProcesses()
   at TE.Plex.MediaServer.Update()
   at TE.Plex.SilentUpdate.Run()
phantomtypist commented 5 years ago

Yeah, same here.

phantomtypist commented 5 years ago

@TechieGuy12

I'm looking into this as well. There are two ways of going about this.

  1. Update Api.GetPlayCount() so it returns the play count (as is) in addition to the recording count.
  2. Add new method Api.GetRecordingCount() that returns the count of active recordings. In addition to this we'd also need to expose a new MediaServer.GetRecordingCount() and add calls to this in pertinent areas of both the SilentUpdate and MainForm classes.

I'm leaning towards number two if you want me to take a look at going down that road?

Hossy commented 5 years ago

I understand knowledge is power and option 2 definitely provides that granularity, but from a purpose-perspective, streaming and recording are equal blockers for the application whose goal is to shutdown Plex. Unless you plan on later providing CLI parameters that ignore streaming or recording from the equation, I think option 1 would satisfy the end goal. Just my $.02.

EDIT: If the CLI parameters are a possibility down the line, then overcoming this Access Denied message and having the ability to terminate Plex when the DVR is recording would still need to be worked out.

phantomtypist commented 5 years ago

In all honesty I'd prefer option two as it adheres to the single responsibility principle in computer programming terms (disclaimer: I'm a programmer.) Doing it this way opens things up and makes things flexible down the road, plus it's easier to figure out what method is doing what. GetPlayCount makes me thing it gets the count of things playing, which includes Live TV. Whereas I would not think, without looking, that it also returns a count including background DVR recording that is not actively playing.

And yes, separating concerns coding wise will make it easier to do things like being able to pass in a CLI parameter that says e.g. "hey, kill play processes and wait for recordings to finish".

phantomtypist commented 5 years ago

I found the API endpoint to get the status on recordings.

Issue a GET request to http://{server}/media/subscriptions/scheduled?X-Plex-Token={token} and you'll get back a MediaContainer object with a collection of MediaGrabOperation elements. We can calculate the count of active recordings by getting all MediaGrabOperations that have the status attribute set to inprogress.

Source of reference: https://forums.plex.tv/t/check-if-a-dvr-recording-is-in-progress-via-the-api/185736/3

EDIT: Just wanted to note that I ran a test in LINQPad and this is confirmed to work.

phantomtypist commented 5 years ago

@TechieGuy12 PR for this submitted. I'll deal with #35 after this.

phantomtypist commented 4 years ago

@TechieGuy12 should probably mark this one closed when you have a minute.

Hossy commented 4 years ago

I've been absent for a while. Thanks @phantomtypist for the fix! @TechieGuy12 when can we get a new build?

TechieGuy12 commented 4 years ago

I just published the beta release for the fix: https://github.com/TechieGuy12/PlexServerAutoUpdater/releases/tag/0.1.8.6-beta.3. Test it out to see if it works for you.

phantomtypist commented 4 years ago

Build deployed on my end. I don't think I'm going to have time to stand up a test server so I'll just have to wait for the next Plex update to drop on my production server.

I'll get started on the other logging features soon.