[raw] [dotfiles.tar.gz]
   1 mp.register_event('file-loaded', function()
   2     local time  = os.date('%Y-%m-%d %H:%M:%S');
   3     local title = mp.get_property('media-title');
   4     local path  = mp.get_property('path'):gsub(
   5         os.getenv('HOME') or os.getenv('HOMEPATH'), '~'
   6     );
   7 
   8     local pos_pr = mp.get_property('percent-pos')
   9     local pos_tm = os.date(
  10         '!%H:%M:%S', mp.get_property('time-pos') or 0
  11     );
  12 
  13     local dir =
  14         os.getenv('APPDATA') or
  15         os.getenv('XDG_CONFIG_HOME') or
  16         os.getenv('HOME')..'/.config';
  17 
  18     local file = io.open(dir..'/mpv/history.log', 'a+');
  19     file:write(('[%s] "%s" %s (%d%%) - %s\n'):format(
  20         time, title, pos_tm, pos_pr, path
  21     ));
  22     file:close();
  23 end);