Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here You Go - Alternate Script (Autohotkey v2+) -- Press DEL (or SHIFT+DEL) to Delete Videos + Move #20

Open
amiga-500 opened this issue Mar 21, 2024 · 3 comments

Comments

@amiga-500
Copy link

amiga-500 commented Mar 21, 2024

Here is a a relatively better script than vlc-delete that I wrote using AutoHotkey (v2+) that not only works when VLC is in true full-screen mode, unlike vlc-delete, but this script also allows using multiple customizable hotkeys to do the following:

  1. Delete the video to recycle bin (default shortcut key: DEL)
  2. Delete the video permanently from disk (default shortcut key: SHIFT+DEL)
  3. Move the video file to an arbitrary location e.g. C:\ (default shortcut key: CTRL+Z)

I added a lot of code comments for your convenience. And, the default shortcut keys can be changed easily to whatever you want, as seen in the code below.

; Delete/Move a playing VLC video (via hotkeys) then jumps to the next video in the playlist.
; ------------------------------------------
; DEL       = Delete video to the recycle bin
; SHIFT+DEL = Permanently delete video of disk
; CTRL+Z    = Move video to arbitrary location
; ------------------------------------------

MOVE_ACTION_DIR := "C:\"
MEDIA_INFO_DIALOG_TITLE := "Current Media Information"
WAIT_FOR_MEDIA_INFO_DIALOG_SECS := 0.25
WAIT_FOR_MEDIA_INFO_DIALOG_RETRIES := 10
CLIPBOARD_WAIT_SECS := 1
WAIT_FOR_NEXT_VID_SECS := 0.10
WAIT_FOR_NEXT_VID_RETRIES := 10
GIVE_BACK_MOUSE_CONTROL_AFTER_SECS := 5

#Requires AutoHotkey >=2.0
#SingleInstance Force
#HotIf WinActive("ahk_class Qt5QWindowIcon")  ; only trigger the use of hotkeys if a VLC window is active

~Shift & Delete:: {  ; SHIFT+DEL = Permanently delete video off disk
    KeyWait "Delete", "Up"
    KeyWait "Shift", "Up"
    DoPermDelete()
    Return
}

~Delete:: {  ; DEL = Delete video to the recycle bin
    KeyWait "Delete", "Up"
    DoRecycleDelete()
    Return
}

~Ctrl & z:: {  ; CTRL+Z = Move video to arbitrary location
    KeyWait "Ctrl", "Up"
    KeyWait "z", "Up"
    DoMove(MOVE_ACTION_DIR)
    Return
}

DoAction(action) {
    BlockInput "MouseMove"  ; block user from using the mouse
    SetTimer AllowMouse, GIVE_BACK_MOUSE_CONTROL_AFTER_SECS * 1000  ; restore the mouse for the user at some point if something goes wrong
    vlcTitle := WinGetTitle("A") ; vlc should be the active window because it's the only way this line got called
    isFullScreen := false

    ; open the media information dialog

    Send "^i" ; CTRL+I is harcoded in vlc to open the media info dialog
    if !WinWait(MEDIA_INFO_DIALOG_TITLE, , WAIT_FOR_MEDIA_INFO_DIALOG_SECS) {
        ; cant find information window - vlc in fullscreen?
        ; attempt to leave fullscreen and retry opening information dialog
        Send "{ESC}" ; leave fullscreen
        Sleep 10
        Send "^i"
        isFullScreen := true ; user was indeed in fullscreen - remember so we can restore it later
        retry := 1
        while !WinWait(MEDIA_INFO_DIALOG_TITLE, , WAIT_FOR_MEDIA_INFO_DIALOG_SECS) {            
            retry++
            if retry == WAIT_FOR_MEDIA_INFO_DIALOG_RETRIES { ; something went wrong.
                Msgbox "Can't find Media Information dialog. Aborting!"
                Return
            }
            Send "^i"
        }
    }

    ; save the full path (as seen in the information dialog) of the video that is playing to the clipboard

    MouseGetPos &orgMouseX, &orgMouseY
    orgClipboardContent := ClipboardAll()
    WinActivate MEDIA_INFO_DIALOG_TITLE
    WinWaitActive MEDIA_INFO_DIALOG_TITLE
    WinGetPos , , &width, &height, MEDIA_INFO_DIALOG_TITLE
    fileLocationX := width/2
    fileLocationY := height-52    
    CoordMode "Mouse", "Window"
    MouseMove fileLocationX, fileLocationY, 1
    Click 3 ; selects the entire path
    Send "^c" ; copies the path to the clipboard
    CoordMode "Mouse", "Screen"
    MouseMove orgMouseX, orgMouseY, 1
    if !ClipWait(CLIPBOARD_WAIT_SECS) {
        WinClose MEDIA_INFO_DIALOG_TITLE
        WinWaitClose MEDIA_INFO_DIALOG_TITLE
        MsgBox "Can't delete/move file!  Problem finding file location nside Media Information dialog."
        Return
    }
    WinClose MEDIA_INFO_DIALOG_TITLE
    WinWaitClose MEDIA_INFO_DIALOG_TITLE

    ; if the user was originally in fullscreen this restore it now

    if isFullScreen {
        ; restore fullscreen if it was orginally set
        WinGetPos , , &width, &height, vlcTitle
        videoX := width/2
        videoY := height/2
        CoordMode "Mouse", "Window"
        MouseMove videoX, videoY, 1
        Click 2
        CoordMode "Mouse", "Screen"
        MouseMove orgMouseX, orgMouseY, 1
    }

    ; move to the next video -- so it can delete/move this video (because vlc locks the running video)

    Send "{PgDn Down}"
    retry := 1
    while WinGetTitle("A") == vlcTitle { ; wait for the next video to start playing
        Sleep WAIT_FOR_NEXT_VID_SECS * 1000 ; give it some more time to move to next video
        retry++
        if retry == WAIT_FOR_NEXT_VID_RETRIES { ; something went wrong.  no more videos? (we cant delete/move if its only 1 video)
            MsgBox "Didn't detect next video change. Only 1 video left?`nCan't delete/move this video."
            Return
        }
    }
    vlcTitle := WinGetTitle("A")

    ; perform action (delete/move the video now)

    BlockInput "MouseMoveOff"  ; allow the user to have control over the mouse now (in case the delete/move takes too long)
    try
        if action == "del_perm"
            FileDelete A_Clipboard
        else if action == "del_recycle" {
            ;WinActivate "ahk_class Shell_TrayWnd"
            ;WinWaitActive "ahk_class Shell_TrayWnd"
            FileRecycle A_Clipboard
        } else
            FileMove A_Clipboard, action
    catch as err
        MsgBox "Problem deleting/moving file:`n`n" A_Clipboard "`n`n(" err.What " - " err.Message ")"
    A_Clipboard := orgClipboardContent
    try
        WinActivate vlcTitle
    catch
        WinActivate "ahk_class Qt5QWindowIcon" ; strange, we can't find the player! ok just activate any vlc window blindly
}

DoPermDelete() {
    DoAction("del_perm")
}

DoRecycleDelete() {
    DoAction("del_recycle")
}

DoMove(path) {
    DoAction(path)
}

AllowMouse() {
    BlockInput "MouseMoveOff"
}
@amiga-500 amiga-500 changed the title Autohotkey v2 Script to ALLOW pressing "DEL" key to delete Videos Here You Go - Alternate Script (Autohotkey v2) -- Press "DEL" key to delete Videos Mar 21, 2024
@amiga-500 amiga-500 changed the title Here You Go - Alternate Script (Autohotkey v2) -- Press "DEL" key to delete Videos Here You Go - Alternate Script (Autohotkey v2) -- Press DEL (or SHIFT+DEL) to delete Videos Mar 21, 2024
@amiga-500 amiga-500 changed the title Here You Go - Alternate Script (Autohotkey v2) -- Press DEL (or SHIFT+DEL) to delete Videos Here You Go - Alternate Script (Autohotkey v2+) -- Press DEL (or SHIFT+DEL) to Delete Videos + Move Mar 22, 2024
@abramter
Copy link

abramter commented Jul 8, 2024

Awesome script but whenever I try and delete a file when I have a bunch of videos in my playlist, I get a error "Didn't detect next video change. Only 1 video left? Can't delete/move this video."
Anyway around this since I do have other videos in the playlist.

@fun29
Copy link

fun29 commented Jul 13, 2024

When you only install autohotkey v2 and put this script in the lua directory (vlc 3.0.18 Win10 64bit) it does not work.

Please add the non-default instruction in what we have to install and configure?

@surrim
Copy link
Owner

surrim commented Jul 24, 2024

Here is a a relatively better script than vlc-delete that I wrote using AutoHotkey (v2+) that not only works when VLC is in true full-screen mode, unlike vlc-delete, but this script also allows using multiple customizable hotkeys to do the following:

That script also looks interesting, but works independently from VLC plugins and needs AutoHotkey.

Anyway, if it works, please share feedback 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants