Could not get n-parameter function
I am using below implementation to retrieve VideoInfosWithDownloadFormatsResponse:
func getVideoDownloadFormats(videoID: String) async {
let YTM = YouTubeModel()
let dataParameters: [HeadersList.AddQueryInfo.ContentTypes : String] = [
.query: videoID]
do {
let response = try await VideoInfosWithDownloadFormatsResponse.sendThrowingRequest(
youtubeModel: YTM,
data: dataParameters
)
for format in response.downloadFormats {
print("URL: \(format.url?.absoluteString ?? "nil"), Quality: \(format.mimeType)")
}
} catch {
print("❌ Failed to fetch formats: \(error)")
}
}
but it fails with below error:
❌ Failed to fetch formats: ResponseError(step: YouTubeKit.VideoInfosWithDownloadFormatsResponse.ResponseError.StepType.scrapPlayer, reason: "Could not get n-parameter function.")
Am i doing it right?
Hello, yes you did it alright, the reason of the fail is that YouTube changes their "n-parameter" function all the time, including its "shape", making it more difficult to extract. As I don't really have the time to adapt the code every time, this function can fail as you've seen. I will try to fix this issue soon. In the meantime, I recommend that you use the base HLS stream that contains audio-only and video tracks (you need to extract them manually in turn.m3u8).