1 mp.register_event('file-loaded', function()
   2     local date  = 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 = mp.get_property('time-pos') or 0;
   9     local pos_tm = os.date('!%H:%M:%S', pos);
  10     local pos_pr = mp.get_property('percent-pos')
  11 
  12     local dir =
  13         os.getenv('APPDATA') or
  14         os.getenv('XDG_CONFIG_HOME') or
  15         os.getenv('HOME')..'/.config';
  16 
  17     local file = io.open(dir..'/mpv/history.log', 'a+');
  18     file:write(('[%s] "%s" %s (%d%%) - %s\n'):format(
  19         date, title, pos_tm, pos_pr, path
  20     ));
  21     file:close();
  22 end);