根据回链快速打开对应视频

发布于:2025-06-27 ⋅ 阅读:(17) ⋅ 点赞:(0)

根据回链快速打开对应视频

引言

之前生成了回链, 但是如果回链的打开依赖特定的视频位置, 所以我想反正视频名字是不变的, 所以利用everything来索引视频名字, 那么就可以不管视频在哪个位置了,都可以进行扫盘打开, 拥有笔记就可以了

实操方案

下载everything

下载 - voidtools

image-20250625161237115

双击安装即可

配置es.exe环境

(1)往下翻, 找到 ES-1.1.0.30.x64.zip

image-20250625161407754

(2)后面解压,放在特定的位置(必须这里, 脚本寻找这个地址, 不然要修改源码)

C:\Program Files\Everything

image-20250625161535874

(3)配置对应环境变量

image-20250625161630549

(4)配置对应的环境变量

image-20250625161902522

测试脚本

现在环境已经配置完成了, 我们提供打包可用文件, 后面附录给出源码, 方便自定义

蓝奏云链接:https://wwyz.lanzn.com/ivnzw2zj7myf

快捷键 Ctrl + Alt + U触发

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

; 配置文件路径
configFile := A_ScriptDir "\config.ini"

; 默认 es.exe 路径
DefaultEsPath := "C:\Program Files\Everything\es.exe"

; 全局变量:是否首次通过链接打开 PotPlayer
isFirstLink := true

; 快捷键 Ctrl + Alt + U
^!u::
{
    ; 检查配置文件是否存在
    if (!FileExist(configFile))
    {
        IniWrite, C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe, %configFile%, Paths, PotPlayer
        IniWrite, %DefaultEsPath%, %configFile%, Paths, Es
        ShowToolTip("检测到首次运行,请先设置 PotPlayer 播放器路径!", 5)
        Goto, Configure
    }

    ; 从配置文件读取 PotPlayer 和 es.exe 路径
    IniRead, potPlayerPath, %configFile%, Paths, PotPlayer
    IniRead, EsPath, %configFile%, Paths, Es, %DefaultEsPath%

    ; 检查 PotPlayer 路径是否有效
    if (!FileExist(potPlayerPath))
    {
        ShowToolTip("配置文件中的 PotPlayer 路径无效,请重新设置!", 5)
        Goto, Configure
    }

    ; 检查 es.exe 路径是否有效
    if (!FileExist(EsPath))
    {
        ShowToolTip("es.exe 路径无效,请检查配置文件中的路径!", 5)
        Return
    }

    ; 获取选中的文本
    ClipSaved := ClipboardAll
    Clipboard := ""
    Send ^c
    ClipWait, 1

    selectedText := Clipboard
    Clipboard := ClipSaved

    ; 检查选中文本是否为空
    if (selectedText = "")
    {
        ShowToolTip("未选中文本,请选中包含时间和路径的文本!", 5)
        Return
    }

    ; 判断选中的文本格式
    if (RegExMatch(selectedText, "^\[(\d{2}:\d{2}:\d{2}(?:\.\d+)?)\]-\[(.+)\]$", match))
    {
        seekTime := match1
        videoPath := match2

        if (SubStr(videoPath, 1, 4) = "http")
        {
            HandleLink(videoPath, seekTime, potPlayerPath)
        }
        else
        {
            HandleLocalPath(videoPath, seekTime, potPlayerPath, selectedText)
        }
    }
    else if (RegExMatch(selectedText, "^\[(\d{2}:\d{2}:\d{2}(?:\.\d+)?)\]$", timeMatch))
    {
        HandleTimeOnly(timeMatch1)
    }
    else if (RegExMatch(selectedText, "^https?://", match))
    {
        ShowToolTip("选中的文本是链接,使用默认浏览器打开。", 3)
        Run, %selectedText%
        Sleep, 3000
        Send, f
        ShowToolTip("已打开链接并发送 F 键以全屏。", 3)
    }
    else
    {
        ShowToolTip("选中的文本格式无效!", 5)
    }
}
Return

; 处理链接的函数 (未修改)
HandleLink(videoLink, seekTime, potPlayerPath)
{
    if (RegExMatch(videoLink, "t=(\d+(?:\.\d+)?)", tMatch))
    {
        seconds := tMatch1
        hours := Floor(seconds / 3600)
        minutes := Floor((seconds - (hours * 3600)) / 60)
        secs := seconds - (hours * 3600) - (minutes * 60)
        formattedTime := Format("{:02}:{:02}:{:04.1f}", hours, minutes, secs)
    }
    else
    {
        ShowToolTip("链接中未检测到时间参数 t=,无法提取时间!", 5)
        Return
    }

    if (RegExMatch(videoLink, "p=(\d+)", pMatch))
    {
        episode := pMatch1
    }
    else
    {
        ShowToolTip("链接中未检测到集数参数 p=,无法提取集数!", 5)
        Return
    }

    ShowToolTip("链接检测到时间参数: " . seconds . " 秒,集数参数: " . episode . ",转换为 " . formattedTime, 5)

    SetTitleMatchMode, 2
    if WinExist("ahk_class PotPlayer64")
    {
        ShowToolTip("检测到已打开的 PotPlayer 窗口。", 3)
        WinActivate
        Sleep, 200

        Clipboard := ""
        Send ^!p
        ShowToolTip("已发送 Ctrl + Alt + P,获取当前播放视频链接。", 3)
        Sleep, 500
        ClipWait, 1
        currentPlayingPath := Clipboard

        if (SubStr(currentPlayingPath, 1, 4) = "http")
            currentPathType := "link"
        else
            currentPathType := "local"

        if (currentPathType = "link")
        {
            currentBaseURL := currentPlayingPath
            if (InStr(currentPlayingPath, "?"))
            {
                RegExMatch(currentPlayingPath, "^(.*?)\?", currentMatch)
                currentBaseURL := currentMatch1
            }

            if (RegExMatch(currentPlayingPath, "p=(\d+)", currentPMatch))
            {
                currentEpisode := currentPMatch1
            }
            else
            {
                ShowToolTip("当前播放的链接中未检测到集数参数 p=,无法提取集数!", 5)
                Return
            }

            baseURL := RegExReplace(videoLink, "\?.*$")
            if (currentBaseURL = baseURL)
            {
                if (episode = currentEpisode)
                {
                    ShowToolTip("当前播放的集数与选中的集数一致,开始定位时间。", 3)
                    SeekTime(formattedTime, !isFirstLink)
                    if (isFirstLink)
                        isFirstLink := false
                }
                else
                {
                    ShowToolTip("当前播放的集数与选中的集数不一致,关闭当前视频并打开新链接。", 3)
                    Send ^!x
                    ShowToolTip("已发送 Ctrl + Alt + X,关闭当前视频。", 3)
                    Sleep, 500
                    OpenLinkAndSeek(videoLink, formattedTime, potPlayerPath)
                }
            }
            else
            {
                ShowToolTip("当前播放的链接基URL与选中的链接不一致,关闭当前视频并打开新链接。", 3)
                Send ^!x
                ShowToolTip("已发送 Ctrl + Alt + X,关闭当前视频。", 3)
                Sleep, 500
                OpenLinkAndSeek(videoLink, formattedTime, potPlayerPath)
            }
        }
        else
        {
            ShowToolTip("当前播放的是本地视频,与选中的链接不一致,关闭当前视频并打开新链接。", 3)
            Send ^!x
            ShowToolTip("已发送 Ctrl + Alt + X,关闭当前视频。", 3)
            Sleep, 500
            OpenLinkAndSeek(videoLink, formattedTime, potPlayerPath)
        }
    }
    else
    {
        ShowToolTip("未检测到已打开的 PotPlayer 窗口,开始打开链接。", 3)
        OpenLinkAndSeek(videoLink, formattedTime, potPlayerPath)
    }
}
Return

; 修改后的处理本地路径的函数
HandleLocalPath(videoPath, seekTime, potPlayerPath, selectedText)
{
    ; 检查路径是否有效
    if (FileExist(videoPath))
    {
        ProcessLocalPath(videoPath, seekTime, potPlayerPath)
    }
    else
    {
        ; 路径无效,提取文件名(包括扩展名)
        SplitPath, videoPath, fileName
        ShowToolTip("视频文件路径无效:" . videoPath . ",尝试通过 es.exe 搜索文件名:" . fileName, 5)

        ; 使用 es.exe 搜索文件名
        foundPaths := SearchWithEs(fileName)

        if (foundPaths.MaxIndex() > 0)
        {
            ; 取第一个匹配的文件
            selectedPath := foundPaths[1]
            ShowToolTip("通过 es.exe 找到文件:" . selectedPath, 5)

            ; 更新 Typora 中的文本
            UpdateTyporaPath(selectedText, seekTime, selectedPath)

            ; 处理找到的路径
            ProcessLocalPath(selectedPath, seekTime, potPlayerPath)
        }
        else
        {
            ShowToolTip("es.exe 未找到匹配文件:" . fileName, 5)
            Return
        }
    }
}
Return

; 新增函数:使用 es.exe 搜索文件名
SearchWithEs(fileName)
{
    global EsPath
    TempFile := A_Temp "\es_output.txt"
    RunWait, %ComSpec% /c ""%EsPath%" "%fileName%" > "%TempFile%"", , Hide
    FileRead, Output, %TempFile%
    FileDelete, %TempFile%
    foundPaths := []
    if (Output != "")
    {
        Loop, Parse, Output, `n, `r
        {
            if (A_LoopField != "")
            {
                foundPaths.Push(A_LoopField)
            }
        }
    }
    return foundPaths
}

; 新增函数:更新 Typora 中的路径
UpdateTyporaPath(selectedText, seekTime, newPath)
{
    ; 构建新文本
    newText := "[" . seekTime . "]-[" . newPath . "]"
    Clipboard := newText
    Send ^v
    ShowToolTip("已更新 Typora 中的路径为:" . newPath, 5)
}

; 处理有效本地路径的函数
ProcessLocalPath(videoPath, seekTime, potPlayerPath)
{
    SetTitleMatchMode, 2
    if WinExist("ahk_class PotPlayer64")
    {
        ShowToolTip("检测到已打开的 PotPlayer 窗口。", 3)
        WinActivate
        Sleep, 做什么? 200

        Clipboard := ""
        Send ^!p
        ShowToolTip("已发送 Ctrl + Alt + P,获取当前播放视频路径。", 3)
        Sleep, 500
        ClipWait, 1
        currentPlayingPath := Clipboard

        if (SubStr(currentPlayingPath, 1, 4) = "http")
            currentPathType := "link"
        else
            currentPathType := "local"

        if (currentPathType = "local")
        {
            if (currentPlayingPath = videoPath)
            {
                ShowToolTip("当前播放的视频与选中的路径一致,开始定位时间。", 3)
                SeekTime(seekTime, true)
            }
            else
            {
                ShowToolTip("当前播放的视频与选中的路径不一致,关闭当前视频并打开新视频。", 3)
                Send ^!x
                ShowToolTip("已发送 Ctrl + Alt + X,关闭当前视频。", 3)
                Sleep, 500
                OpenVideoAndSeek(videoPath, seekTime, potPlayerPath)
            }
        }
        else
        {
            ShowToolTip("当前播放的是链接,与选中的本地路径不一致,关闭当前视频并打开新视频。", 3)
            Send ^!x
            ShowToolTip("已发送 Ctrl + Alt + X,关闭当前视频。", 3)
            Sleep, 500
            OpenVideoAndSeek(videoPath, seekTime, potPlayerPath)
        }
    }
    else
    {
        ShowToolTip("未检测到已打开的 PotPlayer 窗口,开始打开新视频。", 3)
        OpenVideoAndSeek(videoPath, seekTime, potPlayerPath)
    }
}
Return

; 打开链接并定位时间的流程
OpenLinkAndSeek(videoLink, formattedTime, potPlayerPath)
{
    processedLink := RemoveTimeAndAmpersand(videoLink)
    MsgBox, 4,, 处理后的链接:`n%processedLink%`n是否继续粘贴到 PotPlayer?
    IfMsgBox, No
    {
        ShowToolTip("已取消操作。", 3)
        Return
    }

    SetTitleMatchMode, 2
    if WinExist("ahk_class PotPlayer64")
    {
        WinActivate
        Sleep, 200
        ShowToolTip("已激活 PotPlayer 窗口。", 3)
    }
    else
    {
        Run, "%potPlayerPath%", , UseErrorLevel
        if ErrorLevel
        {
            ShowToolTip("PotPlayer 启动失败,请检查 PotPlayer 的路径是否正确!", 5)
            Return
        }
        else
        {
            ShowToolTip("已启动 PotPlayer。", 3)
            Sleep, 1000
        }
    }

    Send ^!{F11}
    ShowToolTip("已发送 Ctrl + Alt + F11,打开链接输入窗口。", 3)
    Sleep, 500

    Clipboard := processedLink
    Send ^v
    ShowToolTip("已粘贴处理后的链接。", 3)
    Sleep, 200

    Send {Enter}
    ShowToolTip("已发送回车键,打开视频。", 3)
    Sleep, 3000

    SeekTime(formattedTime, false)
    global isFirstLink
    isFirstLink := false
}
Return

; 打开新视频并定位时间的函数
OpenVideoAndSeek(videoPath, seekTime, potPlayerPath)
{
    RunCommand := Chr(34) . potPlayerPath . Chr(34) . " " . Chr(34) . videoPath . Chr(34) . " /seek=" . seekTime
    Run, %RunCommand%, , UseErrorLevel
    if ErrorLevel
    {
        ShowToolTip("PotPlayer 启动失败,请检查 PotPlayer 的路径是否正确!", 5)
        Return
    }
    else
    {
        ShowToolTip("已打开新视频。", 3)
        Sleep, 3000
    }

    Send ^!s
    ShowToolTip("已发送 Ctrl + Alt + S,进入全屏。", 3)
    ShowToolTip("已打开新视频并进入全屏!", 3)
}
Return

; 定位时间的函数
SeekTime(formattedTime, sendESC)
{
    Send ^!d
    ShowToolTip("已发送 Ctrl + Alt + D,打开定位设置窗口。", 3)
    Sleep, 500

    Clipboard := formattedTime
    Send ^v
    ShowToolTip("已粘贴定位时间:" . formattedTime, 3)
    Sleep, 200

    Send {Enter}
    ShowToolTip("已发送回车键,确认定位。", 3)
    Sleep, 500

    if (sendESC)
    {
        Send {Esc}
        ShowToolTip("已发送 ESC,关闭定位设置窗口。", 3)
        Sleep, 200
    }

    Send ^!s
    ShowToolTip("已发送 Ctrl + Alt + S,进入全屏。", 3)
    ShowToolTip("已定位到指定时间并进入全屏。", 3)
}
Return

; 处理仅包含时间的函数
HandleTimeOnly(originalTime)
{
    ShowToolTip("处理仅包含时间的选中文本。", 3)
    processedTime := originalTime

    Send ^!2
    ShowToolTip("已发送 Ctrl + Alt + 2。", 3)
    Sleep, 200

    Click
    ShowToolTip("已模拟左键单击。", 3)
    Sleep, 200

    Send ^+v
    ShowToolTip("已发送 Ctrl + Shift + v。", 3)
    Sleep, 300

    Clipboard := processedTime
    Send ^v
    ShowToolTip("已粘贴处理后的时间:" . processedTime, 3)
    Sleep, 200

    Send {Enter}
    ShowToolTip("已发送回车键。", 3)
    Sleep, 200

    Send ^!2
    ShowToolTip("已发送 Ctrl + Alt + 2。", 3)
    Sleep, 200

    Click
    ShowToolTip("已模拟左键单击。", 3)
    ShowToolTip("时间处理完毕并执行相关操作。", 3)
}
Return

; 配置设置:选择 PotPlayer 路径
Configure:
{
    FileSelectFile, potPlayerPath, 3, , 请选择 PotPlayer 播放器路径, 可执行文件 (*.exe)
    if ErrorLevel
    {
        ShowToolTip("您取消了 PotPlayer 播放器路径设置!", 5)
        Return
    }

    IniWrite, %potPlayerPath%, %configFile%, Paths, PotPlayer
    ShowToolTip("设置完成!PotPlayer 路径已保存!", 5)
}
Return

; 工具函数:显示缓缓消失的提示信息
ShowToolTip(text, duration := 3)
{
    Tooltip, %text%, 10, 10
    SetTimer, RemoveToolTip, -%duration%000
}

RemoveToolTip:
    Tooltip
Return

; 删除链接中的 t=时间 参数和多余的 &
RemoveTimeAndAmpersand(link)
{
    link := RegExReplace(link, "([?&])t=\d+(?:\.\d+)?&", "$1")
    link := RegExReplace(link, "([?&])t=\d+(?:\.\d+)?", "")
    link := RegExReplace(link, "\?&", "?")
    link := RegExReplace(link, "&$", "")
    return link
}

快捷键xbutton1(鼠标侧键触发)

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

; 配置文件路径
configFile := A_ScriptDir "\config.ini"

; 默认 es.exe 路径
DefaultEsPath := "C:\Program Files\Everything\es.exe"

; 全局变量:是否首次通过链接打开 PotPlayer
isFirstLink := true

; 快捷键侧键
XButton1::
{
    ; 检查配置文件是否存在
    if (!FileExist(configFile))
    {
        IniWrite, C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe, %configFile%, Paths, PotPlayer
        IniWrite, %DefaultEsPath%, %configFile%, Paths, Es
        ShowToolTip("检测到首次运行,请先设置 PotPlayer 播放器路径!", 5)
        Goto, Configure
    }

    ; 从配置文件读取 PotPlayer 和 es.exe 路径
    IniRead, potPlayerPath, %configFile%, Paths, PotPlayer
    IniRead, EsPath, %configFile%, Paths, Es, %DefaultEsPath%

    ; 检查 PotPlayer 路径是否有效
    if (!FileExist(potPlayerPath))
    {
        ShowToolTip("配置文件中的 PotPlayer 路径无效,请重新设置!", 5)
        Goto, Configure
    }

    ; 检查 es.exe 路径是否有效
    if (!FileExist(EsPath))
    {
        ShowToolTip("es.exe 路径无效,请检查配置文件中的路径!", 5)
        Return
    }

    ; 获取选中的文本
    ClipSaved := ClipboardAll
    Clipboard := ""
    Send ^c
    ClipWait, 1

    selectedText := Clipboard
    Clipboard := ClipSaved

    ; 检查选中文本是否为空
    if (selectedText = "")
    {
        ShowToolTip("未选中文本,请选中包含时间和路径的文本!", 5)
        Return
    }

    ; 判断选中的文本格式
    if (RegExMatch(selectedText, "^\[(\d{2}:\d{2}:\d{2}(?:\.\d+)?)\]-\[(.+)\]$", match))
    {
        seekTime := match1
        videoPath := match2

        if (SubStr(videoPath, 1, 4) = "http")
        {
            HandleLink(videoPath, seekTime, potPlayerPath)
        }
        else
        {
            HandleLocalPath(videoPath, seekTime, potPlayerPath, selectedText)
        }
    }
    else if (RegExMatch(selectedText, "^\[(\d{2}:\d{2}:\d{2}(?:\.\d+)?)\]$", timeMatch))
    {
        HandleTimeOnly(timeMatch1)
    }
    else if (RegExMatch(selectedText, "^https?://", match))
    {
        ShowToolTip("选中的文本是链接,使用默认浏览器打开。", 3)
        Run, %selectedText%
        Sleep, 3000
        Send, f
        ShowToolTip("已打开链接并发送 F 键以全屏。", 3)
    }
    else
    {
        ShowToolTip("选中的文本格式无效!", 5)
    }
}
Return

; 处理链接的函数 (未修改)
HandleLink(videoLink, seekTime, potPlayerPath)
{
    if (RegExMatch(videoLink, "t=(\d+(?:\.\d+)?)", tMatch))
    {
        seconds := tMatch1
        hours := Floor(seconds / 3600)
        minutes := Floor((seconds - (hours * 3600)) / 60)
        secs := seconds - (hours * 3600) - (minutes * 60)
        formattedTime := Format("{:02}:{:02}:{:04.1f}", hours, minutes, secs)
    }
    else
    {
        ShowToolTip("链接中未检测到时间参数 t=,无法提取时间!", 5)
        Return
    }
;优化集数*****************************
;    if (RegExMatch(videoLink, "p=(\d+)", pMatch))
;    {
;        episode := pMatch1
;    }
;    else
;    {
;        ShowToolTip("链接中未检测到集数参数 p=,无法提取集数!", 5)
;        Return
;    }
     episode := pMatch1
;优化集数*****************************
    ShowToolTip("链接检测到时间参数: " . seconds . " 秒,集数参数: " . episode . ",转换为 " . formattedTime, 5)

    SetTitleMatchMode, 2
    if WinExist("ahk_class PotPlayer64")
    {
        ShowToolTip("检测到已打开的 PotPlayer 窗口。", 3)
        WinActivate
        Sleep, 200

        Clipboard := ""
        Send ^!p
        ShowToolTip("已发送 Ctrl + Alt + P,获取当前播放视频链接。", 3)
        Sleep, 500
        ClipWait, 1
        currentPlayingPath := Clipboard

        if (SubStr(currentPlayingPath, 1, 4) = "http")
            currentPathType := "link"
        else
            currentPathType := "local"

        if (currentPathType = "link")
        {
            currentBaseURL := currentPlayingPath
            if (InStr(currentPlayingPath, "?"))
            {
                RegExMatch(currentPlayingPath, "^(.*?)\?", currentMatch)
                currentBaseURL := currentMatch1
            }
;优化集数********************************************************************
;            if (RegExMatch(currentPlayingPath, "p=(\d+)", currentPMatch))
;            {
;                currentEpisode := currentPMatch1
;            }
;            else
;            {
;                ShowToolTip("当前播放的链接中未检测到集数参数 p=,无法提取集数!", 5)
;                Return
;            }
	    RegExMatch(currentPlayingPath, "p=(\d+)", currentPMatch)
	    currentEpisode := currentPMatch1                
;优化集数********************************************************************
            baseURL := RegExReplace(videoLink, "\?.*$")
            if (currentBaseURL = baseURL)
            {
                if (episode = currentEpisode)
                {
                    ShowToolTip("当前播放的集数与选中的集数一致,开始定位时间。", 3)
                    SeekTime(formattedTime, !isFirstLink)
                    if (isFirstLink)
                        isFirstLink := false
                }
                else
                {
                    ShowToolTip("当前播放的集数与选中的集数不一致,关闭当前视频并打开新链接。", 3)
                    Send ^!x
                    ShowToolTip("已发送 Ctrl + Alt + X,关闭当前视频。", 3)
                    Sleep, 500
                    OpenLinkAndSeek(videoLink, formattedTime, potPlayerPath)
                }
            }
            else
            {
                ShowToolTip("当前播放的链接基URL与选中的链接不一致,关闭当前视频并打开新链接。", 3)
                Send ^!x
                ShowToolTip("已发送 Ctrl + Alt + X,关闭当前视频。", 3)
                Sleep, 500
                OpenLinkAndSeek(videoLink, formattedTime, potPlayerPath)
            }
        }
        else
        {
            ShowToolTip("当前播放的是本地视频,与选中的链接不一致,关闭当前视频并打开新链接。", 3)
            Send ^!x
            ShowToolTip("已发送 Ctrl + Alt + X,关闭当前视频。", 3)
            Sleep, 500
            OpenLinkAndSeek(videoLink, formattedTime, potPlayerPath)
        }
    }
    else
    {
        ShowToolTip("未检测到已打开的 PotPlayer 窗口,开始打开链接。", 3)
        OpenLinkAndSeek(videoLink, formattedTime, potPlayerPath)
    }
}
Return

; 修改后的处理本地路径的函数
HandleLocalPath(videoPath, seekTime, potPlayerPath, selectedText)
{
    ; 检查路径是否有效
    if (FileExist(videoPath))
    {
        ProcessLocalPath(videoPath, seekTime, potPlayerPath)
    }
    else
    {
        ; 路径无效,提取文件名(包括扩展名)
        SplitPath, videoPath, fileName
        ShowToolTip("视频文件路径无效:" . videoPath . ",尝试通过 es.exe 搜索文件名:" . fileName, 5)

        ; 使用 es.exe 搜索文件名
        foundPaths := SearchWithEs(fileName)

        if (foundPaths.MaxIndex() > 0)
        {
            ; 取第一个匹配的文件
            selectedPath := foundPaths[1]
            ShowToolTip("通过 es.exe 找到文件:" . selectedPath, 5)

            ; 更新 Typora 中的文本
            UpdateTyporaPath(selectedText, seekTime, selectedPath)

            ; 处理找到的路径
            ProcessLocalPath(selectedPath, seekTime, potPlayerPath)
        }
        else
        {
            ShowToolTip("es.exe 未找到匹配文件:" . fileName, 5)
            Return
        }
    }
}
Return

; 新增函数:使用 es.exe 搜索文件名
SearchWithEs(fileName)
{
    global EsPath
    TempFile := A_Temp "\es_output.txt"
    RunWait, %ComSpec% /c ""%EsPath%" "%fileName%" > "%TempFile%"", , Hide
    FileRead, Output, %TempFile%
    FileDelete, %TempFile%
    foundPaths := []
    if (Output != "")
    {
        Loop, Parse, Output, `n, `r
        {
            if (A_LoopField != "")
            {
                foundPaths.Push(A_LoopField)
            }
        }
    }
    return foundPaths
}

; 新增函数:更新 Typora 中的路径
UpdateTyporaPath(selectedText, seekTime, newPath)
{
    ; 构建新文本
    newText := "[" . seekTime . "]-[" . newPath . "]"
    Clipboard := newText
    Send ^v
    ShowToolTip("已更新 Typora 中的路径为:" . newPath, 5)
}

; 处理有效本地路径的函数
ProcessLocalPath(videoPath, seekTime, potPlayerPath)
{
    SetTitleMatchMode, 2
    if WinExist("ahk_class PotPlayer64")
    {
        ShowToolTip("检测到已打开的 PotPlayer 窗口。", 3)
        WinActivate
        Sleep, 做什么? 200

        Clipboard := ""
        Send ^!p
        ShowToolTip("已发送 Ctrl + Alt + P,获取当前播放视频路径。", 3)
        Sleep, 500
        ClipWait, 1
        currentPlayingPath := Clipboard

        if (SubStr(currentPlayingPath, 1, 4) = "http")
            currentPathType := "link"
        else
            currentPathType := "local"

        if (currentPathType = "local")
        {
            if (currentPlayingPath = videoPath)
            {
                ShowToolTip("当前播放的视频与选中的路径一致,开始定位时间。", 3)
                SeekTime(seekTime, true)
		Send ^!s
		Send,{Space}
            }
            else
            {
                ShowToolTip("当前播放的视频与选中的路径不一致,关闭当前视频并打开新视频。", 3)
                Send ^!x
                ShowToolTip("已发送 Ctrl + Alt + X,关闭当前视频。", 3)
                Sleep, 500
                OpenVideoAndSeek(videoPath, seekTime, potPlayerPath)
            }
        }
        else
        {
            ShowToolTip("当前播放的是链接,与选中的本地路径不一致,关闭当前视频并打开新视频。", 3)
            Send ^!x
            ShowToolTip("已发送 Ctrl + Alt + X,关闭当前视频。", 3)
            Sleep, 500
            OpenVideoAndSeek(videoPath, seekTime, potPlayerPath)
        }
    }
    else
    {
        ShowToolTip("未检测到已打开的 PotPlayer 窗口,开始打开新视频。", 3)
        OpenVideoAndSeek(videoPath, seekTime, potPlayerPath)
    }
}
Return

; 打开链接并定位时间的流程
OpenLinkAndSeek(videoLink, formattedTime, potPlayerPath)
{
    processedLink := RemoveTimeAndAmpersand(videoLink)
    MsgBox, 4,, 处理后的链接:`n%processedLink%`n是否继续粘贴到 PotPlayer?
    IfMsgBox, No
    {
        ShowToolTip("已取消操作。", 3)
        Return
    }

    SetTitleMatchMode, 2
    if WinExist("ahk_class PotPlayer64")
    {
        WinActivate
        Sleep, 200
        ShowToolTip("已激活 PotPlayer 窗口。", 3)
    }
    else
    {
        Run, "%potPlayerPath%", , UseErrorLevel
        if ErrorLevel
        {
            ShowToolTip("PotPlayer 启动失败,请检查 PotPlayer 的路径是否正确!", 5)
            Return
        }
        else
        {
            ShowToolTip("已启动 PotPlayer。", 3)
            Sleep, 1000
        }
    }

    Send ^!{F11}
    ShowToolTip("已发送 Ctrl + Alt + F11,打开链接输入窗口。", 3)
    Sleep, 500

    Clipboard := processedLink
    Send ^v
    ShowToolTip("已粘贴处理后的链接。", 3)
    Sleep, 200

    Send {Enter}
    ShowToolTip("已发送回车键,打开视频。", 3)
    Sleep, 3000

    SeekTime(formattedTime, false)
    global isFirstLink
    isFirstLink := false
}
Return

; 打开新视频并定位时间的函数
OpenVideoAndSeek(videoPath, seekTime, potPlayerPath)
{
    RunCommand := Chr(34) . potPlayerPath . Chr(34) . " " . Chr(34) . videoPath . Chr(34) . " /seek=" . seekTime
    Run, %RunCommand%, , UseErrorLevel
    if ErrorLevel
    {
        ShowToolTip("PotPlayer 启动失败,请检查 PotPlayer 的路径是否正确!", 5)
        Return
    }
    else
    {
        ShowToolTip("已打开新视频。", 3)
        Sleep, 3000
    }

    Send ^!s
    ShowToolTip("已发送 Ctrl + Alt + S,进入全屏。", 3)
    ShowToolTip("已打开新视频并进入全屏!", 3)
}
Return

; 定位时间的函数
SeekTime(formattedTime, sendESC)
{
    Send ^!d
    ShowToolTip("已发送 Ctrl + Alt + D,打开定位设置窗口。", 3)
    Sleep, 500

    Clipboard := formattedTime
    Send ^v
    ShowToolTip("已粘贴定位时间:" . formattedTime, 3)
    Sleep, 200

    Send {Enter}
    ShowToolTip("已发送回车键,确认定位。", 3)
    Sleep, 500

    if (sendESC)
    {
        Send {Esc}
        ShowToolTip("已发送 ESC,关闭定位设置窗口。", 3)
        Sleep, 200
    }

    Send ^!s
    ShowToolTip("已发送 Ctrl + Alt + S,进入全屏。", 3)
    ShowToolTip("已定位到指定时间并进入全屏。", 3)
}
Return

; 处理仅包含时间的函数
HandleTimeOnly(originalTime)
{
    ShowToolTip("处理仅包含时间的选中文本。", 3)
    processedTime := originalTime

    Send ^!2
    ShowToolTip("已发送 Ctrl + Alt + 2。", 3)
    Sleep, 200

    Click
    ShowToolTip("已模拟左键单击。", 3)
    Sleep, 200

    Send ^+v
    ShowToolTip("已发送 Ctrl + Shift + v。", 3)
    Sleep, 300

    Clipboard := processedTime
    Send ^v
    ShowToolTip("已粘贴处理后的时间:" . processedTime, 3)
    Sleep, 200

    Send {Enter}
    ShowToolTip("已发送回车键。", 3)
    Sleep, 200

    Send ^!2
    ShowToolTip("已发送 Ctrl + Alt + 2。", 3)
    Sleep, 200

    Click
    ShowToolTip("已模拟左键单击。", 3)
    ShowToolTip("时间处理完毕并执行相关操作。", 3)
}
Return

; 配置设置:选择 PotPlayer 路径
Configure:
{
    FileSelectFile, potPlayerPath, 3, , 请选择 PotPlayer 播放器路径, 可执行文件 (*.exe)
    if ErrorLevel
    {
        ShowToolTip("您取消了 PotPlayer 播放器路径设置!", 5)
        Return
    }

    IniWrite, %potPlayerPath%, %configFile%, Paths, PotPlayer
    ShowToolTip("设置完成!PotPlayer 路径已保存!", 5)
}
Return

; 工具函数:显示缓缓消失的提示信息
ShowToolTip(text, duration := 3)
{
    Tooltip, %text%, 10, 10
    SetTimer, RemoveToolTip, -%duration%000
}

RemoveToolTip:
    Tooltip
Return

; 删除链接中的 t=时间 参数和多余的 &
RemoveTimeAndAmpersand(link)
{
    link := RegExReplace(link, "([?&])t=\d+(?:\.\d+)?&", "$1")
    link := RegExReplace(link, "([?&])t=\d+(?:\.\d+)?", "")
    link := RegExReplace(link, "\?&", "?")
    link := RegExReplace(link, "&$", "")
    return link
}

测试使用

[小时:分钟:秒]~[路径/视频名字]

选中后, 按下对应按键, 会进行扫盘, 验证路径,找不到,就会自动扫盘,然后修复路径,打开视频


网站公告

今日签到

点亮在社区的每一天
去签到