muse icon indicating copy to clipboard operation
muse copied to clipboard

Age Restricted Youtube Video Support

Open bencorryp opened this issue 1 year ago • 7 comments

Is it possible to allow the bot to search (and play) age-restricted content on youtube? Could not find a setting on the generated API key to allow for age restricted content to be viewed.

bencorryp avatar Feb 10 '24 13:02 bencorryp

No, but happy to accept a PR for this.

codetheweb avatar Feb 12 '24 03:02 codetheweb

Afaik there's no way of directly accessing restricted videos from the YouTube API without being logged in. In other words, you'll have to pass a YouTube account credentials by exporting your browser cookies and passing it to the client. This incidentally also allows accessing private/membership required videos/streams as long as the credentials allows it.

Quick search through code tells me you need to pass the cookie as a header here https://github.com/codetheweb/muse/blob/cc1f18bc196fe1b5acb6023dc23ab42f43b41ba7/src/services/youtube-api.ts#L67-L73

and the generated header should look something like this

jogerj avatar May 17 '24 16:05 jogerj

What about the ytdl library? I've used ytdlp (Python fork) in some personal projects and age-restricted video downloads work as intended. Granted, I'm not sure how they do it, but it's probably not account credentials.

Happyllama25 avatar May 17 '24 16:05 Happyllama25

@Happyllama25 I've worked with yt-dlp before. Passing cookies to the client is the way. It's straight forward in code too, but since this project is written in typescript and doesn't rely on yt-dlp at all, we'll have to do on our own. But the proof of concept above should work.

Edit: you may have been on to something. It does work, sort-of by spoofing a TV client (?) Discussion on reddit here but apparently it's not foolproof if the owner of the video disables the option

jogerj avatar May 17 '24 17:05 jogerj

It does work, sort-of

Yes, it works for me on my bot, something I did notice though is it seems to take longer to download an age-restricted video than a non-restricted one - not 100% sure, I have not done a 1:1 test of this.

image

Happyllama25 avatar May 19 '24 03:05 Happyllama25

Afaik there's no way of directly accessing restricted videos from the YouTube API without being logged in. In other words, you'll have to pass a YouTube account credentials by exporting your browser cookies and passing it to the client. This incidentally also allows accessing private/membership required videos/streams as long as the credentials allows it.

Quick search through code tells me you need to pass the cookie as a header here https://github.com/codetheweb/muse/blob/cc1f18bc196fe1b5acb6023dc23ab42f43b41ba7/src/services/youtube-api.ts#L67-L73

and the generated header should look something like this

@jogerj Did you by any chance implement this fix and if so did it work? I tried doing it and there were a few files that needed tweaking before I could even test it out.

argjendzuh avatar Aug 20 '25 00:08 argjendzuh

@argjendzuh i've not looked into it and went with different solutions for music bot.

Anyways passing a cookie to yt-dlp just looks like this and this is documented here

This project uses ytdl-core (nothing to do with the youtube-api file I mentioned previously) , which supports this too. Just add where ytdl-core is used and pass cookies as described here and it should work

jogerj avatar Aug 20 '25 06:08 jogerj