Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local utils = require 'mp.utils'
- local ytdlPath = mp.find_config_file("youtube-dl.exe")
- local fileDuration = 0
- local function check_position()
- local demuxEndPosition = mp.get_property("demuxer-cache-time")
- if demuxEndPosition and (fileDuration - demuxEndPosition < 10) and (mp.get_property("playlist-pos-1")~=mp.get_property("playlist-count")) then
- local ytdl = {}
- ytdl.args = {ytdlPath}
- table.insert(ytdl.args, "-f best")
- table.insert(ytdl.args, "-e")
- table.insert(ytdl.args, "-g")
- local next = tonumber(mp.get_property("playlist-pos")) + 1
- local nextFile = mp.get_property("playlist/"..tostring(next).."/filename")
- if nextFile then
- table.insert(ytdl.args, nextFile)
- local res = utils.subprocess(ytdl)
- local es, txt = res.status, res.stdout
- local lines = {}
- for s in txt:gmatch("[^\r\n]+") do
- table.insert(lines, s)
- end
- mp.commandv("loadfile", lines[2], "append", 'force-media-title="'..lines[1]..'"')
- mp.commandv("playlist_move", mp.get_property("playlist-count") - 1 , next)
- mp.commandv("playlist_remove", next + 1)
- mp.unobserve_property(check_position)
- end
- end
- end
- local function observe()
- fileDuration = mp.get_property("duration")
- mp.observe_property("time-pos", "native", check_position)
- end
- mp.register_event("file-loaded", observe)
Add Comment
Please, Sign In to add comment