Video Player - mpv GUI: sorting files

This is an example using hotkeys and scripting for sorting video files by moving them to different folders while playing.

Lua scripting was added with VideoPlayerMpv 3.1. It is very basic at the moment (just few custom functions) and not documented yet (but it was copied from tSIP softphone, so some of its documentation would still be true in this application).

Script setup for this example consist of one common script (doing actual work) and N (here N = 4) very short scripts with different output folders defined inside. These short scripts are assigned to hotkeys (e.g. F1 ... F4) and they are calling common script.

Hotkey setup

VideoPlayerMpv hotkes

Example scripts assigned to hotkeys:

-- MoveToA.lua
local dir = "D:\\Dokumenty\\_PROJEKTY\\VideoPlayerMpv\\VideoPlayer\\Debug_Build\\_test\\folderA\\"	-- destination dir

local common = require("scripts.CommonMoveFile")
common.MoveFileToDir(dir)

-- MoveToB.lua
local dir = "D:\\Dokumenty\\_PROJEKTY\\VideoPlayerMpv\\VideoPlayer\\Debug_Build\\_test\\folderB\\"	-- destination dir

local common = require("scripts.CommonMoveFile")
common.MoveFileToDir(dir)

Common script:

-- CommonMoveFile.lua
local M = {} -- public interface

function M.MoveFileToDir(dstDir)

	local filename = GetCurrentFileName()
	if filename.len == 0 then
		return
	end
	
	-- accept directories with and without trailing backslash
	if dstDir:sub(-1, -1) ~= "\\" then
		dstDir = dstDir .. "\\"
	end
	
	ForceDirectories(dstDir)

	-- extract source file name without dir
	local index = string.find(filename:reverse(), "\\")
	local fname
	if index == nil then
		fname = filename
	else
		fname = string.sub(filename, -(index-1))
	end

	print(string.format("Current file: %s\n", filename))

	Skip()	-- play next

	-- move to destination dir
	local dstFile = dstDir .. fname
	local result = MoveFile(filename, dstFile)
	print(string.format("Destination: %s\n", dstFile))
	if result ~= 0 then
		print(string.format("Moving %s to %s failed!\n", filename, dstFile))
		ShowMessage("Moving " .. filename .. " failed!")
	else
		print(string.format("%s moved to %s\n", filename, dstFile))
	end 

end

return M

Scripts as zip

Unzip script files to VideoPlayer /scripts subdirectory: scripts.zip.

Notes

Back to VideoPlayerMpv.