累计签到:22 天 连续签到:1 天
|
正文
大家好,分享一个自己写的 PotPlayer 小工具,主要用来快速跳过片头片尾,适合平时追番、追剧时使用。
这个工具最初是为了省掉每次手动拖动进度条的操作,现在整理成了单独的 exe,发出来给有同样需求的朋友试用。
功能说明
仅在 PotPlayer 窗口中生效,不会影响其他软件。
F7 跳转到当前视频对应的片头结束位置。
F8 跳转到当前视频对应的片尾开始位置。
F9 可记录当前播放位置为该文件名对应的片头时间,并自动持久化保存。
下次播放同系列文件时,F7 会优先使用已保存的片头时间。
源码
[Plain Text] 纯文本查看 复制代码; ================= 用户自定义区域:剧集时间配置 =================; 将你的剧集名称和对应时间按以下格式添加(一个剧集一行); 剧集名称可以灵活匹配,只要文件名中包含此关键词即可,如"S01"或"Part.1"TVSeriesConfig := "(沧元图|90|1200凡人修仙传|85|1180斗破苍穹|95|1220)"; 格式说明:每行是 "剧集名称关键词|片头结束时间(秒)|片尾开始时间(秒)"; ================= 用户自定义区域结束 =================PersistentIntroConfig := A_ScriptDir . "\PotPlayer跳片头尾-通过文件名截取方式跳过.ini"; 核心函数:根据当前播放文件匹配配置并跳转JumpBasedOnSeries(isIntro) { seriesKey := GetCurrentSeriesKey() if (seriesKey = "") { MsgBox, 未能识别当前播放文件名。 return } matchResult := FindSeriesTime(seriesKey, isIntro) if !matchResult.found { if (isIntro = 1) { MsgBox, 未找到当前播放文件的片头跳过配置。`n文件名关键词:%seriesKey% } else { MsgBox, 未找到当前播放文件的片尾跳过配置。`n文件名关键词:%seriesKey% } return } if (isIntro = 1) { action := "片头" } else { action := "片尾" } JumpToTime(matchResult.time) tipText := "跳过来自 [" . matchResult.seriesKey . "] 的" . action ToolTip, %tipText% SetTimer, RemoveToolTip, -2000}; 保存当前文件名对应的片头开始时间SaveCurrentIntroTime() { Global PersistentIntroConfig seriesKey := GetCurrentSeriesKey() if (seriesKey = "") { MsgBox, 未能识别当前播放文件名,无法保存片头时间。 return } currentSeconds := GetCurrentPlaybackTime() if (currentSeconds = "") { MsgBox, 未能获取当前播放时间,无法保存片头时间。 return } IniWrite, %currentSeconds%, %PersistentIntroConfig%, IntroTimes, %seriesKey% formattedTime := FormatTime(currentSeconds) ToolTip, 已保存 [%seriesKey%] 的片头时间:%formattedTime% SetTimer, RemoveToolTip, -2000}; 查找当前文件对应的时间配置FindSeriesTime(seriesKey, isIntro) { Global TVSeriesConfig savedIntroTime := ReadSavedIntroTime(seriesKey) Loop, Parse, TVSeriesConfig, `n, `r { if (A_LoopField = "") continue StringSplit, configPart, A_LoopField, | configKey := Trim(configPart1) introTime := Trim(configPart2) outroTime := Trim(configPart3) if InStr(seriesKey, configKey) { if (isIntro = 1) { targetTime := (savedIntroTime != "" ? savedIntroTime : introTime) if (targetTime = "") return {found: 0, seriesKey: configKey} return {found: 1, time: targetTime + 0, seriesKey: configKey} } if (outroTime = "") return {found: 0, seriesKey: configKey} return {found: 1, time: outroTime + 0, seriesKey: configKey} } } if (isIntro = 1 && savedIntroTime != "") return {found: 1, time: savedIntroTime + 0, seriesKey: seriesKey} return {found: 0, seriesKey: seriesKey}}; 读取持久化保存的片头时间ReadSavedIntroTime(seriesKey) { Global PersistentIntroConfig IniRead, introTime, %PersistentIntroConfig%, IntroTimes, %seriesKey%, __NOT_FOUND__ if (introTime = "__NOT_FOUND__") return "" return introTime}; 获取当前播放文件的匹配关键词GetCurrentSeriesKey() { if !IsPotPlayerActive() return "" WinGetTitle, currentTitle, A return ExtractFolderName(currentTitle)}; 辅助函数:从窗口标题中提取文件名关键词ExtractFolderName(fullTitle) { fileStr := RegExReplace(fullTitle, "\s+-\s+PotPlayer.*$") fileStr := Trim(fileStr) SplitPath, fileStr, , , , nameNoExt nameNoExt := Trim(nameNoExt) if (InStr(nameNoExt, "-")) { StringSplit, parts, nameNoExt, - folderName := Trim(parts1) } else { folderName := nameNoExt } return folderName}; 获取当前播放时间(秒)GetCurrentPlaybackTime() { if !IsPotPlayerActive() return "" if !OpenTimeJumpDialog(playerHwnd, dialogHwnd) return "" ControlGetText, currentTime, Edit1, ahk_id %dialogHwnd% CloseTimeJumpDialog(dialogHwnd, playerHwnd) return ParseTimeToSeconds(currentTime)}; 解析 PotPlayer 中的时间文本ParseTimeToSeconds(timeText) { timeText := Trim(timeText) if (timeText = "") return "" timeText := RegExReplace(timeText, "\s.*$") parts := StrSplit(timeText, ":") partCount := parts.MaxIndex() if (partCount = 2) { minutes := parts[1] + 0 secondsText := RegExReplace(parts[2], "[^\d].*$") return minutes * 60 + (secondsText + 0) } if (partCount >= 3) { hours := parts[1] + 0 minutes := parts[2] + 0 secondsText := RegExReplace(parts[3], "[^\d].*$") return hours * 3600 + minutes * 60 + (secondsText + 0) } return ""}; ================= 核心跳转函数 =================JumpToTime(targetTimeInSeconds) { if !IsPotPlayerActive() { MsgBox, 请先激活PotPlayer窗口! return } formattedTime := FormatTime(targetTimeInSeconds) if !OpenTimeJumpDialog(playerHwnd, dialogHwnd) { MsgBox, 未能打开 PotPlayer 的时间跳转窗口。 return } ControlFocus, Edit1, ahk_id %dialogHwnd% ControlSetText, Edit1, %formattedTime%, ahk_id %dialogHwnd% ControlSend, Edit1, {Enter}, ahk_id %dialogHwnd% Sleep, 100 CloseTimeJumpDialog(dialogHwnd, playerHwnd)}; ================= 辅助函数:时间格式化 =================FormatTime(seconds) { if (seconds < 3600) { minutes := seconds // 60 secs := Mod(seconds, 60) return Format("{:02}:{:02}", minutes, secs) } else { hours := seconds // 3600 minutes := Mod(seconds // 60, 60) secs := Mod(seconds, 60) return Format("{:02}:{:02}:{:02}", hours, minutes, secs) }}; 判断当前激活窗口是否为 PotPlayerIsPotPlayerActive() { WinGet, processName, ProcessName, A WinGetClass, windowClass, A return (processName = "PotPlayerMini64.exe" || processName = "PotPlayerMini.exe" || windowClass = "PotPlayer64" || windowClass = "PotPlayer")}OpenTimeJumpDialog(ByRef playerHwnd, ByRef dialogHwnd) { playerHwnd := WinExist("A") Send, g WinWaitActive, ahk_class #32770,, 1 if ErrorLevel return 0 dialogHwnd := WinExist("A") return dialogHwnd ? 1 : 0}CloseTimeJumpDialog(dialogHwnd, playerHwnd := 0) { dialogWinTitle := "ahk_id " . dialogHwnd playerWinTitle := "ahk_id " . playerHwnd if (dialogHwnd && WinExist(dialogWinTitle)) { WinActivate, %dialogWinTitle% Sleep, 50 SendInput, !c WinWaitClose, %dialogWinTitle%,, 1 } if (playerHwnd && WinExist(playerWinTitle)) WinActivate, %playerWinTitle%}RemoveToolTip: ToolTipreturn#If IsPotPlayerActive()F7:: ; 按下 F7,跳过来自匹配剧集的片头 JumpBasedOnSeries(1)returnF8:: ; 按下 F8,跳过来自匹配剧集的片尾 JumpBasedOnSeries(0)returnF9:: ; 按下 F9,保存当前文件名对应的片头起始时间 SaveCurrentIntroTime()return#If
工作方式
程序会根据当前播放文件名提取关键词进行匹配。
默认可在脚本配置中预设片头和片尾时间。
如果某一集的片头时间想手动微调,可以直接在对应位置按 F9 保存,后续会自动读取保存结果。
适用场景
同一动画、剧集的大部分集数片头片尾时间相近。
文件名有相对固定的命名规律。
希望用快捷键快速跳过,不想每次手动拖进度条。
使用方法
运行程序。
打开 PotPlayer 播放视频。
按 F7 跳片头,按 F8 跳片尾。
如果当前集片头位置需要重新记录,先把视频播放到目标位置,再按 F9 保存。
说明
工具仅针对 PotPlayer 使用。
配置文件会保存在程序目录下,方便后续直接读取。
exe 由 AutoHotkey 打包生成,部分安全软件可能会有误报,这类情况属于脚本类程序常见现象;介意的话可以直接查看源码版。
程序是自用后整理分享,欢迎反馈命名规则兼容性和使用问题。
更新内容
限制热键只在 PotPlayer 中生效。
新增 F9 记录片头时间并持久化。
修正跳转窗口关闭逻辑,避免误关闭视频。
下载方式
PotPlayer跳片头尾-通过文件名截取方式跳过.zip
演示截图
PotPlayer 播放界面截图

配置保存效果截图

INI 持久化截图

结尾
如果这个小工具对你有帮助,欢迎回复反馈。
如果后续有新的功能想法,比如自动识别更多命名格式、支持更多播放器,我也可以继续完善。 |
|