Skip to content

Instantly share code, notes, and snippets.

@garoto
Last active August 6, 2025 07:33
Show Gist options
  • Save garoto/e0eb539b210ee077c980e01fb2daef4a to your computer and use it in GitHub Desktop.
Save garoto/e0eb539b210ee077c980e01fb2daef4a to your computer and use it in GitHub Desktop.
Simple media logger Lua script for mpv
-- Not my code: originally from https://redd.it/3t6s7k (author deleted; failed to ask for permission).
-- Only tested on Windows. Date is set to dd/mmm/yy and time to machine-wide format.
-- Save as "mpvhistory.lua" in your mpv scripts dir. Log will be saved to mpv default config directory.
-- Make sure to leave a comment if you make any improvements/changes to the script!
local HISTFILE = (os.getenv('APPDATA') or os.getenv('HOME')..'/.config')..'/mpv/mpvhistory.log';
mp.register_event('file-loaded', function()
local title, logfile;
title = mp.get_property('media-title');
title = (title == mp.get_property('filename') and '' or ('(%s)'):format(title));
logfile = io.open(HISTFILE, 'a+');
logfile:write(('[%s] %s %s\n'):format(os.date('%d/%b/%y %X'), mp.get_property('path'), title));
logfile:close();
end)
@ipatch
Copy link

ipatch commented Aug 29, 2018

great script, I'd suggest using double quotes instead of single quotes IMHO

@christosangelopoulos
Copy link

Great script, I modified it and intergrated it to a project that scrolls mpv title in the panel in xfce desktop environment.

https://gitlab.com/christosangel/genmon-mpv

@jimmy-1000
Copy link

@garoto Hi, I have a little question if you have time. How to modify this lua so that each entry starts on a new line instead of continuing the previous line or insert an empty line between entries to make the history look better and clearer.

@garoto
Copy link
Author

garoto commented Mar 6, 2025

@jimmy-1000 Not sure what you mean, but a LF char is already inserted at the end of every line, see line #15: logfile:write(('[%s] %s %s\n') See the "\n" there? Yeah, that's the Lua newline escaped char. Or maybe the log viewer you're using doesn't recognize a single LF as a newline delimiter, like Win7 notepad.exe perhaps?

@jimmy-1000
Copy link

@jimmy-1000 Not sure what you mean, but a LF char is already inserted at the end of every line, see line #15: logfile:write(('[%s] %s %s\n') See the "\n" there? Yeah, that's the Lua newline escaped char. Or maybe the log viewer you're using doesn't recognize a single LF as a newline delimiter, like Win7 notepad.exe perhaps?

You are right in everything you say, what a shame 🙈

@garoto
Copy link
Author

garoto commented Mar 6, 2025

No worries my dude, but in anycase, if you want to have a file that has CRLF as line endings, just add a \r before the "\n" at line #15 like I mentioned in my comment, so it'd be like: logfile:write(('[%s] %s %s\r\n')

@jimmy-1000
Copy link

No worries my dude, but in anycase, if you want to have a file that has CRLF as line endings, just add a \r before the "\n" at line #15 like I mentioned in my comment, so it'd be like: logfile:write(('[%s] %s %s\r\n')

Thanks! This greatly improves the look with notepad.

@Listarsss
Copy link

excuse me,you mean the author has deleted the script or his website?I tried but i can't open the linking you give for details。

@garoto
Copy link
Author

garoto commented Aug 1, 2025

excuse me,you mean the author has deleted the script or his website?I tried but i can't open the linking you give for details.

The reddit user who originally concocted the script deleted his account, so I was never able to ask him for permission to share it on github. The redd.it short link shown on the script comment section works and redirects to the original thread.

@Listarsss
Copy link

excuse me,you mean the author has deleted the script or his website?I tried but i can't open the linking you give for details.

The reddit user who originally concocted the script deleted his account, so I was never able to ask him for permission to share it on github. The short link shown on the script comment section works and redirects to the original thread.redd.it

well,that may be my problem.thanks

@Listarsss
Copy link

have u ever tried to use a script called bookmark or bookmarker-menu?they have similar function as this script.I tried both of them but it doen't work.I have to write a script by myself to open video automatically when open mpv.If u know something for this,i would appreciate it very much

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