vincegeratorix

playlistduration.lua backup

Jan 31st, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. -- playlistduration.lua -- VLC extension --
  2. --[[
  3. INSTALLATION:
  4. Put the file in the VLC subdir /lua/extensions, by default:
  5. * Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\
  6. * Windows (current user): %APPDATA%\VLC\lua\extensions\
  7. * Linux (all users): /usr/share/vlc/lua/extensions/
  8. * Linux (current user): ~/.local/share/vlc/lua/extensions/
  9. * Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/
  10. (create directories if they don't exist)
  11. Restart the VLC.
  12. Then you simply use the extension by going to the "View" menu and selecting it.
  13. --]]
  14.  
  15. function descriptor()
  16.   return { title = "Playlist Duration" ;
  17.     version = "1.0" ;
  18.     author = "abremir" ;
  19.     url = '';
  20.     shortdesc = "Playlist Duration";
  21.     description = "Get the playlist duration.\n"
  22.       .. "Returns the total play time of the current playlist." ;
  23.   }
  24. end
  25.  
  26. function activate()
  27.   vlc.msg.info("[playlist duration] start")
  28.   playdur = vlc.dialog("Playlist Duration")
  29.   playdur:add_label("", 1, 1, 11, 2)
  30.   playdur:add_label("Total time:", 12, 1, 1, 2)
  31.   durlabel=playdur:add_label(playlist_duration(), 13, 1, 1, 2)
  32.   playdur:add_label("", 14, 1, 11, 2)
  33.   playdur:add_button("Ok", close_dialog, 12, 3, 2, 1)
  34.   playdur:show()
  35. end
  36.  
  37. function deactivate()
  38.   vlc.msg.info("[playlist duration] stop")
  39. end
  40.  
  41. function close_dialog()
  42.   vlc.deactivate()
  43. end
  44.  
  45. function dur_to_time(duration)
  46.   if duration>0 then
  47.     local durationHour = math.floor(duration / 3600)
  48.     local durationMinute = math.floor((duration % 3600) / 60)
  49.     local durationSecond = math.floor(duration % 60)
  50.     return durationHour, durationMinute, durationSecond
  51.   else
  52.     return 0, 0, 0
  53.   end
  54. end
  55.  
  56. function playlist_duration()
  57.   local sum = 0
  58.   local play_list = vlc.playlist.get("playlist",false)
  59.   for k, item in pairs(play_list.children) do
  60.     if item.duration ~= -1 then
  61.       sum = sum + item.duration
  62.     end
  63.   end
  64.   local h, m, s = dur_to_time(sum)
  65.   return tostring(string.format("%02d:%02d:%02d", h, m, s))
  66. end
Advertisement
Add Comment
Please, Sign In to add comment