Guest User

Untitled

a guest
Feb 6th, 2019
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. -- cache for alredy resolved titles and titles that could not be resolved (filenames)
  2. -- filename => title
  3. local title_cache = {}
  4.  
  5. mp.register_script_message("osc_update_title", function(filename, title)
  6.         title_cache[filename] = title
  7.     end)
  8.  
  9. function get_playlist()
  10.     local pos = mp.get_property_number('playlist-pos', 0) + 1
  11.     local count, limlist = limited_list('playlist', pos)
  12.     if count == 0 then
  13.         return 'Empty playlist.'
  14.     end
  15.  
  16.     local message = string.format('Playlist [%d/%d]:\n', pos, count)
  17.     for i, v in ipairs(limlist) do
  18.         local title = v.title
  19.         if not title then
  20.             -- try getting title from cache
  21.             if title_cache[v.filename] then
  22.                 title = title_cache[v.filename]
  23.            
  24.             -- title not in cache
  25.             else
  26.                 local _
  27.                 _, title = utils.split_path(v.filename)
  28.                 -- set title to filename
  29.                 title_cache[v.filename] = title
  30.                
  31.                 -- try to resolving title in background
  32.                 mp.commandv('script-message', 'ytdl_resolve_title', v.filename)
  33.             end
  34.         end
  35.         message = string.format('%s %s %s\n', message,
  36.             (v.current and '●' or '○'), title)
  37.     end
  38.     return message
  39. end
Add Comment
Please, Sign In to add comment