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

Does not work with channelId but it works liveId #67

Open
Khyretos opened this issue Dec 2, 2021 · 10 comments
Open

Does not work with channelId but it works liveId #67

Khyretos opened this issue Dec 2, 2021 · 10 comments

Comments

@Khyretos
Copy link

Khyretos commented Dec 2, 2021

it does not work when i put my channel id:

//const liveChat = new LiveChat({ liveId: "0cWertczhs0" })
const liveChat = new LiveChat({ channelId: "UC8v86z0UWlgIg-foURD1Lyw" })

const ok = liveChat.start()

// Emit at start of observation chat.
// liveId: string
liveChat.on("start", (liveId) => {
    /* Your code here! */
    console.log("1");
})

// Emit at end of observation chat.
// reason: string?
liveChat.on("end", (reason) => {
    /* Your code here! */
    console.log("2");
})

// Emit at receive chat.
// chat: ChatItem
liveChat.on("chat", (chatItem) => {
    /* Your code here! */
    console.log("3");
})

// Emit when an error occurs
// err: Error or any
liveChat.on("error", (err) => {
    /* Your code here! */
    console.log("4");
})

// Start fetch loop

if (!ok) {
    console.log("Failed to start, check emitted error")
}

error:

D:\999 - OS\Documents\LoquendoBotV2\node_modules\axios\lib\adapters\xhr.js:210 GET https://consent.youtube.com/m?continue=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC8v86z0UWlgIg-foURD1Lyw%2Flive&gl=NL&m=0&pc=yt&uxe=23983171&hl=en&src=1 403

@neverclear86
Copy link
Collaborator

umm...

Your code works on my PC...

@Khyretos
Copy link
Author

Khyretos commented Dec 3, 2021

When i created mine with python i had to send this:

# Header needs to be send in order to get response
headers = {
    'Accept-Language': 'en-US,en;q=0.8',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0',
}

# Cookie needs to be send in order to get response
cookies={
    'CONSENT': 'YES+42'
}

maybe that is missing for me since i use it in electron.

@Khyretos
Copy link
Author

Khyretos commented Dec 4, 2021

can i modify your code to insert these headers and cookies to see if it works?
where do i need to add this?

@neverclear86
Copy link
Collaborator

I tested whether the header was necessary or not, but it worked without it, so I don't specify it now.

@Khyretos
Copy link
Author

Khyretos commented Dec 5, 2021

can you send me the code with the headers to test it on my end? maybe its just a issue for me.

@Khyretos
Copy link
Author

Khyretos commented Dec 5, 2021

or a different branch so i can test it

@neverclear86
Copy link
Collaborator

You can specify a header in requests.ts

@Khyretos
Copy link
Author

Khyretos commented Dec 8, 2021

I figured it out:

in my country you need to confirm a dialog before opening youtube:
image

i tried it with postman and these are the headers i need to send:

'cache-control': 'no-cache',
Connection: 'keep-alive',
Cookie: 'CONSENT=YES+42',
Host: 'www.youtube.com',
'Postman-Token': '22881d06-be4b-4ff5-9e91-67ce106f8379,151619c9-a51e-4f11-9318-2961809b2fa4',
'Cache-Control': 'no-cache',
Accept: '*/*',
'User-Agent': 'PostmanRuntime/7.17.1',

but if i try to send these headers with the npm package axios i get this:

const axiosConfig = {
headers: {
	'content-Type': 'application/json',
	Accept: '/',
	'cache-control': 'no-cache',
	Connection: 'keep-alive',
	Cookie: 'CONSENT=YES+42',
	Host: 'www.youtube.com',
	'Postman-Token': '22881d06-be4b-4ff5-9e91-67ce106f8379,151619c9-a51e-4f11-9318-2961809b2fa4',
	'Cache-Control': 'no-cache',
	'User-Agent': 'PostmanRuntime/7.17.1',
},
credentials: 'same-origin',
};
axios.defaults.withCredentials = true;
axios.get(
`https://www.youtube.com/channel/${channelId}/live`,
axiosConfig,
)
.then((res) => {
// Some result here
	console.log(res);
})
.catch((err) => {
	console.log(err);
});

image

and when i do it with npm package request it is a success:

	const options = {
		method: 'GET',
		url: `https://www.youtube.com/channel/${channelId}/live`,
		headers:
		{
			'cache-control': 'no-cache',
			Connection: 'keep-alive',
			Cookie: 'CONSENT=YES+42',
			Host: 'www.youtube.com',
			'Postman-Token': '22881d06-be4b-4ff5-9e91-67ce106f8379,151619c9-a51e-4f11-9318-2961809b2fa4',
			'Cache-Control': 'no-cache',
			Accept: '*/*',
			'User-Agent': 'PostmanRuntime/7.17.1',
		},
	};

	request(options, (error, response, body) => {
		if (error) throw new Error(error);

		const soup = new JsSoup(body, false);

		const livestreamLink = soup.findAll('link', { rel: 'canonical' });
		console.log(livestreamLink);

	});
}

you can close the case if you want but if other people use your package it will need to get updated.

@neverclear86
Copy link
Collaborator

I see...
I didn't notice it because there is no dialog in Japan. 😞
I have a plan to replace axios with another library, so I'm sorry, but I'll think about it a bit.

@rodrigograca31
Copy link

Mine was working with channelId then stopped working but worked with liveId and now I went back and works with channelId again so I guess its some caching or something?

maybe when using channelId it tries to get the live but because its a parser it gets the previous live that is cached and then doesnt work? 🤔

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

No branches or pull requests

3 participants