8
votes

I am using "https://www.youtube.com/get_video_info" to get the video information,thumbnails images,and video URL

To Play the video in Custom video player,but when click on "vevo channel" video.

its not return any video URL. I also try the different parameter in "get_video_info" api . Example :

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=detailpage&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

There are many of the videos not getting the video info. There are following videos, its not getting the video info.

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

but we can play this videos in some of the live application.Example

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

How its possible ??

if I want to play all the videos, so what's the solution ??

3
I also referred to this example --- github.com/runmad/RMYouTubeExtractor \n but not getting any solution yetVishal Khatri
try this 1)gdata.youtube.com/feeds/api/videos/3O1_3zBUKM8?v=2 (2)gdata.youtube.com/feeds/api/videos/kHue-HaXXzg?v=2 ans so on ,just insert video no before the query string partAgent Chocks.
YouTube Data API (v2) has been officially deprecated, some API functions will stop working (and return errors) sooner than other functions. developers.google.com/youtube/2.0/… ----->> So we have to find another solution @AgentVishal Khatri

3 Answers

1
votes

The url retrieve videoUrl from YouTube is https://www.youtube.com/get_video_info?video_id=/*videoId*/&el=vevo&el=embedded&asv=3&sts=15902

Here is how to get the videoUrl through videoId. Lua code:

-- 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

You can 'translate' it into Objective-C code.

Hope this helps.

0
votes

Youtube won't let you play videos that contain rights. All playable videos will be the ones that are free for use and free of rights. From July 2021 "get_video_info" returns "410 - gone", I guess that someone in google had a crisis that the videos can be played outside youtube. need "get_video_info"? you can use my NuGet https://www.nuget.org/packages/Youtube.VideoInfo

enjoy!

-2
votes

That type of video can only be played when it's embedded on a real website. we don't expose those lists via the API.

This blog post has a bit more detail as well:

http://apiblog.youtube.com/2011/12/understanding-playback-restrictions.html