Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with Restricted URLs in getStreamingData on Netlify (Only Some Videos) #828

Open
LArroyoS opened this issue Dec 4, 2024 · 5 comments
Labels
question Further information is requested

Comments

@LArroyoS
Copy link

LArroyoS commented Dec 4, 2024

Question

Hello everyone,

I am working on a YouTube client for Roku and I am experiencing a problem with some videos that are restricted when I use getStreamingData. The URL I get is restricted, but this only happens with some videos and on the server I set up on Netlify. When I make the same request from my local server on my laptop, the link is not restricted.

I want to know if this has happened to you, and if so, how you solved it.

For me, most videos work on my Netlify server except for a few specific ones.

Thanks in advance for your help!

Other details

My Code

const youtubei = require('youtubei.js');

const { Innertube } = youtubei
const credentials = { /* My credentials */ }

const VideoRequest = async (req, res) => {
    const { query } = req
    const { id = "" } = query
    
    let expired = false
    
    try{
        const innertube = await Innertube.create();
    
        const timeout = setTimeout(() => { 
            expired = true
            res.status(408).json({ error: "Request Timeout" });  
        }, 10000);

        await innertube.session.signIn(credentials)
        .catch(err => { 
            console.error('Error al iniciar sesión:', err); 
            res.setHeader('logout', true);
            return; 
        });
        
        clearTimeout(timeout)
    
        const video = await innertube.getStreamingData(id, { format: "mp4", type: "video+audio", quality: "bestefficiency" }).catch(err => { })
        const info = await innertube.getInfo(id).catch(err => console.error(err))
    
        const { basic_info = {}, primary_info = {}, streaming_data = {} } = info
    
        const videoData = { ...primary_info, ...basic_info, ...(video || streaming_data) }


        try{
            await info.addToWatchHistory()
        }
        catch(err) { 
            console.error('No se pudo agregar al historial de reproducción:', err.message);
        }
        console.log("My video ", video)
        console.log("My info ", info)

        if(!expired){
            return res.json({
                id: videoData.id ?? 'ID no disponible',
                title: videoData.title?.text ?? videoData.title ?? 'Título no disponible',
                duration: videoData.duration ?? 'Duración no disponible',
                thumbnails: videoData.thumbnail?.pop()?.url ?? 'URL no disponible',
                author_id: videoData.channel_id ?? 'ID de autor no disponible',
                author_name: videoData.author ?? 'Nombre de autor no disponible',
                published: videoData.relative_date?.text ?? videoData.published?.text ?? 'Fecha de publicación no disponible',
                short_view_count: videoData.short_view_count?.text ?? videoData.view_count?.text ?? 'Conteo de vistas no disponible',
                video_url: videoData.url ?? videoData.hls_manifest_url ?? 'Video no disponible',
                video_quality: videoData.quality_label ?? "Calidad no disponible"
            })
        }
    }
    catch (err) { 
        console.error('Error Video:', err); 
        return res.status(500).json({ error: "Internal Server Error" }); 
    }
}```

![image](https://github.com/user-attachments/assets/2c8ecddf-df65-48b1-a313-40504c62a707)

Image Message
Access denied to rr1---sn-p5qddn7r.googlevideo.comYou do not have user rights to view this page. HTTP ERROR 403

### Checklist

- [X] I am running the latest version.
- [X] I checked the documentation and found no answer.
- [X] I have searched the existing issues and made sure this is not a duplicate.
- [X] I have provided sufficient information.
@LArroyoS LArroyoS added the question Further information is requested label Dec 4, 2024
@LuanRT
Copy link
Owner

LuanRT commented Dec 4, 2024

It could be that they're blocking the server's IP, but you say it only happens with some videos so I'm not sure.. Have you tried changing the default client the getInfo function uses? (second parameter)

@LArroyoS
Copy link
Author

LArroyoS commented Dec 4, 2024

It could be that they're blocking the server's IP, but you say it only happens with some videos so I'm not sure.. Have you tried changing the default client the getInfo function uses? (second parameter)

Sorry for my inexperience, I am new to these topics, so I don't know if you could explain or share a link about the following questions.

  • How does changing the InnerTubeClient modify the behavior of data retrieval?
  • I was intrigued by what you mentioned about IP blocking. What is that, and how can I prevent it from happening to me?

@LArroyoS
Copy link
Author

LArroyoS commented Dec 4, 2024

It could be that they're blocking the server's IP, but you say it only happens with some videos so I'm not sure.. Have you tried changing the default client the getInfo function uses? (second parameter)

I changed the InnertubeClient to TV, but the result is the same.

To show my example:

This is the URL that is denied:

https://rr3---sn-p5qlsn7d.googlevideo.com/videoplayback?expire=1733373590&ei=NtpQZ6mDM_qAkucPwom18A8&ip=98.82.32.153&id=o-ADmFvL0iPOq8e_9YDY5Fkr8tTVISR27f60tNPr-njfhN&itag=18&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&met=1733351990%2C&mh=A7&mm=31%2C26&mn=sn-p5qlsn7d%2Csn-ab5sznzk&ms=au%2Conr&mv=m&mvi=3&pl=13&rms=au%2Cau&gcr=us&initcwndbps=4052500&siu=1&bui=AQn3pFRJz6Kj4dAv4OV_2ffD5OUkFl7fcOWMNbCqyO4dqR3V3ksUEawpA9Sl32mmM2bl6LA_7g&spc=qtApAZlOhKU1T4JnKmhVQI97__uaJZB4rDvTWkke2nOahF6LPKEyN79BkDWegaCmYhi8MIQzF8Vu&vprv=1&svpuc=1&mime=video%2Fmp4&ns=e85l2DXznZv4NYyluPupXocQ&rqh=1&cnr=14&ratebypass=yes&dur=91.184&lmt=1724638832187310&mt=1733351595&fvip=5&fexp=51326932%2C51335594%2C51355912&c=WEB&sefc=1&txp=8218224&n=boNwaCmiDWdK8A&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cgcr%2Csiu%2Cbui%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Crqh%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AJfQdSswRQIhAKrNcf7j0G5fgrWo5ztcS-HcWqTuQXawyrBP1DJnNE2DAiADRSTY0ihU-1N_j4SeKX5c7PS8tkjBPwEKv9ADrlfMPg%3D%3D&lsparams=met%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Crms%2Cinitcwndbps&lsig=AGluJ3MwRgIhAMbK148AIZ_MvtptgpuHHostFfW_u_TpmpeyEt9m8nNfAiEA0c4XgeDjiFPNoJxEcWX-qKEXTbGVgnCa_lC71nD-bmQ%3D&cver=2.20240111.09.00

And this is another video obtained through my same API:

https://rr3---sn-p5qlsn7l.googlevideo.com/videoplayback?expire=1733373859&ei=Q9tQZ5XPHO65kucPucvxuA8&ip=98.82.32.153&id=o-AMtkhbTBmdWwGljDnYKY23wqt42iCJ8X9YaO11zNP-Ki&itag=18&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&met=1733352259%2C&mh=8x&mm=31%2C26&mn=sn-p5qlsn7l%2Csn-ab5l6nrz&ms=au%2Conr&mv=m&mvi=3&pl=13&rms=au%2Cau&initcwndbps=3905000&siu=1&bui=AQn3pFSOJ_0_JUk_1mKrGG3CaSglffz-YExV095111VPhxN1epQI08Sq3ep_LlelJ0uqVxpXqQ&spc=qtApAcoh-DxLAy8YRy175TIzSA9PZhKCL3Y3a-5fO9n-N10QYE_G2HYqTIjF36v14STpiwqe8F4l&vprv=1&svpuc=1&mime=video%2Fmp4&ns=B2uAE7LEbVcMSE5uWw-8otkQ&rqh=1&gir=yes&clen=7292904&ratebypass=yes&dur=78.994&lmt=1733341853179727&mt=1733351834&fvip=5&fexp=51326932%2C51335594%2C51355912&c=WEB&sefc=1&txp=5438434&n=eF37pqpKXD129g&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Csiu%2Cbui%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Crqh%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=AJfQdSswRAIgGw2cMBXVbil6TpUBC12y122HbG_jhBTOC7PXZjuGgokCIDWk3YDmPLltFnao4BY5XEnVWqG6thopnfq2jFeBFwOd&lsparams=met%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Crms%2Cinitcwndbps&lsig=AGluJ3MwRgIhAPHbuD6dpwzIFdqomXN1v0Fo6CUgq-IaFwkhz-65YcSUAiEAtB8WjFBxL-jtYdA8FD5fNhPJ3-NdwPWU4_JzfdRODKY%3D&cver=2.20240111.09.00

@LuanRT
Copy link
Owner

LuanRT commented Dec 5, 2024

Are you sure you changed to the TV client? In the streaming URL, it still says WEB.

@LArroyoS
Copy link
Author

LArroyoS commented Dec 5, 2024

Are you sure you changed to the TV client? In the streaming URL, it still says WEB.

You're right, I hadn't noticed that it still says WEB. According to my changes, it should be like this:

const video = await innertube.getStreamingData(id, { format: "mp4", type: "video+audio", quality: "bestefficiency", client: "TV" }).catch(err => { })
const info = await innertube.getInfo(id, "TV").catch(err => console.error(err))

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants