Skip to content

Conversation

@atpugvaraa
Copy link

Pull Request

Description

This implementation addresses the signature algorithm detection issue by implementing a fix based on YouTube.js PR #953. The solution uses a dynamic approach to find the global variable containing the signature algorithm instead of relying on hardcoded variable names, which makes the library more resilient to YouTube's frequent changes.

Related Issues

Changes Made

  • Updated the JavaScript extraction logic to dynamically detect the global variable used for signature algorithms
  • Added proper documentation to the js property explaining the new signature deciphering approach

Checklist

  • APIs have been properly documented (if relevant).
  • Documentation has been updated (if relevant).
  • New unit tests have been written (if relevant).

Out of scope

  • Extraction method: .remote is also broken (.local is preferred until a fix is pushed)

Additional Notes

  • The implementation tries to maintain compatibility with the existing codebase

P.S. This is my first real PR. I am still in a learning phase and moderate use of Artificial Intelligence has been made in order to fix this issue.

This implementation is based on the fix from YouTube.js PR #953 which uses a global variable to find the signature algorithm instead of relying on hardcoded variable names.
@jordibruin
Copy link

Thanks for finding a fix so quickly!

@manchan
Copy link

manchan commented Apr 28, 2025

There still seems to be an error.

Failed to decode object from given start point: 
pattern (ytplayer\.config\s*=\s*) failed: (YouTubeKit.YouTubeKitError1)
applying descrambler
YouTubeKit/RegularExpression.swift:16: Fatal error: Illegal regular expression var (\w+)={[^}]+}

@atpugvaraa
Copy link
Author

atpugvaraa commented Apr 28, 2025

Kind of found what the problem is...

Extraction.swift:61 
let configPatterns = [
    // NSRegularExpression(#"ytplayer\.config\s*=\s*(\{)"#), ---> Seems to be outdated. Hence should be commented out?
    NSRegularExpression(#"ytInitialPlayerResponse\s*=\s*(\{)"#)
]
  • I do not have proper error handling or Unit tests setup right now (don't know how to)
  • I am testing this package using an app and the error has seemed to have been "removed"

"Error fix"

NSRegularExpression(#"ytplayer\.config\s*=\s*(\{)"#), ---> Seems to be outdated. Hence commented out

Failed to decode object from given start point:
pattern (ytplayer\.config\s*=\s*) failed: (YouTubeKit.YouTubeKitError1)
applying descrambler
YouTubeKit/RegularExpression.swift:16: Fatal error: Illegal regular expression var (\w+)={[^}]+}
@fynn-bckr
Copy link

This still fails with pattern (ytInitialPlayerResponse\s*=\s*(\{)) failed: The operation couldn’t be completed. (YouTubeKit.YouTubeKitError error 1.) for me.

@chnbr
Copy link

chnbr commented Apr 28, 2025

I have now commit 76bc73f running, but still get these errors at runtime:

finding initial function name
pattern (ytInitialPlayerResponse\s*=\s*({)) failed: Der Vorgang konnte nicht abgeschlossen werden. (YouTubeKit.YouTubeKitError-Fehler 1.)
applying descrambler
Found global variable for signature algorithm: J
Using global variable: J
getting transform object
getting transform object
finding initial function name
pattern (ytInitialPlayerResponse\s*=\s*({)) failed: Der Vorgang konnte nicht abgeschlossen werden. (YouTubeKit.YouTubeKitError-Fehler 1.)
Found global variable for signature algorithm: J
Using global variable: J
getting transform object
getting transform object

@chnbr
Copy link

chnbr commented Apr 28, 2025

@alexeichhorn : Could you please also have a look into this issue. It seems that YTK is currently broken for most of us. Thx!

@alexeichhorn
Copy link
Owner

Hey @atpugvaraa, thanks for your work.
Unfortunately, it still gets a lot of errors in my tests.
I'm also working a bit on trying to find a solution. It just requires a lot of time, going through all the yt-dlp changes, and the necessary changes look quite significant. They will take time on my part.

@atpugvaraa
Copy link
Author

atpugvaraa commented Apr 29, 2025

@alexeichhorn thanks for looking into this, i still lack the necessary knowledge and experience to fix things, being only able to make it work locally (without proper error handling seems to be what happened)

Thanks a lot for YTK.

@chnbr
Copy link

chnbr commented May 3, 2025

Good morning, are there any news on this ?

Please keep us updated !

Thank you so much !!!

@alexeichhorn
Copy link
Owner

Internally, it's in a state where some videos work again, but most still have problems. Unfortunately, I just don't have much time currently to put into this.

@chnbr
Copy link

chnbr commented May 5, 2025

Internally, it's in a state where some videos work again, but most still have problems. Unfortunately, I just don't have much time currently to put into this.

We are very grateful that you initiated and maintain this project and we fully understand that time for open source projects is limited. But since we are using this in a commercial project we have to think about solution.

Are you aware of similar projects we could migrate to ?

What are the steps when you fix issues like this ?
Are you taking the codebase of ytdl as template and 'convert' it to Swift ?

Can we do something to 'incentivate' you ?

Regards
Christian

p.s. Nothing above is meant offensive ! Just thinking about options....

@fynn-bckr
Copy link

I've written a very hacky solution for this, see my comment in #78.

@alexeichhorn
Copy link
Owner

Please checkout #80 (or branch fix/youtube-may-25) and give some feedback if it works for you or not.

@alexeichhorn
Copy link
Owner

Internally, it's in a state where some videos work again, but most still have problems. Unfortunately, I just don't have much time currently to put into this.

We are very grateful that you initiated and maintain this project and we fully understand that time for open source projects is limited. But since we are using this in a commercial project we have to think about solution.

Are you aware of similar projects we could migrate to ?

What are the steps when you fix issues like this ? Are you taking the codebase of ytdl as template and 'convert' it to Swift ?

Can we do something to 'incentivate' you ?

Regards Christian

p.s. Nothing above is meant offensive ! Just thinking about options....

Fair question.
I usually use yt-dlp as a template, but their code structure and language limitations are so different from mine that it is sometimes extremely hard to just "copy over the changes." When I started this, I purposefully structured it very similarly to the "pytube" project, but pytube has stopped being maintained. So it has gotten harder. 😉

I have written some more things about the future of YouTubeKit in #82, where I also asked some questions. Would appreciate your input there.

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

Successfully merging this pull request may close these issues.

6 participants