Last active
August 19, 2023 18:35
-
-
Save bitingsock/f9a87ea158035d4a36899b559d611228 to your computer and use it in GitHub Desktop.
resolves ytdl for urls in playlist when the demuxer reaches near the end of the file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local utils = require 'mp.utils' | |
local ytdlPath = mp.find_config_file("youtube-dl.exe") | |
local fileDuration = 0 | |
local function check_position() | |
if fileDuration==0 then | |
mp.unobserve_property(check_position) | |
return | |
end | |
local demuxEndPosition = mp.get_property("demuxer-cache-time") | |
if demuxEndPosition and | |
fileDuration > 0 and | |
(fileDuration - demuxEndPosition < 10) and | |
(mp.get_property("playlist-pos-1")~=mp.get_property("playlist-count")) then | |
local next = tonumber(mp.get_property("playlist-pos")) + 1 | |
local nextFile = mp.get_property("playlist/"..tostring(next).."/filename") | |
if nextFile then | |
local ytdl = {} | |
ytdl.args = {ytdlPath, "-f "..mp.get_property("ytdl-format"), "-e", "-g", nextFile} | |
local res = utils.subprocess(ytdl) | |
local lines = {} | |
for s in res.stdout:gmatch("[^\r\n]+") do | |
table.insert(lines, s) | |
end | |
local audioURL = "" | |
if lines[3] then | |
audioURL = ',audio-file=['..lines[3]..']' | |
end | |
if lines[1] and lines[2] then | |
mp.commandv("loadfile", lines[2], "append", 'force-media-title=['..lines[1]..']'..audioURL) | |
mp.commandv("playlist_move", mp.get_property("playlist-count") - 1 , next) | |
mp.commandv("playlist_remove", next + 1) | |
end | |
mp.unobserve_property(check_position) | |
end | |
end | |
end | |
local function observe() | |
if mp.get_property("path"):find("://", 0, false) then | |
fileDuration = mp.get_property("duration", 0) | |
fileDuration = tonumber(fileDuration) | |
mp.observe_property("time-pos", "native", check_position) | |
end | |
end | |
mp.register_event("file-loaded", observe) |
I've discovered that a lot of usefulness of this script doesn't actually work :(
It appears --prefetch-playlist doesn't actually fill the cache with subsequent data and merely opens the url and keeps it active, downloading what appears to be header and metadata and mpv just waits for that file to actually be playing before downloading any more.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On Linux change line 2:
local ytdlPath = "youtube-dl"