Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- playlistduration.lua -- VLC extension --
- --[[
- INSTALLATION:
- Put the file in the VLC subdir /lua/extensions, by default:
- * Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\
- * Windows (current user): %APPDATA%\VLC\lua\extensions\
- * Linux (all users): /usr/share/vlc/lua/extensions/
- * Linux (current user): ~/.local/share/vlc/lua/extensions/
- * Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/
- (create directories if they don't exist)
- Restart the VLC.
- Then you simply use the extension by going to the "View" menu and selecting it.
- --]]
- function descriptor()
- return { title = "Playlist Duration" ;
- version = "1.0" ;
- author = "abremir" ;
- url = '';
- shortdesc = "Playlist Duration";
- description = "Get the playlist duration.\n"
- .. "Returns the total play time of the current playlist." ;
- }
- end
- function activate()
- vlc.msg.info("[playlist duration] start")
- playdur = vlc.dialog("Playlist Duration")
- playdur:add_label("", 1, 1, 11, 2)
- playdur:add_label("Total time:", 12, 1, 1, 2)
- durlabel=playdur:add_label(playlist_duration(), 13, 1, 1, 2)
- playdur:add_label("", 14, 1, 11, 2)
- playdur:add_button("Ok", close_dialog, 12, 3, 2, 1)
- playdur:show()
- end
- function deactivate()
- vlc.msg.info("[playlist duration] stop")
- end
- function close_dialog()
- vlc.deactivate()
- end
- function dur_to_time(duration)
- if duration>0 then
- local durationHour = math.floor(duration / 3600)
- local durationMinute = math.floor((duration % 3600) / 60)
- local durationSecond = math.floor(duration % 60)
- return durationHour, durationMinute, durationSecond
- else
- return 0, 0, 0
- end
- end
- function playlist_duration()
- local sum = 0
- local play_list = vlc.playlist.get("playlist",false)
- for k, item in pairs(play_list.children) do
- if item.duration ~= -1 then
- sum = sum + item.duration
- end
- end
- local h, m, s = dur_to_time(sum)
- return tostring(string.format("%02d:%02d:%02d", h, m, s))
- end
Advertisement
Add Comment
Please, Sign In to add comment