Advertisement
Guest User

Untitled

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