This project has moved and is read-only. For the latest updates, please go here.

Plex DVR Wait until MCEBuddy Finishes Processing a File

Sep 16, 2016 at 4:13 AM
Is there a way, perhaps using MCEBuddy.UserCLI.exe, to wait until MCEBuddy finishes processing a file?

It looks as if Plex DVR added post-processing before it moves the file into the target library. However from what I can tell, this call to the post-processing step is synchronous like a batch file.

If I were to use --command=addfile, is there a way to wait for that specific file to be done processing? The most preferred way would be to have MCEBuddy.UserCLI.exe simply block until done, but if there was a way to call it to block until a file is complete, or to even poll for status until done, that would be okay too...

I would really prefer to use MCEBuddy rather than write a batch file around comskip and other tools...
Sep 16, 2016 at 5:04 AM
I just found this guide:
https://www.reddit.com/r/PleX/comments/52v7vd/guide_commercialfree_experience_with_plex_dvr/
Which has a link to a batch file which monitors the MCEBuddy queue length. This answers my question.
Sep 16, 2016 at 6:06 AM
You can also set a delay in the monitor task settings. See the pop up help for more details

Sep 16, 2016 at 12:56 PM
Edited Sep 16, 2016 at 1:01 PM
Ethrex wrote:
I just found this guide:
https://www.reddit.com/r/PleX/comments/52v7vd/guide_commercialfree_experience_with_plex_dvr/
Which has a link to a batch file which monitors the MCEBuddy queue length. This answers my question.
That's my guide/script :) It's not perfect though because the MCEBuddy queue needs to be empty. So if 4 new recordings are added at roughly the same time, you'll have to wait for MCEBuddy to finish all of them before Plex can start moving files.

I'd love to see a solution on a file to file basis with the UserCLI.exe. I thought about it but haven't found a better solution than using the MCEBuddy queue length.

rboy1 wrote:
You can also set a delay in the monitor task settings. See the pop up help for more details
I don't think you understood Ethrex's question right?
Sep 17, 2016 at 12:52 AM
The way I read, there appeared to be a typo in the first line:
"Is there a way, perhaps using MCEBuddy.UserCLI.exe, to wait until MCEBuddy finishes processing a file?"

should read as

"Is there a way, perhaps using MCEBuddy.UserCLI.exe, to wait until Plex finishes processing a file? "

MCEbuddy waiting for CLI didn't make sense.

Keeping this in mind, I responded that MCEbuddy can wait until plex finishes processing the file by putting a delay in the monitor task (not through the CLI). You can setup MCEbuddy to monitor the folder. Now that isn't an option then delaying through the CLI is something that isn't possible in the current architecture

Sep 17, 2016 at 1:43 AM
Edited Sep 17, 2016 at 1:47 AM
There was no typo.
I suggest reading this Guide, part 3 to learn about the Plex postprocessing option:
https://www.reddit.com/r/PleX/comments/52v7vd/guide_commercialfree_experience_with_plex_dvr/

The script I wrote uses MCEBuddy.UserCLI to start/stop the engine and to check whether or not the MCEBuddy queue is empty.
What we want to know is if it's possible via MCEBuddy.UserCLI to add a specific file and check whether this particular job has finished processing.
Sep 17, 2016 at 2:17 AM
Hmm okay thanks for pointing that out. I went over it again, I didn't quite understand why you would want MCEbuddy to finish processing one file before proceeding to the next? the CLI just adds it to the queue and when one is done it'll proceed to the next. CLI waiting for the current queue to finish and then adding the next one, didn't understand the objective of that?

Sep 17, 2016 at 3:05 AM
Edited Sep 17, 2016 at 3:06 AM
So when Plex finishes a DVR recording, the script is called. The script then starts the MCEBuddy engine and starts the scan process. After the queue is empty again, the script terminates and Plex recognizes that and starts moving the file. Great.

The "issue" exists when multiple recordings are finishing at the same time. Plex then calls multiple instances of the script. Even when one task/conversion finishes before the other (let's say four files were added, two finish first because concurrent conversions set to two) all four scripts wait for the queue to be empty, even though 2 conversions are already finished. So Plex can only start moving the files when the four scripts all terminate at the same time, so when all four conversions are done (queue empty).

That's why it would be nice to program the script to be not dependend on the queue length but on the conversion status of the added file.
Sep 17, 2016 at 11:10 PM
So if I'm understanding this correctly you want a way to query to status of the conversion jobs within the queue so each task can track it's own job. Is that correct?
That should be doable so the question is what information do you want returned? Would you like to query based on job number or filename?

Sep 17, 2016 at 11:21 PM
Edited Sep 17, 2016 at 11:23 PM
rboy1 wrote:
So if I'm understanding this correctly you want a way to query to status of the conversion jobs within the queue so each task can track it's own job. Is that correct?
Yes, I think you got it.
rboy1 wrote:
That should be doable so the question is what information do you want returned? Would you like to query based on job number or filename?
Job number wouldn't make sense because when one job gets finished, the others would move one up.

Ideally would be if I can say: MCEBuddy.UserCLI.exe --command=query --action=checkstatus <insert full path of file> and it returns something like 1 for in progress and 0 for has finished.

Speaking of what should be returned. Why does "--action=queuelength" return like 6 whole unnecessary sentences? I had to do a workaround because of that, put the sentences in a output.txt and then scan the output.txt for "INFORMATION> Number of items in queue = 0 ". Why doesn't it return just a number like 0?
Sep 17, 2016 at 11:48 PM
hmm okay we'll put an option for a `verbose=off` operation where it'll return just one line for the query or action

Sep 18, 2016 at 12:11 AM
Edited Sep 18, 2016 at 12:11 AM
rboy1 wrote:
hmm okay we'll put an option for a verbose=off operation where it'll return just one line for the query or action
That would be awesome, thanks! Ideally only one number (if possible depending on the command).
Will you add --action=checkstatus <insert full path of file> or similar too?
Sep 18, 2016 at 1:02 AM
Yes actually we're adding --quiet which will return the status of the query, it could be a number or status but basically no extra words or headers/footers. It will return -2 if there was an error. (the program still returns 0, -1 and -2 but this is text we are talking about). Also adding an option to get the job status, that's a little more complex but we'll figure it out.
It will likely return something like queued, converting or not present

The thing with not present is that because we're looking at queue, we can't tell from the queue was completed successfully or not, all we can tell if the job in the queue or not, hence not present would could indicate the job wasn't added, failed or converted

Sep 18, 2016 at 1:09 AM
rboy1 wrote:
Also adding an option to get the job status, that's a little more complex but we'll figure it out. It will likely return something like queued, converting or not present The thing with not present is that because we're looking at queue, we can't tell from the queue was completed successfully or not, all we can tell if the job in the queue or not, hence not present would could indicate the job wasn't added, failed or converted
I already thought this will be the case, this is not an issue. With the current queue length implementation the script can't tell Plex whether or not the conversion failed as well.
Thanks for the fast support and I look forward to version 2.4.6.
Sep 18, 2016 at 2:20 AM
Done in today's build, two new options
1. --quiet
2. --command=jobstatus --action="<filename>"

Sep 18, 2016 at 2:26 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Sep 18, 2016 at 2:37 AM
Edited Sep 18, 2016 at 2:41 AM
rboy1 wrote:
Done in today's build, two new options 1. --quiet 2. --command=jobstatus --action="<filename>"
I'll try it tomorrow, but can you clarify anyway:

Is it --action="<path of file>" or --action="<Filename>"?
So as an example --action="C:\YY\YY.mkv" or --action="YY.mkv"?

Plex passes on the full path of the recording, not the filename alone. So the second one "YY.mkv" will be much harder to implement (splitting the variable after the last "\", don't know if this is even possible).
Sep 18, 2016 at 3:12 AM
Full path of file, you can see the help command for an example

Sep 18, 2016 at 4:30 AM
Ah I wish I got back into this conversation earlier. I think the best flexibility for scripters would be to simply specify a command to MCEBuddy which it would cause MCEBuddy to execute the command with "cmd /C" after processing the requested file. Therefore it makes MCEBuddy agnostic to any external implementation moving forward. For example, I would pass it:

--onfinished="waitfor /SI my_unique_signal"

Therefore I would be causing MCEBuddy to fire a signal on my local machine, and my calling batch file would be waiting for the signal:

waitfor my_unique_signal

waitfor is documented at: https://technet.microsoft.com/en-us/library/ms188253.aspx

Or I could simply have it call another batch file:

--onfinished="custom_post_processing.cmd argument1"

The beauty of this approach is that the calling back file doesn't need to do any polling gymnastics to synchronize with MCEBuddy, and MCEBuddy doesn't need to implement any crazy commands to handle all these custom command line scenarios...

Thanks
Sep 18, 2016 at 4:34 AM
Oops looks like I got a link to the wrong waitfor. here is the right one:
https://technet.microsoft.com/en-us/library/cc731613.aspx
Sep 18, 2016 at 1:37 PM
So why do you think you can't do this using PostCustomCommand in your profile?

Sep 18, 2016 at 3:43 PM
Edited Sep 18, 2016 at 3:46 PM
How would you solve this with a PostCustomCommand? I guess you could combine the %sourcefile% with a number. But it has to be unique for each file (hence %sourcefile%) otherwise all running scripts would terminate at the same time.

I "solved" it by using a loop in the script which checks every 2 seconds whether the conversion has been finished. So I'm not editing the profiles.conf.
:loop
for /f "delims=" %%o in ('C:\Progra~1\MCEBuddy2x\MCEBuddy.UserCLI.exe --command=jobstatus --action=%1 --quiet') do set status=%%o
if %status% == "not present" (
    Exit
) else (
    timeout /t 2 /nobreak > NUL
    goto loop
)
Marked as answer by rboy1 on 9/18/2016 at 8:04 AM
Sep 18, 2016 at 4:06 PM
If you can post your customcommand in the profile, I'll put it up on the MCEBuddy Server under SHARED_INFORMATION for folks
Sep 18, 2016 at 4:23 PM
Edited Sep 18, 2016 at 4:29 PM
As I said I don't use any CustomCommands except of what I shared here: https://mcebuddy2x.codeplex.com/discussions/657921
Maybe Ethrex can up with something but my new Plex postprocessing script works fine (see here: https://www.reddit.com/r/PleX/comments/52v7vd/guide_commercialfree_experience_with_plex_dvr/ or direct link here: http://www85.zippyshare.com/v/U361XMja/file.html) so I don't need to add more lines in profiles.conf.
Sep 18, 2016 at 4:32 PM
Hi rboy1, maybe PostCustomCommand would work if it executed after the file is fully processed, but there is no way to specify it at the command line. I would need to pass unique arguments per add file request and those unique arguments need to follow the request to the end without being overwritten by parallel requests with their own unique arguments. Therefore writing it to the config is not an option.
Sep 18, 2016 at 4:36 PM
If you were truly motivated (as in a positive manner) to do a CustomCommand here's one option, from the script before invoking UserCLI to add the file to the MCEBuddy queue, write the unique parameter and filename into a text file. Then in your CustomCommand read that file, extract the unique param that corresponds to the source file and then use that to complete your stuff :)

Sep 19, 2016 at 3:52 AM
Hi Wiidesire,
Maybe Ethrex can up with something
Well the entire script you pasted above would be reduced to just:

waitfor my_unique_signal

But that's only if there was something like an --onfinished argument (or whatever it would be named) to the CLI so when you addfile you would also include:

MCEBuddy.UserCLI.exe --onfinished="waitfor /SI my_unique_signal"

Its just a way better approach then having to do poll-gymnastics.

Hi rboy1, I can see that working, but you have to admit, it feels like a big hack and a lot of work for scripters on something which should be easy. It feels like the solution should be clean and extensible for many different scenarios.