fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.49k stars 793 forks source link

MinigetError: input stream: Status code: 404 #980

Open N1C0exe opened 3 years ago

N1C0exe commented 3 years ago

Hi guys unfortunately this 404 error is back , but the package and the bot throw this error if u try to play a age limit video ( https://www.youtube.com/watch?v=dmJefsOErr0 )

N1C0exe commented 3 years ago

Also I want to add that yesterday I could play song with age limit

mpirescarvalho commented 3 years ago

+1, I'm also getting 404

MatteZ02 commented 3 years ago

doesn't seem to be a ytdl-core only problem. lavalink runs into the same issue but with error video is unavailable.

N1C0exe commented 3 years ago

Request like this works as expected:

POST /youtubei/v1/player HTTP/1.1
Host: www.youtube.com
Authorization: Bearer ya29.a0ARrdaM8ubnr5IhwHHNB2vZh-VcGZT2JaeVtOnF-7SZMqmnES0...

{"context":{"client":{"clientName":"ANDROID","clientVersion":"16.05"}},
"racyCheckOk":true,"videoId":"dmJefsOErr0"}

Is this a age limit video?

N1C0exe commented 3 years ago

Did you actually look at the request? Its the exact same video you posted...

Oh okay yea

N1C0exe commented 3 years ago

Did you actually look at the request? Its the exact same video you posted...

Now i have tried again and continue to give error

mpirescarvalho commented 3 years ago

Are you sure the problem is age restricted videos? I'm getting 404 for ALL videos.

For example, this one:

https://www.youtube.com/watch?v=SJ3e03OGvRg image

N1C0exe commented 3 years ago

Yes I can play this video with my bot. Are u using v 4.9.0?

Il Ven 23 Lug 2021, 18:26 Marcelo Carvalho @.***> ha scritto:

Are you sure the problem is age restricted videos? I'm getting 404 for ALL videos.

For example, this one:

https://www.youtube.com/watch?v=SJ3e03OGvRg [image: image] https://user-images.githubusercontent.com/20830847/126812460-81fc7632-66ef-4bbc-bb7a-47107498b246.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fent/node-ytdl-core/issues/980#issuecomment-885754713, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQMXMQ5IZKG6XTQHYEOXKK3TZGJ2HANCNFSM5A2V26OQ .

N1C0exe commented 3 years ago

Are you sure the problem is age restricted videos? I'm getting 404 for ALL videos. For example, this one: https://www.youtube.com/watch?v=SJ3e03OGvRg

This request works as expected:

POST /youtubei/v1/player HTTP/1.1
Host: www.youtube.com
X-Goog-Api-Key: AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8

{"context":{"client":{"clientName":"ANDROID","clientVersion":"16.05"}},
"videoId":"SJ3e03OGvRg"}

Yes bec is not age restricted

N1C0exe commented 3 years ago

Yes bec is not age restricted

Request like this works as expected:

POST /youtubei/v1/player HTTP/1.1
Host: www.youtube.com
Authorization: Bearer ya29.a0ARrdaM8ubnr5IhwHHNB2vZh-VcGZT2JaeVtOnF-7SZMqmnES0...

{"context":{"client":{"clientName":"ANDROID","clientVersion":"16.05"}},
"racyCheckOk":true,"videoId":"dmJefsOErr0"}

For me not dude . Its throw the 404 error

mpirescarvalho commented 3 years ago

Where did that bearer token come from?

N1C0exe commented 3 years ago

Yes not at all ahahah

Il Ven 23 Lug 2021, 18:39 Steven Penny @.***> ha scritto:

For me not dude . Its throw the 404 error

I dont think you know what youre talking about.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fent/node-ytdl-core/issues/980#issuecomment-885762520, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQMXMQ5PCPCR2HZ2F3YMXT3TZGLMRANCNFSM5A2V26OQ .

mpirescarvalho commented 3 years ago

its an OAuth access_token

I know, but I'm not using any token

mpirescarvalho commented 3 years ago

@89z I asked about the token because you said my request worked as expected for you, but you had a token in it.

But nevermind, I think I have already found my problem.

N1C0exe commented 3 years ago

No way guys I found another limitation that throw the 404 error . The explicit contents video

QuazArxx commented 3 years ago

Are you sure the problem is age restricted videos? I'm getting 404 for ALL videos.

For example, this one:

https://www.youtube.com/watch?v=SJ3e03OGvRg image

Yeah I was getting 404 only for age restricted songs. I checked all the links I used as well. This was something that was supposedly fixed a month ago but I'm assuming the Youtube API was updated and caused the issue again.

N1C0exe commented 3 years ago

Are you sure the problem is age restricted videos? I'm getting 404 for ALL videos. For example, this one: https://www.youtube.com/watch?v=SJ3e03OGvRg image

Yeah I was getting 404 only for age restricted songs. I checked all the links I used as well. This was something that was supposedly fixed a month ago but I'm assuming the Youtube API was updated and caused the issue again. yes :(

N1C0exe commented 3 years ago

Are you sure the problem is age restricted videos? I'm getting 404 for ALL videos. For example, this one: https://www.youtube.com/watch?v=SJ3e03OGvRg image

Yeah I was getting 404 only for age restricted songs. I checked all the links I used as well. This was something that was supposedly fixed a month ago but I'm assuming the Youtube API was updated and caused the issue again. yes :(

EPXOL commented 3 years ago

When requesting this video from browser it returns this data:

{"responseContext":{"serviceTrackingParams":[{"service":"GFEEDBACK","params":[{"key":"is_viewed_live","value":"False"},{"key":"logged_in","value":"1"},{"key":"e","value":"23946420,24037794,24057628,24068193,24074909,23984880,24045411,24007246,23918597,24016724,24016285,24002022,23986032,23891346,23996830,24049820,24059521,23857950,24071362,24050503,23884386,23804281,24032277,24042870,24056264,23934970,24001373,24030040,24049571,24069707,24042738,23971645,24058380,23966208,23885490,24049573,24058812,23983813,23998056,23974595,24056275,23891344,24053866,24043240,24004644,24060921,23937619,23940237,23744176,24002025,1714247,24028143,24056704,24059975,23968386,24070166,23996512,24058128,23843508,24070073,23944779,23983296,24068842,23882685,24036948,24034978,24057238"}]},{"service":"CSI","params":[{"key":"c","value":"WEB"},{"key":"cver","value":"2.20210721.00.00"},{"key":"yt_li","value":"1"},{"key":"GetPlayer_rid","value":"0x26272868f40dcaf5"}]},{"service":"GUIDED_HELP","params":[{"key":"logged_in","value":"1"}]},{"service":"ECATCHER","params":[{"key":"client.version","value":"2.20210721"},{"key":"client.name","value":"WEB"}]}],"mainAppWebResponseContext":{"datasyncId":"103277725654256864760||","loggedOut":false},"webResponseContextExtensionData":{"hasDecorated":true}},"playabilityStatus":{"status":"AGE_VERIFICATION_REQUIRED","errorScreen":{"playerErrorMessageRenderer":{"subreason":{"runs":[{"text":"Dokončite krátku kontrolu, či máte dostatočný vek na pozeranie tohto videa. "},{"text":"Ďalšie informácie","navigationEndpoint":{"clickTrackingParams":"CAAQu2kiEwjr3IOdtv7xAhWGpFUKHWLADLw=","commandMetadata":{"webCommandMetadata":{"url":"https://support.google.com/youtube?p=watching_arv\u0026hl=sk","webPageType":"WEB_PAGE_TYPE_UNKNOWN","rootVe":83769}},"urlEndpoint":{"url":"https://support.google.com/youtube?p=watching_arv\u0026hl=sk"}}}]},"reason":{"runs":[{"text":"Overte svoj vek"}]},"proceedButton":{"buttonRenderer":{"style":"STYLE_WHITE_WITH_BORDER","size":"SIZE_DEFAULT","isDisabled":false,"text":{"runs":[{"text":"Overiť"}]},"trackingParams":"CAEQrfIGIhMI69yDnbb-8QIVhqRVCh1iwAy8","command":{"clickTrackingParams":"CAEQrfIGIhMI69yDnbb-8QIVhqRVCh1iwAy8","commandMetadata":{"webCommandMetadata":{"url":"https://myaccount.google.com/age-verification?utm_source=YT_WEB\u0026utm_medium=watch_link\u0026utm_campaign=watch_verify_prompt\u0026authuser=0\u0026continue=https%3A//youtube.com/watch%3Fv%3DdmJefsOErr0%26pp%3DQADoAwE%253D","webPageType":"WEB_PAGE_TYPE_UNKNOWN","rootVe":83769}},"urlEndpoint":{"url":"https://myaccount.google.com/age-verification?utm_source=YT_WEB\u0026utm_medium=watch_link\u0026utm_campaign=watch_verify_prompt\u0026authuser=0\u0026continue=https%3A//youtube.com/watch%3Fv%3DdmJefsOErr0%26pp%3DQADoAwE%253D"}}}},"icon":{"iconType":"ERROR_OUTLINE"}}},"desktopLegacyAgeGateReason":9,"contextParams":"Q0FFU0FnZ0I="},"videoDetails":{"videoId":"dmJefsOErr0","title":"Rae Sremmurd - Swang (Official Video)","lengthSeconds":"229","keywords":["Sremmurd","Swang","Eardruma/Interscope","rae sremmurd swang","rae sremmurd black beatles lyrics","rae sremmurd look alive","rae sremmurd mannequin challenge","rae sremmurd come get her","rae sremmurd no type","rae sremmurd","rae sremmurd black beatles","SremmLife 2","SremmLife 2 rae sremmurd","SremmLife","swang lyrics rae sremmurd","swang music video","swang lyrics","swang clean lyrics","slim jimmy"],"channelId":"UCweazuUMMKdL2wwSyrxla9A","isOwnerViewing":false,"shortDescription":"Rae Sremmurd “SremmLife 2” available now\niTunes: http://smarturl.it/SremmLife2\nApple Music: http://smarturl.it/SremmLife2.AP\nGoogle Play: http://smarturl.it/SremmLife2.GP\nAmazon: http://smarturl.it/SremmLife2.AMZ\nSpotify: http://smarturl.it/SremmLife2.SP\nTarget (includes 2 bonus tracks): Sremmlife 2: http://smarturl.it/Sremmlife2.Tgt \nRae Sremmurd newsletter: http://smarturl.it/RaeSremmurd.News \n\nStream “Swang” http://smarturl.it/Swang.sp\n\nMusic video by Rae Sremmurd performing Swang. (C) 2016 Eardruma/Interscope Records\n\n#RaeSremmurd #Swang #Vevo","isCrawlable":true,"thumbnail":{"thumbnails":[{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEbCKgBEF5IVfKriqkDDggBFQAAiEIYAXABwAEG\u0026rs=AOn4CLAZIwDhvRNE4vIe5g05pwPBKFNuQg","width":168,"height":94},{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEbCMQBEG5IVfKriqkDDggBFQAAiEIYAXABwAEG\u0026rs=AOn4CLCLK2nzQjD445NB2nejSpOtWO4TBA","width":196,"height":110},{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==\u0026rs=AOn4CLBOZf9Zdn4zwoeuZG1iCuUVUoOZQw","width":246,"height":138},{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==\u0026rs=AOn4CLBLDcI0JNk9UC4nviLHzrlcph4WcA","width":336,"height":188},{"url":"https://i.ytimg.com/vi_webp/dmJefsOErr0/maxresdefault.webp","width":1920,"height":1080}]},"averageRating":4.7515512,"allowRatings":true,"viewCount":"464114651","author":"RaeSremmurdVEVO","isPrivate":false,"isUnpluggedCorpus":false,"isLiveContent":false},"microformat":{"playerMicroformatRenderer":{"thumbnail":{"thumbnails":[{"url":"https://i.ytimg.com/vi/dmJefsOErr0/maxresdefault.jpg","width":1280,"height":720}]},"embed":{"iframeUrl":"https://www.youtube.com/embed/dmJefsOErr0","flashUrl":"http://www.youtube.com/v/dmJefsOErr0?version=3\u0026autohide=1","width":1280,"height":720,"flashSecureUrl":"https://www.youtube.com/v/dmJefsOErr0?version=3\u0026autohide=1"},"title":{"simpleText":"Rae Sremmurd - Swang (Official Video)"},"description":{"simpleText":"Rae Sremmurd “SremmLife 2” available now\niTunes: http://smarturl.it/SremmLife2\nApple Music: http://smarturl.it/SremmLife2.AP\nGoogle Play: http://smarturl.it/SremmLife2.GP\nAmazon: http://smarturl.it/SremmLife2.AMZ\nSpotify: http://smarturl.it/SremmLife2.SP\nTarget (includes 2 bonus tracks): Sremmlife 2: http://smarturl.it/Sremmlife2.Tgt \nRae Sremmurd newsletter: http://smarturl.it/RaeSremmurd.News \n\nStream “Swang” http://smarturl.it/Swang.sp\n\nMusic video by Rae Sremmurd performing Swang. (C) 2016 Eardruma/Interscope Records\n\n#RaeSremmurd #Swang #Vevo"},"lengthSeconds":"229","ownerProfileUrl":"http://www.youtube.com/user/RaeSremmurdVEVO","externalChannelId":"UCweazuUMMKdL2wwSyrxla9A","isFamilySafe":false,"isUnlisted":false,"hasYpcMetadata":false,"viewCount":"464114651","category":"Music","publishDate":"2017-02-16","ownerChannelName":"RaeSremmurdVEVO","uploadDate":"2017-02-16"}},"trackingParams":"CAAQu2kiEwjr3IOdtv7xAhWGpFUKHWLADLw=","frameworkUpdates":{"entityBatchUpdate":{"mutations":[{"entityKey":"Eg0KC2RtSmVmc09FcnIwIPYBKAE%3D","type":"ENTITY_MUTATION_TYPE_REPLACE","payload":{"offlineabilityEntity":{"key":"Eg0KC2RtSmVmc09FcnIwIPYBKAE%3D","accessState":"OFFLINEABILITY_FEATURE_ACCESS_STATE_UNKNOWN"}}}],"timestamp":{"seconds":"1627223046","nanos":70852067}}}}

This is data that ytdl-core recieve every time that you try to play song or you use .getInfo but you can search as much as you want for video formats but you will not find it. It meens that ytdl-core does not have any format available to download stream and it will create corupted URL like "null" or "undefined" so we found problem. Now to the solution. We need to create ALT accounts on google in ordet to create youtube VERIFIED accounts. Then you need to copy the cookies and x-user-data header of https://www.youtube.com site with that account becouse cookies and x-user-data header includes access token of account. We need to put that cookies into array. Let's say that it's named "ytAltCookies".

var ytAltCookies = [["cookies1", "x-user-data1"], ["cookies2", "x-user-data2"], ...];  //Make as many accounts as you want

Then we need to use these account in our ytdl-core request so it will return correct video info with video formats. And to switch between these accouns in ordet not to get too many requests error we need to switch these accouns constantly. Edid your code whereever you are using "ytdl(url)" for downloading stream with code below.

var cookies = ytAltCookies[0];
ytAltCookies.push(ytAltCookies.shift()); //Remove this cookies from start of array and put it on the end of array
ytdl("<ytURL", {
  requestOptions: {
    headers: {
      Cookie: cookies[0],
      'x-user-data': cookies[1]
    }
  }
});

Now ytdl-core should reqeust youtube site with these cookies and as age verified account. I didn't test it becouse I kind of can't verifie accout for myself so it is possible that it is not perfect solution.

To prevent making too many requests please check if video is age restricted and use these cookies only when video is age restricted becouse you could get too many reqeusts error really easy.

Edit: You need to use x-user-data header too.

N1C0exe commented 3 years ago

Hey guys I want to let you know my situtation . Now my bot can play age restricted video ( i used cookie ) and can play the song with explicit content and lyrics becouse my host has a new IP ( probably Yt blocked the old one ) . So 404 error as gone ! But I dont close the issue bec somone maybe need help :)

ProGamer2711 commented 3 years ago

When requesting this video from browser it returns this data:

{"responseContext":{"serviceTrackingParams":[{"service":"GFEEDBACK","params":[{"key":"is_viewed_live","value":"False"},{"key":"logged_in","value":"1"},{"key":"e","value":"23946420,24037794,24057628,24068193,24074909,23984880,24045411,24007246,23918597,24016724,24016285,24002022,23986032,23891346,23996830,24049820,24059521,23857950,24071362,24050503,23884386,23804281,24032277,24042870,24056264,23934970,24001373,24030040,24049571,24069707,24042738,23971645,24058380,23966208,23885490,24049573,24058812,23983813,23998056,23974595,24056275,23891344,24053866,24043240,24004644,24060921,23937619,23940237,23744176,24002025,1714247,24028143,24056704,24059975,23968386,24070166,23996512,24058128,23843508,24070073,23944779,23983296,24068842,23882685,24036948,24034978,24057238"}]},{"service":"CSI","params":[{"key":"c","value":"WEB"},{"key":"cver","value":"2.20210721.00.00"},{"key":"yt_li","value":"1"},{"key":"GetPlayer_rid","value":"0x26272868f40dcaf5"}]},{"service":"GUIDED_HELP","params":[{"key":"logged_in","value":"1"}]},{"service":"ECATCHER","params":[{"key":"client.version","value":"2.20210721"},{"key":"client.name","value":"WEB"}]}],"mainAppWebResponseContext":{"datasyncId":"103277725654256864760||","loggedOut":false},"webResponseContextExtensionData":{"hasDecorated":true}},"playabilityStatus":{"status":"AGE_VERIFICATION_REQUIRED","errorScreen":{"playerErrorMessageRenderer":{"subreason":{"runs":[{"text":"Dokončite krátku kontrolu, či máte dostatočný vek na pozeranie tohto videa. "},{"text":"Ďalšie informácie","navigationEndpoint":{"clickTrackingParams":"CAAQu2kiEwjr3IOdtv7xAhWGpFUKHWLADLw=","commandMetadata":{"webCommandMetadata":{"url":"https://support.google.com/youtube?p=watching_arv\u0026hl=sk","webPageType":"WEB_PAGE_TYPE_UNKNOWN","rootVe":83769}},"urlEndpoint":{"url":"https://support.google.com/youtube?p=watching_arv\u0026hl=sk"}}}]},"reason":{"runs":[{"text":"Overte svoj vek"}]},"proceedButton":{"buttonRenderer":{"style":"STYLE_WHITE_WITH_BORDER","size":"SIZE_DEFAULT","isDisabled":false,"text":{"runs":[{"text":"Overiť"}]},"trackingParams":"CAEQrfIGIhMI69yDnbb-8QIVhqRVCh1iwAy8","command":{"clickTrackingParams":"CAEQrfIGIhMI69yDnbb-8QIVhqRVCh1iwAy8","commandMetadata":{"webCommandMetadata":{"url":"https://myaccount.google.com/age-verification?utm_source=YT_WEB\u0026utm_medium=watch_link\u0026utm_campaign=watch_verify_prompt\u0026authuser=0\u0026continue=https%3A//youtube.com/watch%3Fv%3DdmJefsOErr0%26pp%3DQADoAwE%253D","webPageType":"WEB_PAGE_TYPE_UNKNOWN","rootVe":83769}},"urlEndpoint":{"url":"https://myaccount.google.com/age-verification?utm_source=YT_WEB\u0026utm_medium=watch_link\u0026utm_campaign=watch_verify_prompt\u0026authuser=0\u0026continue=https%3A//youtube.com/watch%3Fv%3DdmJefsOErr0%26pp%3DQADoAwE%253D"}}}},"icon":{"iconType":"ERROR_OUTLINE"}}},"desktopLegacyAgeGateReason":9,"contextParams":"Q0FFU0FnZ0I="},"videoDetails":{"videoId":"dmJefsOErr0","title":"Rae Sremmurd - Swang (Official Video)","lengthSeconds":"229","keywords":["Sremmurd","Swang","Eardruma/Interscope","rae sremmurd swang","rae sremmurd black beatles lyrics","rae sremmurd look alive","rae sremmurd mannequin challenge","rae sremmurd come get her","rae sremmurd no type","rae sremmurd","rae sremmurd black beatles","SremmLife 2","SremmLife 2 rae sremmurd","SremmLife","swang lyrics rae sremmurd","swang music video","swang lyrics","swang clean lyrics","slim jimmy"],"channelId":"UCweazuUMMKdL2wwSyrxla9A","isOwnerViewing":false,"shortDescription":"Rae Sremmurd “SremmLife 2” available now\niTunes: http://smarturl.it/SremmLife2\nApple Music: http://smarturl.it/SremmLife2.AP\nGoogle Play: http://smarturl.it/SremmLife2.GP\nAmazon: http://smarturl.it/SremmLife2.AMZ\nSpotify: http://smarturl.it/SremmLife2.SP\nTarget (includes 2 bonus tracks): Sremmlife 2: http://smarturl.it/Sremmlife2.Tgt \nRae Sremmurd newsletter: http://smarturl.it/RaeSremmurd.News \n\nStream “Swang” http://smarturl.it/Swang.sp\n\nMusic video by Rae Sremmurd performing Swang. (C) 2016 Eardruma/Interscope Records\n\n#RaeSremmurd #Swang #Vevo","isCrawlable":true,"thumbnail":{"thumbnails":[{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEbCKgBEF5IVfKriqkDDggBFQAAiEIYAXABwAEG\u0026rs=AOn4CLAZIwDhvRNE4vIe5g05pwPBKFNuQg","width":168,"height":94},{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEbCMQBEG5IVfKriqkDDggBFQAAiEIYAXABwAEG\u0026rs=AOn4CLCLK2nzQjD445NB2nejSpOtWO4TBA","width":196,"height":110},{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==\u0026rs=AOn4CLBOZf9Zdn4zwoeuZG1iCuUVUoOZQw","width":246,"height":138},{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==\u0026rs=AOn4CLBLDcI0JNk9UC4nviLHzrlcph4WcA","width":336,"height":188},{"url":"https://i.ytimg.com/vi_webp/dmJefsOErr0/maxresdefault.webp","width":1920,"height":1080}]},"averageRating":4.7515512,"allowRatings":true,"viewCount":"464114651","author":"RaeSremmurdVEVO","isPrivate":false,"isUnpluggedCorpus":false,"isLiveContent":false},"microformat":{"playerMicroformatRenderer":{"thumbnail":{"thumbnails":[{"url":"https://i.ytimg.com/vi/dmJefsOErr0/maxresdefault.jpg","width":1280,"height":720}]},"embed":{"iframeUrl":"https://www.youtube.com/embed/dmJefsOErr0","flashUrl":"http://www.youtube.com/v/dmJefsOErr0?version=3\u0026autohide=1","width":1280,"height":720,"flashSecureUrl":"https://www.youtube.com/v/dmJefsOErr0?version=3\u0026autohide=1"},"title":{"simpleText":"Rae Sremmurd - Swang (Official Video)"},"description":{"simpleText":"Rae Sremmurd “SremmLife 2” available now\niTunes: http://smarturl.it/SremmLife2\nApple Music: http://smarturl.it/SremmLife2.AP\nGoogle Play: http://smarturl.it/SremmLife2.GP\nAmazon: http://smarturl.it/SremmLife2.AMZ\nSpotify: http://smarturl.it/SremmLife2.SP\nTarget (includes 2 bonus tracks): Sremmlife 2: http://smarturl.it/Sremmlife2.Tgt \nRae Sremmurd newsletter: http://smarturl.it/RaeSremmurd.News \n\nStream “Swang” http://smarturl.it/Swang.sp\n\nMusic video by Rae Sremmurd performing Swang. (C) 2016 Eardruma/Interscope Records\n\n#RaeSremmurd #Swang #Vevo"},"lengthSeconds":"229","ownerProfileUrl":"http://www.youtube.com/user/RaeSremmurdVEVO","externalChannelId":"UCweazuUMMKdL2wwSyrxla9A","isFamilySafe":false,"isUnlisted":false,"hasYpcMetadata":false,"viewCount":"464114651","category":"Music","publishDate":"2017-02-16","ownerChannelName":"RaeSremmurdVEVO","uploadDate":"2017-02-16"}},"trackingParams":"CAAQu2kiEwjr3IOdtv7xAhWGpFUKHWLADLw=","frameworkUpdates":{"entityBatchUpdate":{"mutations":[{"entityKey":"Eg0KC2RtSmVmc09FcnIwIPYBKAE%3D","type":"ENTITY_MUTATION_TYPE_REPLACE","payload":{"offlineabilityEntity":{"key":"Eg0KC2RtSmVmc09FcnIwIPYBKAE%3D","accessState":"OFFLINEABILITY_FEATURE_ACCESS_STATE_UNKNOWN"}}}],"timestamp":{"seconds":"1627223046","nanos":70852067}}}}

This is data that ytdl-core recieve every time that you try to play song or you use .getInfo but you can search as much as you want for video formats but you will not find it. It meens that ytdl-core does not have any format available to download stream and it will create corupted URL like "null" or "undefined" so we found problem. Now to the solution. We need to create ALT accounts on google in ordet to create youtube VERIFIED accounts. Then you need to copy the cookies and x-user-data header of https://www.youtube.com site with that account becouse cookies and x-user-data header includes access token of account. We need to put that cookies into array. Let's say that it's named "ytAltCookies".

var ytAltCookies = [["cookies1", "x-user-data1"], ["cookies2", "x-user-data2"], ...];  //Make as many accounts as you want

Then we need to use these account in our ytdl-core request so it will return correct video info with video formats. And to switch between these accouns in ordet not to get too many requests error we need to switch these accouns constantly. Edid your code whereever you are using "ytdl(url)" for downloading stream with code below.

var cookies = ytAltCookies[0];
ytAltCookies.push(ytAltCookies.shift()); //Remove this cookies from start of array and put it on the end of array
ytdl("<ytURL", {
  requestOptions: {
    headers: {
      Cookie: cookies[0],
      'x-user-data': cookies[1]
    }
  }
});

Now ytdl-core should reqeust youtube site with these cookies and as age verified account. I didn't test it becouse I kind of can't verifie accout for myself so it is possible that it is not perfect solution.

To prevent making too many requests please check if video is age restricted and use these cookies only when video is age restricted becouse you could get too many reqeusts error really easy.

Edit: You need to use x-user-data header too.

Hello, I wonder is it necessary for the yt accounts to be verified and also how do I find the headers and cookies I'm searching for? Thanks in advance.

ProGamer2711 commented 3 years ago

Did you mean the "X-Youtube-Identity-Token" header? @Nico-ITA

gabcaua commented 3 years ago

I can't find "x-user-data" cookie

EPXOL commented 3 years ago

For all who cant find these data required

Cookies:

Open any youtube video in browser.Go to dev tools. Go to dev tools. Open console. And type: "document.cookie"

Header:

Open any youtube video in browser.Go to dev tools. Open network. Press F5 for reload. Select 1st request created. Find "Request Headers" category. And there you can find the "x-user-data" header.

EPXOL commented 3 years ago

When requesting this video from browser it returns this data:

{"responseContext":{"serviceTrackingParams":[{"service":"GFEEDBACK","params":[{"key":"is_viewed_live","value":"False"},{"key":"logged_in","value":"1"},{"key":"e","value":"23946420,24037794,24057628,24068193,24074909,23984880,24045411,24007246,23918597,24016724,24016285,24002022,23986032,23891346,23996830,24049820,24059521,23857950,24071362,24050503,23884386,23804281,24032277,24042870,24056264,23934970,24001373,24030040,24049571,24069707,24042738,23971645,24058380,23966208,23885490,24049573,24058812,23983813,23998056,23974595,24056275,23891344,24053866,24043240,24004644,24060921,23937619,23940237,23744176,24002025,1714247,24028143,24056704,24059975,23968386,24070166,23996512,24058128,23843508,24070073,23944779,23983296,24068842,23882685,24036948,24034978,24057238"}]},{"service":"CSI","params":[{"key":"c","value":"WEB"},{"key":"cver","value":"2.20210721.00.00"},{"key":"yt_li","value":"1"},{"key":"GetPlayer_rid","value":"0x26272868f40dcaf5"}]},{"service":"GUIDED_HELP","params":[{"key":"logged_in","value":"1"}]},{"service":"ECATCHER","params":[{"key":"client.version","value":"2.20210721"},{"key":"client.name","value":"WEB"}]}],"mainAppWebResponseContext":{"datasyncId":"103277725654256864760||","loggedOut":false},"webResponseContextExtensionData":{"hasDecorated":true}},"playabilityStatus":{"status":"AGE_VERIFICATION_REQUIRED","errorScreen":{"playerErrorMessageRenderer":{"subreason":{"runs":[{"text":"Dokončite krátku kontrolu, či máte dostatočný vek na pozeranie tohto videa. "},{"text":"Ďalšie informácie","navigationEndpoint":{"clickTrackingParams":"CAAQu2kiEwjr3IOdtv7xAhWGpFUKHWLADLw=","commandMetadata":{"webCommandMetadata":{"url":"https://support.google.com/youtube?p=watching_arv\u0026hl=sk","webPageType":"WEB_PAGE_TYPE_UNKNOWN","rootVe":83769}},"urlEndpoint":{"url":"https://support.google.com/youtube?p=watching_arv\u0026hl=sk"}}}]},"reason":{"runs":[{"text":"Overte svoj vek"}]},"proceedButton":{"buttonRenderer":{"style":"STYLE_WHITE_WITH_BORDER","size":"SIZE_DEFAULT","isDisabled":false,"text":{"runs":[{"text":"Overiť"}]},"trackingParams":"CAEQrfIGIhMI69yDnbb-8QIVhqRVCh1iwAy8","command":{"clickTrackingParams":"CAEQrfIGIhMI69yDnbb-8QIVhqRVCh1iwAy8","commandMetadata":{"webCommandMetadata":{"url":"https://myaccount.google.com/age-verification?utm_source=YT_WEB\u0026utm_medium=watch_link\u0026utm_campaign=watch_verify_prompt\u0026authuser=0\u0026continue=https%3A//youtube.com/watch%3Fv%3DdmJefsOErr0%26pp%3DQADoAwE%253D","webPageType":"WEB_PAGE_TYPE_UNKNOWN","rootVe":83769}},"urlEndpoint":{"url":"https://myaccount.google.com/age-verification?utm_source=YT_WEB\u0026utm_medium=watch_link\u0026utm_campaign=watch_verify_prompt\u0026authuser=0\u0026continue=https%3A//youtube.com/watch%3Fv%3DdmJefsOErr0%26pp%3DQADoAwE%253D"}}}},"icon":{"iconType":"ERROR_OUTLINE"}}},"desktopLegacyAgeGateReason":9,"contextParams":"Q0FFU0FnZ0I="},"videoDetails":{"videoId":"dmJefsOErr0","title":"Rae Sremmurd - Swang (Official Video)","lengthSeconds":"229","keywords":["Sremmurd","Swang","Eardruma/Interscope","rae sremmurd swang","rae sremmurd black beatles lyrics","rae sremmurd look alive","rae sremmurd mannequin challenge","rae sremmurd come get her","rae sremmurd no type","rae sremmurd","rae sremmurd black beatles","SremmLife 2","SremmLife 2 rae sremmurd","SremmLife","swang lyrics rae sremmurd","swang music video","swang lyrics","swang clean lyrics","slim jimmy"],"channelId":"UCweazuUMMKdL2wwSyrxla9A","isOwnerViewing":false,"shortDescription":"Rae Sremmurd “SremmLife 2” available now\niTunes: http://smarturl.it/SremmLife2\nApple Music: http://smarturl.it/SremmLife2.AP\nGoogle Play: http://smarturl.it/SremmLife2.GP\nAmazon: http://smarturl.it/SremmLife2.AMZ\nSpotify: http://smarturl.it/SremmLife2.SP\nTarget (includes 2 bonus tracks): Sremmlife 2: http://smarturl.it/Sremmlife2.Tgt \nRae Sremmurd newsletter: http://smarturl.it/RaeSremmurd.News \n\nStream “Swang” http://smarturl.it/Swang.sp\n\nMusic video by Rae Sremmurd performing Swang. (C) 2016 Eardruma/Interscope Records\n\n#RaeSremmurd #Swang #Vevo","isCrawlable":true,"thumbnail":{"thumbnails":[{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEbCKgBEF5IVfKriqkDDggBFQAAiEIYAXABwAEG\u0026rs=AOn4CLAZIwDhvRNE4vIe5g05pwPBKFNuQg","width":168,"height":94},{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEbCMQBEG5IVfKriqkDDggBFQAAiEIYAXABwAEG\u0026rs=AOn4CLCLK2nzQjD445NB2nejSpOtWO4TBA","width":196,"height":110},{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==\u0026rs=AOn4CLBOZf9Zdn4zwoeuZG1iCuUVUoOZQw","width":246,"height":138},{"url":"https://i.ytimg.com/vi/dmJefsOErr0/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==\u0026rs=AOn4CLBLDcI0JNk9UC4nviLHzrlcph4WcA","width":336,"height":188},{"url":"https://i.ytimg.com/vi_webp/dmJefsOErr0/maxresdefault.webp","width":1920,"height":1080}]},"averageRating":4.7515512,"allowRatings":true,"viewCount":"464114651","author":"RaeSremmurdVEVO","isPrivate":false,"isUnpluggedCorpus":false,"isLiveContent":false},"microformat":{"playerMicroformatRenderer":{"thumbnail":{"thumbnails":[{"url":"https://i.ytimg.com/vi/dmJefsOErr0/maxresdefault.jpg","width":1280,"height":720}]},"embed":{"iframeUrl":"https://www.youtube.com/embed/dmJefsOErr0","flashUrl":"http://www.youtube.com/v/dmJefsOErr0?version=3\u0026autohide=1","width":1280,"height":720,"flashSecureUrl":"https://www.youtube.com/v/dmJefsOErr0?version=3\u0026autohide=1"},"title":{"simpleText":"Rae Sremmurd - Swang (Official Video)"},"description":{"simpleText":"Rae Sremmurd “SremmLife 2” available now\niTunes: http://smarturl.it/SremmLife2\nApple Music: http://smarturl.it/SremmLife2.AP\nGoogle Play: http://smarturl.it/SremmLife2.GP\nAmazon: http://smarturl.it/SremmLife2.AMZ\nSpotify: http://smarturl.it/SremmLife2.SP\nTarget (includes 2 bonus tracks): Sremmlife 2: http://smarturl.it/Sremmlife2.Tgt \nRae Sremmurd newsletter: http://smarturl.it/RaeSremmurd.News \n\nStream “Swang” http://smarturl.it/Swang.sp\n\nMusic video by Rae Sremmurd performing Swang. (C) 2016 Eardruma/Interscope Records\n\n#RaeSremmurd #Swang #Vevo"},"lengthSeconds":"229","ownerProfileUrl":"http://www.youtube.com/user/RaeSremmurdVEVO","externalChannelId":"UCweazuUMMKdL2wwSyrxla9A","isFamilySafe":false,"isUnlisted":false,"hasYpcMetadata":false,"viewCount":"464114651","category":"Music","publishDate":"2017-02-16","ownerChannelName":"RaeSremmurdVEVO","uploadDate":"2017-02-16"}},"trackingParams":"CAAQu2kiEwjr3IOdtv7xAhWGpFUKHWLADLw=","frameworkUpdates":{"entityBatchUpdate":{"mutations":[{"entityKey":"Eg0KC2RtSmVmc09FcnIwIPYBKAE%3D","type":"ENTITY_MUTATION_TYPE_REPLACE","payload":{"offlineabilityEntity":{"key":"Eg0KC2RtSmVmc09FcnIwIPYBKAE%3D","accessState":"OFFLINEABILITY_FEATURE_ACCESS_STATE_UNKNOWN"}}}],"timestamp":{"seconds":"1627223046","nanos":70852067}}}}

This is data that ytdl-core recieve every time that you try to play song or you use .getInfo but you can search as much as you want for video formats but you will not find it. It meens that ytdl-core does not have any format available to download stream and it will create corupted URL like "null" or "undefined" so we found problem. Now to the solution. We need to create ALT accounts on google in ordet to create youtube VERIFIED accounts. Then you need to copy the cookies and x-user-data header of https://www.youtube.com site with that account becouse cookies and x-user-data header includes access token of account. We need to put that cookies into array. Let's say that it's named "ytAltCookies".

var ytAltCookies = [["cookies1", "x-user-data1"], ["cookies2", "x-user-data2"], ...];  //Make as many accounts as you want

Then we need to use these account in our ytdl-core request so it will return correct video info with video formats. And to switch between these accouns in ordet not to get too many requests error we need to switch these accouns constantly. Edid your code whereever you are using "ytdl(url)" for downloading stream with code below.

var cookies = ytAltCookies[0];
ytAltCookies.push(ytAltCookies.shift()); //Remove this cookies from start of array and put it on the end of array
ytdl("<ytURL", {
  requestOptions: {
    headers: {
      Cookie: cookies[0],
      'x-user-data': cookies[1]
    }
  }
});

Now ytdl-core should reqeust youtube site with these cookies and as age verified account. I didn't test it becouse I kind of can't verifie accout for myself so it is possible that it is not perfect solution.

To prevent making too many requests please check if video is age restricted and use these cookies only when video is age restricted becouse you could get too many reqeusts error really easy.

Edit: You need to use x-user-data header too.

Hello, I wonder is it necessary for the yt accounts to be verified and also how do I find the headers and cookies I'm searching for? Thanks in advance.

Yes it is necesary we download age-restricted video as the verified accout. you need to have verified accout for this.

EPXOL commented 3 years ago

Did you mean the "X-Youtube-Identity-Token" header? @Nico-ITA

Its document cookies and x-user-data. It includes verification details for accout. But if you know a way to use X-Youtube-Identify-Token you can use it.