How to get a direct link to youtube video and in different resolutions?

My problem is I want to get a direct youtube video link and different links for different qualities. for example, if I have this url www.youtube.com/watch?v=VCQ24gXfRrc , then direct links of this video in a different capacity are as follows

for 240p

for 360p

for 720p

can someone tell me how to get direct links of youtube video from youtube. I searched a lot but couldn't find a solution. any solution in php and javascript would be helpful.

+3


source to share


1 answer


You can use this code:

videoUrls = ytplayer.config.args.adaptive_fmts
            .split(',')
            .map(item => item
            .split('&')
            .reduce((prev, curr) => (curr = curr.split('='),
                Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])})
        ), {})
        )
        .reduce((prev, curr) => Object.assign(prev, {
                [curr.quality_label || curr.type]: curr
            }), {} );

      



json output with different qualities:

        {720p: {…}, 480p: {…}, 360p: {…}, 240p: {…}, 144p: {…}, …}
    144p
    :
    {bitrate: "105451", lmt: "1501151759670299", quality_label: "144p", type: "video/webm;+codecs="vp9"", projection_type: "1", …}
    240p
    :
    {bitrate: "236138", lmt: "1501151763073149", quality_label: "240p", type: "video/webm;+codecs="vp9"", projection_type: "1", …}
    360p
    :
    {bitrate: "431019", lmt: "1501151763523043", quality_label: "360p", type: "video/webm;+codecs="vp9"", projection_type: "1", …}
    480p
    :
    {bitrate: "751515", lmt: "1501151761884798", quality_label: "480p", type: "video/webm;+codecs="vp9"", projection_type: "1", …}
    720p
    :
    {bitrate: "1530639", lmt: "1501151774338090", quality_label: "720p", type: "video/webm;+codecs="vp9"", projection_type: "1", …}
    audio/mp4;+codecs="mp4a.40.2"
    :
    {url: "https://redirector.googlevideo.com/videoplayback?k…70E2C77F1747DA9B3&source=youtube&mime=audio%2Fmp4", type: "audio/mp4;+codecs="mp4a.40.2"", init: "0-591", projection_type: "1", bitrate: "96956", …}
    audio/webm;+codecs="opus"
    :
    {url: "https://redirector.googlevideo.com/videoplayback?k…AEF92557AE5C5581&source=youtube&mime=audio%2Fwebm", type: "audio/webm;+codecs="opus"", init: "0-271", projection_type: "1", bitrate: "116254", …}
    audio/webm;+codecs="vorbis"
    :
    {url: "https://redirector.googlevideo.com/videoplayback?k…FA29AC0F6C925E21&source=youtube&mime=audio%2Fwebm", type: "audio/webm;+codecs="vorbis"", init: "0-4082", projection_type: "1", bitrate: "77114", …}
    __proto__
    :
    Object

      

0


source







All Articles