json = require "json" local media = {} function pop(cmd) local f = assert(io.popen(cmd, 'r')) local s = assert(f:read('*a')) f:close() return s end function media.getVideoUrl(yurl) if yurl == nil then return 0 end local h = hintbox.new{caption="Please Wait ...", text="I'm Thinking."} if h then h:paint() end local data = pop("/usr/bin/yt-dlp --dump-single-json " .. yurl) local itagnum = 0 local urls = {} local video = nil media.VideoUrl = nil media.UrlVideoAudio = nil if data then local jnTab = json:decode(data) if jnTab ~= nil then for k,v in pairs(jnTab.formats) do --if v.audio_channels == 2 and v.resolution ~= "audio only" then if v.resolution ~= "audio only" then itagnum = tonumber(v.format_id) if itagnum == 22 or itagnum == 18 or itagnum == 95 then urls[itagnum] = v.url end if v.resolution then print(v.format,v.resolution) end end end end video = urls[22] if video then media.VideoUrl = video else media.VideoUrl = urls[18] end if urls[95] then media.VideoUrl = urls[95] end end if h then h:hide() end end return media