"Delete the current video" on MPC-BE Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
nolifeguy
Posts: 8
Joined: 20 Jan 2016, 09:01

"Delete the current video" on MPC-BE

Post by nolifeguy » 01 Feb 2019, 13:33

This code already works on MPC-HC but not on MPC-BE. Is it because BE has that software name and version added after the files full path name in the title bar? (because the code needs the full path name for it to work). Is there any work around?

Image


sources:
https://gist.github.com/XIDA/4475692
https://sourceforge.net/p/mpcbe/tickets/247/

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance force
#Persistent ;Script nicht beenden nach der Auto-Execution-Section

SetWorkingDir %A_ScriptDir%
SetTitleMatchMode, 2


;Menu, tray, NoStandard
Menu, tray, add  ; Creates a separator line.
Menu, tray, add, Reload  
Menu, tray, add, Exit


return

~delete::
IfWinActive, ahk_class MPC-BE
{
WinGetTitle, output
;MsgBox, %output%
Send, {PgDn}
Sleep 500
FileDelete, %output%
TrayTip, File Delete, %output%
}
return

Reload:
	Reload
return 

Exit:
	ExitApp
return

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: "Delete the current video" on MPC-BE  Topic is solved

Post by safetycar » 01 Feb 2019, 14:32

Currently since you aren't seeing a full path in the title, the script should be trying to find that file name at the working dir that you set as A_ScriptDir.

Look at MPC-BE settings and see if you can make it put the full video path in the title.

Once you have that you could do:

Code: Select all

WinGetTitle, output
output := RegExReplace(output, " - MPC-BE x64 - .*?$", "")

User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: "Delete the current video" on MPC-BE

Post by jeeswg » 01 Feb 2019, 14:52

- I'd probably use the RegExReplace approach.
- Alternatively, in MPC-HC you can get the path of the file from the registry. You might be able to do the same in MPC-BE.

Code: Select all

q:: ;media player classic - get path from registry
RegRead, vPath, HKEY_CURRENT_USER\Software\MPC-HC\MPC-HC\Recent File List, File1
MsgBox, % vPath
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

nolifeguy
Posts: 8
Joined: 20 Jan 2016, 09:01

Re: "Delete the current video" on MPC-BE

Post by nolifeguy » 02 Feb 2019, 09:02

safetycar wrote:
01 Feb 2019, 14:32
Currently since you aren't seeing a full path in the title, the script should be trying to find that file name at the working dir that you set as A_ScriptDir.

Look at MPC-BE settings and see if you can make it put the full video path in the title.

Once you have that you could do:

Code: Select all

WinGetTitle, output
output := RegExReplace(output, " - MPC-BE x64 - .*?$", "")
This forum never disappoints! Yes, i got the full video path from settings (same as MPC-HC) and applied your code and it worked!
Now i can move fully from mpc-hc to BE.
thank you very much.

Bubo_Bubo
Posts: 8
Joined: 03 Oct 2014, 01:47

Re: "Delete the current video" on MPC-BE

Post by Bubo_Bubo » 07 Feb 2019, 07:12

In MPC Home Cinema you may Post Message #24044 to recycle current file: PostMessage 0x0111, 24044, , , MPC_HC_CLASS_NAME. Unfortunately, this message is not available to BE :?

I use this method for home cinema (warning! AHK2.0):

Code: Select all

global MPC_CLASS := "ahk_class MediaPlayerClassicW"

mpcRecycleFile() {
	; ************** HOME CINEMA ******************
	PostMessage 0x0111, 24044, , , MPC_CLASS
	; *** Here a confirmation window appears, waiting for it... ***
	WinWait "Удалить файл ahk_class #32770", , 10 ; Replace window title according to your language
	if ErrorLevel
		return
	While WinExist("Удалить файл ahk_class #32770") {
		; Smash Yes button until it acts :-)
		ControlClick "Д&а", "Удалить файл ahk_class #32770"  ; Replace Yes button text according to your language
		sleep 200
	}
}
And this is for BE (thanks to safetycar):

Code: Select all

global MPC_CLASS := "ahk_class MPC-BE" 

mpcRecycleFile() {
	; ************** BE ***************************
	fname := WinGetTitle(MPC_CLASS) ; select "Full path" in window title in MPC options
	fname := RegExReplace(fname, " - MPC-BE x64 - .*?$", "")
	if !InStr(fname, "\") { ; A deletable file name must have a slash 
		; for example, c:\folder\file.mp3 or \\server\share\music.mp3
		TrayTip "File not found"
		return
	}
	PostMessage 0x0111, 890, , , MPC_CLASS ; stop
	PostMessage 0x0111, 922, , , MPC_CLASS ; next
	FileRecycle fname ; Recycling the file while next track is being played
	if ErrorLevel
		TrayTip "Recycling " fname " failed :(" ; Use your favorite notification technique 
}

nwgat
Posts: 1
Joined: 19 Mar 2021, 10:00

Re: "Delete the current video" on MPC-BE

Post by nwgat » 19 Mar 2021, 10:06

can you please post a working full example for mpc-be?
thanks
Bubo_Bubo wrote:
07 Feb 2019, 07:12
In MPC Home Cinema you may Post Message #24044 to recycle current file: PostMessage 0x0111, 24044, , , MPC_HC_CLASS_NAME. Unfortunately, this message is not available to BE :?

I use this method for home cinema (warning! AHK2.0):

Code: Select all

global MPC_CLASS := "ahk_class MediaPlayerClassicW"

mpcRecycleFile() {
	; ************** HOME CINEMA ******************
	PostMessage 0x0111, 24044, , , MPC_CLASS
	; *** Here a confirmation window appears, waiting for it... ***
	WinWait "Удалить файл ahk_class #32770", , 10 ; Replace window title according to your language
	if ErrorLevel
		return
	While WinExist("Удалить файл ahk_class #32770") {
		; Smash Yes button until it acts :-)
		ControlClick "Д&а", "Удалить файл ahk_class #32770"  ; Replace Yes button text according to your language
		sleep 200
	}
}
And this is for BE (thanks to safetycar):

Code: Select all

global MPC_CLASS := "ahk_class MPC-BE" 

mpcRecycleFile() {
	; ************** BE ***************************
	fname := WinGetTitle(MPC_CLASS) ; select "Full path" in window title in MPC options
	fname := RegExReplace(fname, " - MPC-BE x64 - .*?$", "")
	if !InStr(fname, "\") { ; A deletable file name must have a slash 
		; for example, c:\folder\file.mp3 or \\server\share\music.mp3
		TrayTip "File not found"
		return
	}
	PostMessage 0x0111, 890, , , MPC_CLASS ; stop
	PostMessage 0x0111, 922, , , MPC_CLASS ; next
	FileRecycle fname ; Recycling the file while next track is being played
	if ErrorLevel
		TrayTip "Recycling " fname " failed :(" ; Use your favorite notification technique 
}

Bubo_Bubo
Posts: 8
Joined: 03 Oct 2014, 01:47

Re: "Delete the current video" on MPC-BE

Post by Bubo_Bubo » 20 Mar 2021, 02:33

nwgat wrote:
19 Mar 2021, 10:06
working full example for mpc-be?
1. Set this in mpc settings:
Spoiler
2. Here is a full code for mpc be 64-bit. Press F8 to recycle the current file:

Code: Select all

; tested on AHK version 2.0-a123
global MPC_CLASS := "ahk_class MPC-BE" ;"ahk_class MediaPlayerClassicW"

#HotIf WinActive(MPC_CLASS)
F8:: mpcRecycleFile()

mpcRecycleFile() {
	; ****** for MPC-BE 64-bit version *******************
	fname := WinGetTitle(MPC_CLASS)
	fname := RegExReplace(fname, " - MPC-BE x64.*?$", "")
	if !InStr(fname, "\") {
		TrayTip "File not found"
		return
	}
	MpcMsg 890 ; stop
	MpcMsg 922 ; next
	try
		FileRecycle fname
	catch
		TrayTip "Recycling failed: " fname
}

MpcMsg(msg := 889) {
	; Send a msg to MPC window, i.e. 889 = Play/Pause
	PostMessage 0x0111, msg, , , MPC_CLASS
}
I am using AutoHotKey 2.0-a123. You may need to edit some statements (#HotIf) for your version.

gimel
Posts: 18
Joined: 15 Aug 2022, 17:31

Re: "Delete the current video" on MPC-BE

Post by gimel » 15 Aug 2022, 17:37

What would the code be on a 32-bit system?

I tried substituting x86 for 64 but I get a popup error after pressing F8 saying recycling failed.

Bubo_Bubo
Posts: 8
Joined: 03 Oct 2014, 01:47

Re: "Delete the current video" on MPC-BE

Post by Bubo_Bubo » 15 Aug 2022, 22:49

gimel wrote:
15 Aug 2022, 17:37
What would the code be on a 32-bit system?
image.png
image.png (4.93 KiB) Viewed 1946 times
Try replacing this line:

Code: Select all

	fname := RegExReplace(fname, " - MPC-BE x64.*?$", "")
to this:

Code: Select all

	fname := RegExReplace(fname, " - MPC-BE .*?$", "")
Don't forget to set «Title bar text» to «Full path» in settings.

gimel
Posts: 18
Joined: 15 Aug 2022, 17:31

Re: "Delete the current video" on MPC-BE

Post by gimel » 16 Aug 2022, 16:13

That did it - thank you so much.

Such a useful feature.

gimel
Posts: 18
Joined: 15 Aug 2022, 17:31

Re: "Delete the current video" on MPC-BE

Post by gimel » 19 Aug 2022, 19:44

Had time to try it out more frequently and often it deletes a file and moves onto playing the next, but other times after deleting a file successfully, a notification appears within MPC stating that the last file in the folder has been reached - regardless of where in the folder the next file is - and that's it.

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: "Delete the current video" on MPC-BE

Post by safetycar » 20 Aug 2022, 14:17

Try a sleep before recycling, so that the next file has time to start loading.

gimel
Posts: 18
Joined: 15 Aug 2022, 17:31

Re: "Delete the current video" on MPC-BE

Post by gimel » 20 Aug 2022, 15:56

I haven't a clue as to how to do this in an ahk V1 script let alone a V2 script - I tried.

In the meantime I found a v1 script that works well. I notice it has sleep. Would be nice though to eliminate
the yes/no confirmation dialog (how?) as It's easier to to restore the odd mistaken recycle than to frequently click yes or no.

Code: Select all

; enable options -> player -> title bar -> display full path to use this
#IfWinActive ahk_class MPC-BE
Delete::
  WinGetTitle, filePath                             ; filename
  file := RegExReplace(filePath, " - MPC-BE.*", "") ; remove junk

  Send, {Space}                                     ; pause
  MsgBox, 4388, , Do you want to delete %file%?
  IfMsgBox No
  {
    Send, {Space}                                   ; unpause
    Return
  }
  IfMsgBox Yes
  {
    Send, .                                         ; stop
    Sleep, 200
    Send, {PgDn}                                    ; go to next file in playlist/directory
    Sleep, 1000
    FileRecycle, %file%                             ; Move file to recycle bin
    Return
  }
#IfWinActive

BWs_AHK
Posts: 1
Joined: 07 Sep 2022, 19:51

Re: "Delete the current video" on MPC-BE

Post by BWs_AHK » 07 Sep 2022, 19:56

gimel wrote:
20 Aug 2022, 15:56
I haven't a clue as to how to do this in an ahk V1 script let alone a V2 script - I tried.

In the meantime I found a v1 script that works well. I notice it has sleep. Would be nice though to eliminate
the yes/no confirmation dialog (how?) as It's easier to to restore the odd mistaken recycle than to frequently click yes or no.

Code: Select all

; enable options -> player -> title bar -> display full path to use this
#IfWinActive ahk_class MPC-BE
Delete::
  WinGetTitle, filePath                             ; filename
  file := RegExReplace(filePath, " - MPC-BE.*", "") ; remove junk

  Send, {Space}                                     ; pause
  MsgBox, 4388, , Do you want to delete %file%?
  IfMsgBox No
  {
    Send, {Space}                                   ; unpause
    Return
  }
  IfMsgBox Yes
  {
    Send, .                                         ; stop
    Sleep, 200
    Send, {PgDn}                                    ; go to next file in playlist/directory
    Sleep, 1000
    FileRecycle, %file%                             ; Move file to recycle bin
    Return
  }
#IfWinActive
Great script! It work perfectly.
As for the confirmation, just simply remove the Msgbox.I have also reduce the sleep time since 1000 seems too long.

Code: Select all

; enable options -> player -> title bar -> display full path to use this
#IfWinActive ahk_class MPC-BE
Delete::
  WinGetTitle, filePath                             ; filename
  file := RegExReplace(filePath, " - MPC-BE.*", "") ; remove junk

  Send, .                                         ; stop
  Sleep, 100
  Send, {Down}                                    ; go to next file in playlist/directory
  Sleep, 100
  FileRecycle, %file%                             ; Move file to recycle bin
#IfWinActive

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: "Delete the current video" on MPC-BE

Post by safetycar » 08 Sep 2022, 08:58

Be careful with the return you removed, or the hotkey will keep going and execute things you don't want, if not now in the future.
I don't have that player currently at hand to check the rest.

gimel
Posts: 18
Joined: 15 Aug 2022, 17:31

Re: "Delete the current video" on MPC-BE

Post by gimel » 10 Mar 2023, 08:43

BWs_AHK wrote:
07 Sep 2022, 19:56
gimel wrote:
20 Aug 2022, 15:56


Great script! It work perfectly.
As for the confirmation, just simply remove the Msgbox.I have also reduce the sleep time since 1000 seems too long.

Code: Select all

; enable options -> player -> title bar -> display full path to use this
#IfWinActive ahk_class MPC-BE
Delete::
  WinGetTitle, filePath                             ; filename
  file := RegExReplace(filePath, " - MPC-BE.*", "") ; remove junk

  Send, .                                         ; stop
  Sleep, 100
  Send, {Down}                                    ; go to next file in playlist/directory
  Sleep, 100
  FileRecycle, %file%                             ; Move file to recycle bin
#IfWinActive
Thank you.

Apologies for the delayed response.

I changed Send, {Down} to Send, {PgDn} and now it works for me.

I hope more MPC-BE users come across these autohotkey scripts to delete videos from within MPC-BE.

They make a huge difference.


[Mod edit: Corrected quote tags that made the reply look like part of the quoted post.]

Post Reply

Return to “Ask for Help (v1)”