我正在使用" https://www.youtube.com/get_video_info"获取视频信息,缩略图图像和视频URL
要在自定义视频播放器中播放视频,但在点击" vevo频道"视频。
它不会返回任何视频网址。我也尝试了" get_video_info"中的不同参数。 api。示例:
https://www.youtube.com/get_video_info?hl=en&video_id=0KSOMA3QBU0&eurl=&el=embedded&gl=US&ps=default
https://www.youtube.com/get_video_info?hl=en&video_id=0KSOMA3QBU0&eurl=&el=vevo&gl=US&ps=default
https://www.youtube.com/get_video_info?hl=en&video_id=0KSOMA3QBU0&eurl=&el=&gl=US&ps=default
有很多视频无法获取视频信息。 有以下视频,它没有获取视频信息。
https://www.youtube.com/watch?v=3O1_3zBUKM8
https://www.youtube.com/watch?v=kHue-HaXXzg
https://www.youtube.com/watch?v=PNu_-deVemE
https://www.youtube.com/watch?v=CevxZvSJLk8
https://www.youtube.com/watch?v=CEUg7OplvIQ
但我们可以在一些实时应用中播放此视频。例如
https://play.google.com/store/apps/details?id=com.tfsapps.playtube2
https://itunes.apple.com/in/app/itube-playlist-management/id789819758?mt=8
https://itunes.apple.com/ca/app/itube-free-music-playlists/id866761482?mt=8
怎么可能?
如果我想播放所有视频,那么解决方案是什么?
答案 0 :(得分:1)
从YouTube检索的videoUrl是https://www.youtube.com/get_video_info?video_id=/*videoId*/&el=vevo&el=embedded&asv=3&sts=15902
以下是如何通过videoId获取videoUrl。 Lua代码:
-- string.explode(string, separator)
function string.explode(p, d)
local t, i
t={}
i=0
if(#p == 1) then return {p} end
while true do
l=string.find(p,d,i,true)
if l~=nil then
table.insert(t, string.sub(p,i,l-1))
i=l+1
else
table.insert(t, string.sub(p,i))
break
end
end
return t
end
-- string.begin_with
function string.begin_with(str, sub_str)
return string.find(str, sub_str)==1
end
-- string.url_decode
function string.url_decode(str)
str = string.gsub (str, "+", " ")
str = string.gsub (str, "%%(%x%x)", function(h) return string.char(tonumber(h,16)) end)
str = string.gsub (str, "\r\n", "\n")
return str
end
-- string.url_query_parameter_map
function string.url_query_parameter_map(str)
local params_kv = {}
for k,v in pairs(string.explode(str, "&")) do
local eqmark_idx = string.find(v, "=")
if eqmark_idx ~= nil and eqmark_idx > 1 and eqmark_idx < string.len(v) then
local param_name = string.sub(v, 1, eqmark_idx-1)
local param_value = string.sub(v, eqmark_idx+1)
param_name = string.url_decode(param_name)
param_value = string.url_decode(param_value)
--print (param_name .." => " .. param_value)
params_kv[param_name] = param_value
else
params_kv[string.url_decode(v)] = ""
end
end
return params_kv
end
function string.ytb_sig_charswap(str, pos)
local c1 = string.sub(str,1,1)
local pos2 = (pos-1)%string.len(str)+1--lua has index begun at 1!
local c2 = string.sub(str,pos2,pos2)
return c2..string.sub(str,2,pos2-1)..c1..string.sub(str,pos2+1)
end
-- string.ytb_sig_decrypt
function string.ytb_sig_decrypt(str)
local sig = str
sig = string.sub(sig, 3)
sig = string.reverse(sig)
sig = string.sub(sig, 4)
sig = string.ytb_sig_charswap(sig, 10)
sig = string.sub(sig, 4)
sig = string.ytb_sig_charswap(sig, 44)
sig = string.sub(sig, 4)
sig = string.reverse(sig)
sig = string.ytb_sig_charswap(sig, 24)
return sig
end
--local s = "YFRHVIIsjrkkiGDtqKXrh847DI5GKDKokWjjgougGDLanT2rw92V6cuXY5BfPGMsaLwgGUYV76wr1T6W"
--print(string.ytb_sig_decrypt(s))
-- define the parser function
-- return: number of video resource, table of video resources, failed reason text.
parse = function (s)
local params_kv = string.url_query_parameter_map(s)
-- print(params_kv["fmt_list"]);
local fmt_list, fmt_stream = params_kv["fmt_list"], params_kv["url_encoded_fmt_stream_map"]
local reason, rental_bar = params_kv["reason"], params_kv["ypc_video_rental_bar_text"]
if (fmt_list == nil or fmt_stream == nil) then
local reason_text = "reason="
if (reason ~= nil) then
reason_text = reason_text .. reason
elseif (rental_bar ~= nil) then
reason_text = reason_text .. rental_bar
else
reason_text = "reason=This video cannot be played for some unknown reason(unexpected)"
end
return 0, {}, reason_text
end
print(fmt_list)
--local fmt_infos = {}
--for k,v in pairs(string.explode(fmt_list, ",")) do
-- local fmt_info = string.explode(v, "/")
-- local v_itag, v_reso = fmt_info[1], fmt_info[2]
-- fmt_infos[v_itag]=v_reso
-- print (v_itag.." => "..v_reso)
--end
local stream_n, stream_infos = 0, {}
for k,v in pairs(string.explode(fmt_stream, ",")) do
local s_info = string.url_query_parameter_map(v)
local v_itag, v_url, v_s, v_sig = s_info["itag"], s_info["url"], s_info["s"], s_info["sig"]
--print (v_itag.." => "..v_url)
--print ((v_s or "nil").." ~ "..(v_sig or "nil"))
if (string.find(v_url, "signature=") ~= nil) then
v_url = v_url
elseif (v_sig ~= nil) then
v_url = v_url.."&signature="..v_sig
elseif (v_s ~= nil) then
v_url = v_url.."&signature="..string.ytb_sig_decrypt(v_s)
else
v_url = v_url
end
stream_infos[v_itag] = v_url
stream_n=stream_n+1
print (v_itag.." => "..v_url)
end
return stream_n, stream_infos, ""
end
-- multiple return values:
-- the first one is script version number.
-- the second one is remote YouTube URL for fetching, with one parameter placeholder "%s".
-- the third one is the parser entry function object.
return "14.3.5", "https://www.youtube.com/get_video_info?video_id=%s&el=vevo&el=embedded&asv=3&sts=15902", parse
你可以翻译&#39;它成为Objective-C代码。
希望这有帮助。
答案 1 :(得分:0)
Youtube 不允许您播放包含版权的视频。 所有可播放的视频都将是免费使用且无权利的视频。 从 2021 年 7 月“get_video_info”返回“410 -消失”,我猜谷歌有人遇到了视频可以在 youtube 之外播放的危机。 需要“get_video_info”? 你可以使用我的 NuGet https://www.nuget.org/packages/Youtube.VideoInfo/1.0.0
享受吧!
答案 2 :(得分:-2)
这种类型的视频只有在真实网站上嵌入时才能播放。我们不会通过API公开这些列表。
此博客文章还有更多细节:
http://apiblog.youtube.com/2011/12/understanding-playback-restrictions.html