Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. mp = require 'mp'
  2.  
  3. local decode_needed = false
  4.  
  5. function trim(s)
  6.    return (s:gsub("^%s*(.-)%s*$", "%1"))
  7. end
  8.  
  9. function decode(title)
  10.     local ret = io.popen(string.format('%s "%s" | %s',
  11.         'echo', title, 'iconv -f="windows-1251" -t="utf-8"')):read('*all')
  12.  
  13.     return trim(ret)
  14. end
  15.  
  16. function on_title_changed(name, title)
  17.     if decode_needed then
  18.         local decoded = decode(title)
  19.         print(title, '->', decoded)
  20.         mp.set_property('force-media-title', decoded)
  21.     end
  22. end
  23.  
  24. mp.observe_property('media-title', 'string', on_title_changed)
  25. mp.add_hook('on_load', 50, function()
  26.         local filename = mp.get_property('path', nil)
  27.         decode_needed =  string.find(filename, 'ru')
  28.     end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement