13.4.0 - Download audio error
Steps to reproduce
My code:
import { Innertube, UniversalCache, Utils } from "youtubei.js";
import fs from "fs";
(async () => {
const videoId = "liDNey1UB-U";
const innertube = await Innertube.create({
cache: new UniversalCache(false),
generate_session_locally: true,
});
const outputPath = "output.mp3";
const audioStream = await innertube.download(videoId, {
type: "audio",
quality: "best",
client: "YTMUSIC",
});
const writeStream = fs.createWriteStream(outputPath);
for await (const chunk of Utils.streamToIterable(audioStream)) {
writeStream.write(chunk);
}
console.log("done");
})()
Failure Logs
Response (0 KB) {
ok: false,
url: "https://rr1---sn-8qj-nbo66.googlevideo.com/videoplayback?expire=1745507246&ei=Tv8JaOOVMM27ssUP9frb6QM&ip=14.252.145.48&id=o-AKIQupHFP_31CXlzP2M7aRim3N0mH0CcYlZJvlc9Z52j&itag=140&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&met=1745485646%2C&mh=L8&mm=31%2C26&mn=sn-8qj-nbo66%2Csn-oguesndz&ms=au%2Conr&mv=m&mvi=1&pl=20&rms=au%2Cau&initcwndbps=2515000&bui=AccgBcPqRWJH6vHCqlupXrGPv1iN6hEK-zbCnYUBUGV7LTkXJ3rbfEq9RdrhOGzXa1NtDBw3XH4pBlUv&spc=_S3wKnQ5tzrdCZZIpJ00AythWag0EF37tMtAHmug49sGs7f99qRY0PnNsiLqlitMKIg&vprv=1&svpuc=1&mime=audio%2Fmp4&ns=hoO5_aQlHjJkMkF0eyjmAiEQ&rqh=1&gir=yes&clen=3978687&dur=245.783&lmt=1744473045518816&mt=1745485280&fvip=1&keepalive=yes&c=WEB_REMIX&sefc=1&txp=6208224&n=RngStZHNf7p_Xg&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cbui%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Crqh%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=met%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Crms%2Cinitcwndbps&lsig=ACuhMU0wRQIhANFWhYdA0pq4Oe7-GpqtjZq2CXPrADv3D00xx7IZtA1nAiBxAmyKdhSoDAmCNhg2EBwhvwqkD5tm2QIhUNLtuh_gzg%3D%3D&sig=AJfQdSswRAIgXsmu5DS12o8w3xD6aw-3h1n60X2694lZ_ayR9yIB1RwCIHTi9FgUjm6gzNY668tVGbkNzotYnq9yLwuQYMlO3Di-&cver=1.20250219.01.00&cpn=WI4CY_Z28ie__B90&range=0-10485760",
status: 403,
statusText: "Forbidden",
headers: Headers {
"last-modified": "Wed, 02 May 2007 10:26:10 GMT",
"content-type": "text/plain",
"content-length": "0",
"connection": "close",
"access-control-allow-origin": "https://www.youtube.com",
"access-control-allow-credentials": "true",
"timing-allow-origin": "https://www.youtube.com",
"access-control-expose-headers": "Client-Protocol, Content-Length, Content-Type, X-Bandwidth-Est, X-Bandwidth-Est2, X-Bandwidth-Est3, X-Bandwidth-App-Limited, X-Bandwidth-Est-App-Limited, X-Bandwidth-Est-Comp, X-Bandwidth-Avg, X-Head-Time-Millis, X-Head-Time-Sec, X-Head-Seqnum, X-Response-Itag, X-Restrict-Formats-Hint, X-Sequence-Num, X-Segment-Lmt, X-Walltime-Ms",
"vary": "Origin",
"cross-origin-resource-policy": "cross-origin",
"x-content-type-options": "nosniff",
"date": "Thu, 24 Apr 2025 09:07:26 GMT",
"server": "gvs 1.0",
},
redirected: false,
bodyUsed: false,
Blob (0 KB)
}
16 | return shim;
17 | }
18 | }
19 | export class InnertubeError extends Error {
20 | constructor(message, info) {
21 | super(message);
^
error: The server responded with a non 2xx status code
info: {
"error_type": "FETCH_FAILED",
"response": {}
}
at new InnertubeError (/Users/thanhastraler/Desktop/VSCode/test/node_modules/youtubei.js/dist/src/utils/Utils.js:21:9)
at /Users/thanhastraler/Desktop/VSCode/test/node_modules/youtubei.js/dist/src/utils/FormatUtils.js:66:31
Expected behavior
Save file success
Current behavior
Throw error
Version
Default
Anything else?
No response
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.
I'm also having this issue. I tried two workarounds which used to work when I tried to reverse signatures myself, which include :
- changing my network (from Wifi to 4G) so I get a new IP address ;
- forcing a certain user agent : back in the days, some user agents had more success rate. I tried
com.google.android.youtube/17.36.4 (Linux; U; Android 12; GB) gzip.
None of which succeeded. So I don't think it's a ratelimit thing. What could it be ? An issue with the deciphering process ?
@Ximaz Make sure you're properly using PO tokens (required by nearly all WEB clients, and currently undergoing A/B testing on IOS).
@Ximaz Make sure you're properly using PO tokens (required by nearly all WEB clients, and currently undergoing A/B testing on IOS).
I've seen many time this term but I'm quite unsure about what is actually is, and whether it's hard to get. Can you tell me more or give a resource you read to understand them please ?