((solved))makemkv script that automates certain tasks

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Post Reply
motoryzen
Level 10
Level 10
Posts: 3497
Joined: Sun Dec 08, 2019 12:25 am

((solved))makemkv script that automates certain tasks

Post by motoryzen »

If i cannot achieve full automation in one or a combination of two scripts...that's ok ..Just want to see how close I can get.

flathub version of makemkv here that I use to digitize my personal movie collection and here is what I have so far... ( xdotool is awesome ;) )
I always start with either physically pushing the eject button on my LG bluray burner, or clicking my custom made gui button that has the command eject -T /dev/sr0 in it.. then insert the bluray movie, then launch the bash script below to get the ball rolling..

Here is what happens when I run the makemkv flatpak application via terminal ( obviously my hopes were to see specific messages that would give me an indication as to when /how to go about adding applicable next commands in the script to automate what I need to automate

command to run it = /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=makemkv com.makemkv.MakeMKV
results in terminal ....

Code: Select all

Gtk-Message: 17:36:02.054: Failed to load module "xapp-gtk3-module"
Qt: Session management error: Could not open network socket
info string reallocated, size=538
info string reallocated, size=562
info string reallocated, size=769
info string reallocated, size=565
info string reallocated, size=565
info string reallocated, size=589
info string reallocated, size=565

== If a movie has no problem being done with the basic quick 1st scan part...usually between 12 and 17 seconds to then reach the next part where you have the big button in the middle that more thoroughly " reads" the movie to acquire all titles per whatever Settings rules one sets. ( for me..it is to ignore all titles below 999 seconds of run time)

Code: Select all

#!/bin/bash
/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=makemkv com.makemkv.MakeMKV
eject -T /dev/sr0
xdotool sleep 20 key Tab sleep 0.5 key Return
xdotool sleep 20 mousemove 150 1350 sleep 0.2 click 3 sleep 0.2 key u
##  command or commands involved in auto sense when the task of ripping/attempting to rip is finished pops up..then

xdotool sleep 0.25 key Return
xdotool sleep 0.33 mousemove 265 1175 sleep 0.2 click 1
sleep 1 && pkill makemkv
So ...the xdotool mousemove command moves the mouse on my screen to the precise point and click 3 sleep 0.2 key u right clicks and UNselects all titles, then I have to take it manually from there. ( which isn't a big deal because I always hand type custom movie names and sometimes change the output directory/path too )

***but***
I'd love to know how to add the applicable content that tells the system to search literally every 15 or so seconds for when the message of " failed blah blah " or " success blah blah " in makemkv's gui pop up when it's done trying to rip the movie.... upon either of those messages....it auto executes that eject -T /dev/sr0 OR sometimes I noticed when I do that manually myself via that eject command.nothing happens and it's as have makemkv has taken over ejecting functions of the drive.... so... xdotool mousemove ### #### sleep 0.2 click 1 to the rescue....

be it the eject -T command or the mousemove click 1 deal... I want to it automate the last part I just explained + do the bashscript part I mentioned above all in one script if possible.

I have a feeling the content involves something about " While " and " If " statements or variables...etc etc...But unsure how to wrap my brain around it yet.



So..
Last edited by motoryzen on Sun Mar 03, 2024 8:38 pm, edited 1 time in total.
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
User avatar
axrusar
Level 7
Level 7
Posts: 1515
Joined: Sat Jan 30, 2021 5:30 pm

Re: makemkv script that automates certain tasks

Post by axrusar »

Not my coding here. But seems like a good starting point to save time writing the functions, loops and playing with the commands. Tweak accordingly:

Code: Select all

#!/bin/bash

# Function to check for specific message in MakeMKV GUI
check_for_message() {
    # Run xdotool to focus on MakeMKV window and copy text from it
    xdotool search --name "MakeMKV" windowactivate --sync
    xdotool key ctrl+a
    xdotool key ctrl+c

    # Check if the copied text contains the specified message
    copied_text=$(xclip -o)
    if echo "$copied_text" | grep -q "failed blah blah"; then
        # Execute action for failure message (e.g., eject DVD drive)
        eject -T /dev/sr0
    elif echo "$copied_text" | grep -q "success blah blah"; then
        # Execute action for success message (e.g., proceed with further processing)
        echo "Ripping process successful"
    fi
}

# Run MakeMKV
/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=makemkv com.makemkv.MakeMKV &

# Wait for MakeMKV to start up
sleep 10

# Main loop to monitor MakeMKV GUI for messages
while true; do
    # Check for specific message
    check_for_message

    # Wait for 15 seconds before checking again
    sleep 15
done

Linux Mint Una Cinnamon 20.3 Kernel: 5.15.x | Quad Core I7 4.2Ghz | 24GB Ram | 1TB NVMe | Intel Graphics
Image
motoryzen
Level 10
Level 10
Posts: 3497
Joined: Sun Dec 08, 2019 12:25 am

Re: makemkv script that automates certain tasks

Post by motoryzen »

axrusar.. That Looks exactly like one i'm looking for

I'll be home in less than four hours and we'll try it then and report back thanks.
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
motoryzen
Level 10
Level 10
Posts: 3497
Joined: Sun Dec 08, 2019 12:25 am

Re: makemkv script that automates certain tasks

Post by motoryzen »

Well I am slowly but surely getting closer to my goal.

Code: Select all

#!/bin/bash

# Function to check for specific message in MakeMKV GUI
check_for_message() {
    # Run xdotool to focus on MakeMKV window and copy text from it
    xdotool search --name "MakeMKV BETA popup" windowactivate --sync
    xdotool key ctrl+a
    xdotool key ctrl+c
    
    # Check if the copied text contains the specified message
    copied_text=$(xclip -o)
    if echo "$copied_text" | grep -q "Copy complete. 1 titles saved."; then
        # Execute action for failure message (e.g., eject DVD drive)
	xdotool sleep 0.75 mousemove 1065 1600 sleep 0.2 click 1 sleep 0.25 mousemove 265 1175 sleep 0.2 click 1 & pkill makemkv.sh & eject -T /dev/sr0
    elif echo "$copied_text" | grep -q "Copy complete. 0 titles saved, 1 failed."; then
        # Execute action for success message (e.g., proceed with further processing)
        echo "Victory"
        xdotool sleep 0.75 mousemove 1065 1600 sleep 0.2 click 1 sleep 0.25 mousemove 265 1175 sleep 0.2 click 1 & pkill makemkv.sh & eject -T /dev/sr0
    fi
}

# Run MakeMKV
/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=makemkv com.makemkv.MakeMKV &
eject -T /dev/sr0
sleep 4.5
eject -T /dev/sr0 & 
xdotool search --name "MakeMKV BETA popup" windowactivate --sync
xdotool sleep 25 mousemove 475 1575 sleep 0.2 click 1 sleep 7 key Tab sleep 0.25 key Return
xdotool sleep 10 mousemove 400 1275 sleep 0.2 click 3 sleep 0.2 key u sleep 0.33 key Tab sleep 0.2 key Down sleep 0.25 key --repeat 4 Tab

# Wait for MakeMKV to start up
sleep 1.25

# Main loop to monitor MakeMKV GUI for messages
while true; do
    # Check for specific message
    check_for_message

    # Wait for 15 seconds before checking again
    sleep 15
done
This script will do everything ( of course aside from me manually selecting the correct video/movie " title" , then renaming it in the applicable field, ) ...except then... when the final popup of " Copy complete. 1 titles saved." appears...it does nothing EXCEPT it seems to " focus '' on that " MakeMKV BETA pop " title named pop up window..that contains text which it refuses to highlight and copy that text message of " Copy complete. 1 titles saved."

Yet..when I run the commands manually of

xdotool search --name "MakeMKV BETA popup" windowactivate --sync
then press n hold ctrl and press a to select all. THAT works..and so does the manual hand typing way of copying

So there is something wrong from .

the beginning of that bashscript...until ...

Code: Select all

copied_text=$(xclip -o)
    if echo "$copied_text" | grep -q "Copy complete. 1 titles saved."; then
        # Execute action for failure message (e.g., eject DVD drive)
	xdotool sleep 0.75 mousemove 1065 1600 sleep 0.2 click 1 sleep 0.25 mousemove 265 1175 sleep 0.2 click 1 & pkill makemkv.sh & eject -T /dev/sr0
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
User avatar
axrusar
Level 7
Level 7
Posts: 1515
Joined: Sat Jan 30, 2021 5:30 pm

Re: makemkv script that automates certain tasks

Post by axrusar »

I usually play and test things and scrips in VMs to help other members here.
In this case i do not have a DVD iso, not even a DVD drive to make one and try to replicate the issue in MakeMKV :? I checked the program but i do not see any other way to make the popups show up to experiment sorry.
Linux Mint Una Cinnamon 20.3 Kernel: 5.15.x | Quad Core I7 4.2Ghz | 24GB Ram | 1TB NVMe | Intel Graphics
Image
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: makemkv script that automates certain tasks

Post by Koentje »

Same here..
Image
motoryzen
Level 10
Level 10
Posts: 3497
Joined: Sun Dec 08, 2019 12:25 am

Re: makemkv script that automates certain tasks

Post by motoryzen »

Either way I'm grateful for the info/script. I'm still experimenting :)
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
User avatar
axrusar
Level 7
Level 7
Posts: 1515
Joined: Sat Jan 30, 2021 5:30 pm

Re: makemkv script that automates certain tasks

Post by axrusar »

If you print the variable in the terminal with:

Code: Select all

echo $copied_text
It shows empty?
What if you try making xdotool add an extra click somewhere in the popup to make sure it is on focus?
You can also make xdotool to click, hold and drag to make the selection before copying.

Try also using the --clearmodifiers to make sure there is nothing else interfering

Code: Select all

xdotool key --clearmodifiers ctrl+a
xdotool key --clearmodifiers ctrl+c
Linux Mint Una Cinnamon 20.3 Kernel: 5.15.x | Quad Core I7 4.2Ghz | 24GB Ram | 1TB NVMe | Intel Graphics
Image
motoryzen
Level 10
Level 10
Posts: 3497
Joined: Sun Dec 08, 2019 12:25 am

Re: makemkv script that automates certain tasks

Post by motoryzen »

It shows empty?
If you're asking if there is any popup messing showing the text in which is autohighlighted and copied..there is not, but I assume no reason to need that to happen.
What if you try making xdotool add an extra click somewhere in the popup to make sure it is on focus?
I've noticed when I manually ran the commands below..everything works as it should..

1. It focuses on that pop up window labeled precisely as " MakeMKV BETA popup" ,
2. It moves my mouse pointer to " Ok " button on that small pop up window and leftclicks it and then moves and clicks the eject button icon within Makemkv's main window.

1. xdotool search --name "MakeMKV BETA popup" windowactivate --sync
2. xdotool sleep 0.75 mousemove 1065 1600 sleep 0.2 click 1 sleep 0.25 mousemove 265 1175 sleep 0.2 click 1

But running those exact commands in the correct places in the script...( aka launching makemkv via that exact script with my edits above with 1. and 2. in both spots of- or moreover ...under ...
# Check if the copied text contains the specified message
copied_text=$(xclip -o)
if echo "$copied_text" | grep -q "Copy complete. 1 titles saved."; then
# Execute action for failure message (e.g., eject DVD drive)
and
# Check if the copied text contains the specified message
copied_text=$(xclip -o)
if echo "$copied_text" | grep -q "Copy complete. 1 titles saved."; then
# Execute action for failure message (e.g., eject DVD drive)
..... ... It doesn't do anything when the success or failure messages pop up.

I'll try the clear modifiers next and report back soon.


)
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
User avatar
axrusar
Level 7
Level 7
Posts: 1515
Joined: Sat Jan 30, 2021 5:30 pm

Re: makemkv script that automates certain tasks

Post by axrusar »

Do you have xclip installed? not installed in mint by default i see..
Linux Mint Una Cinnamon 20.3 Kernel: 5.15.x | Quad Core I7 4.2Ghz | 24GB Ram | 1TB NVMe | Intel Graphics
Image
User avatar
axrusar
Level 7
Level 7
Posts: 1515
Joined: Sat Jan 30, 2021 5:30 pm

Re: makemkv script that automates certain tasks

Post by axrusar »

I am testing a little script with just the grep part in the xclip section and i see is going nowhere..
But then looking at your actions in the IF statement, you are using the same

Code: Select all

xdotool sleep 0.75 mousemove 1065 1600 sleep 0.2 click 1 sleep 0.25 mousemove 265 1175 sleep 0.2 click 1 & pkill makemkv.sh & eject -T /dev/sr0
action. so whatever message pops is irrelevant right?
In that case, why not forget about copying the text and just executing the action when the "MakeMKV BETA popup" pops?
Linux Mint Una Cinnamon 20.3 Kernel: 5.15.x | Quad Core I7 4.2Ghz | 24GB Ram | 1TB NVMe | Intel Graphics
Image
motoryzen
Level 10
Level 10
Posts: 3497
Joined: Sun Dec 08, 2019 12:25 am

Re: makemkv script that automates certain tasks

Post by motoryzen »

In that case, why not forget about copying the text and just executing the action when the "MakeMKV BETA popup" pops?
Oh that's all good to me :).

So the only real task I have left is figuring out how to word the script so that it or the system knows when that Pop up window pops up. and then executes the command below to click " ok " on that pop up window, then auto clicks on eject Makemkv gui button and then ends the program aka kills it.

xdotool sleep 0.75 mousemove 1065 1600 sleep 0.2 click 1 sleep 0.25 mousemove 265 1175 sleep 0.2 click 1 & pkill makemkv.sh & eject -T /dev/sr0
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
motoryzen
Level 10
Level 10
Posts: 3497
Joined: Sun Dec 08, 2019 12:25 am

Re: makemkv script that automates certain tasks

Post by motoryzen »

In that case, why not forget about copying the text and just executing the action when the "MakeMKV BETA popup" pops?
Oh that's all good to me :).

So the only real task I have left is figuring out how to word the script so that it or the system knows when that Pop up window pops up. and then executes the command below to click " ok " on that pop up window, then auto clicks on eject Makemkv gui button and then ends the program aka kills it.

Code: Select all

xdotool sleep 0.75 mousemove 1065 1600 sleep 0.2 click 1 sleep 0.25 mousemove 265 1175 sleep 0.2 click 1 & pkill makemkv.sh & eject -T /dev/sr0
Sorry.not sure why my message got posted twice (Shrugs)
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
motoryzen
Level 10
Level 10
Posts: 3497
Joined: Sun Dec 08, 2019 12:25 am

Re: makemkv script that automates certain tasks

Post by motoryzen »

*Does quagmire victory dance from Family Guy show*

:mrgreen:
The bashscript below does precisely..and only the folllowing while still allowing me infinite time to type in a different name of the movie " title " and will only execute the next stops once I click to begin the ripping process..

1. Launches makemkv
2. Waits 18 seconds for big button to show for to execute " skim-read" process, then moves the mouse & clicks it

3. Waits another 25 seconds to skim-read for any and all titles longer than 999 seconds ( my makemkv settings), ...then moves mouse to right click on the top most title, right clicks, and key presses letter " u " to unselect all ( all the vast majority of movies I encounter have multiple titles and I end up having to do this anyways to eventually select only one title I want )
4. Auto presses Tab key 5 times, the Video/movie title naming field. Then I manually take over from there naming it, and then either shift Tab a couple of times and press enter/return OR moving mouse to click the button to begin ripping the movie.

5. The script from them on either starts..OR is already auto checking every 7 seconds for any pop up windows that are named " MAKEMKV BETA Popup" and regardless of the message of success or failure then clicks " ok " on that box, then moves the mouse and clicks eject button of the makemkv program...

6 Now it waits around 4.5 to 5 seconds from the split second the drive's tray is fully ejected giving me time to grab the disc, it auto closes, then kills the bashcript and makemkv program.

** Stewie Griffith accent **
... VICTORY IS MINE!! ...

Code: Select all

#!/bin/bash

# Run MakeMKV
/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=makemkv com.makemkv.MakeMKV &
eject -T /dev/sr0
sleep 4.75
eject -T /dev/sr0

# Now to click the big button to begin basic skim-reading process ( usually takes between 9 seconds to 18 seconds tops )
xdotool sleep 18 mousemove 560 1650 sleep 0.2 click 1

# Now to right click on the top title and Unselect all - most often movies have multiple titles of which only one is the one I want...
xdotool sleep 25 mousemove 150 1275 sleep 0.2 click 3 sleep 0.25 key u

# Now to tab over, press " Down" to selec the 1TB gopro ssd as the destination, then go to the Video title's naming field
xdotool sleep 0.5 key --repeat 5 Tab

# Periodically check for finished Makemkv success or failure ripping popup window
while true
do
	id=$(xdotool search --name "MakeMKV BETA popup")
	if [ "$id" ]; then
	   xdotool sleep 2 mousemove 1070 1625 sleep 0.2 click 1 sleep 0.25 mousemove 265 1175 sleep 0.2 click 1
	   xdotool sleep 2 mousemove 265 1175 sleep 0.2 click 1
	   sleep 6
	   eject -T /dev/sr0
	   pkill makemkv
	   fi
	sleep 7
done
Thanks everyone for your help :D
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
Post Reply

Return to “Scripts & Bash”