Guest User

Untitled

a guest
Jan 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. local utils = require 'mp.utils'
  2. local ytdlPath = mp.find_config_file("youtube-dl.exe")
  3. local fileDuration = 0
  4. local function check_position()
  5. local demuxEndPosition = mp.get_property("demuxer-cache-time")
  6. if demuxEndPosition and (fileDuration - demuxEndPosition < 10) and (mp.get_property("playlist-pos-1")~=mp.get_property("playlist-count")) then
  7. local ytdl = {}
  8. ytdl.args = {ytdlPath}
  9. table.insert(ytdl.args, "-f best")
  10. table.insert(ytdl.args, "-e")
  11. table.insert(ytdl.args, "-g")
  12. local next = tonumber(mp.get_property("playlist-pos")) + 1
  13. local nextFile = mp.get_property("playlist/"..tostring(next).."/filename")
  14. if nextFile then
  15. table.insert(ytdl.args, nextFile)
  16. local res = utils.subprocess(ytdl)
  17. local es, txt = res.status, res.stdout
  18. local lines = {}
  19. for s in txt:gmatch("[^\r\n]+") do
  20. table.insert(lines, s)
  21. end
  22. mp.commandv("loadfile", lines[2], "append", 'force-media-title="'..lines[1]..'"')
  23. mp.commandv("playlist_move", mp.get_property("playlist-count") - 1 , next)
  24. mp.commandv("playlist_remove", next + 1)
  25. mp.unobserve_property(check_position)
  26. end
  27. end
  28. end
  29. local function observe()
  30. fileDuration = mp.get_property("duration")
  31. mp.observe_property("time-pos", "native", check_position)
  32. end
  33. mp.register_event("file-loaded", observe)
Add Comment
Please, Sign In to add comment