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

[YouTube] Update iOS client and add visitor data to InnerTube requests #1262

Merged
merged 5 commits into from
Jan 21, 2025

Conversation

Theta-Dev
Copy link
Contributor

@Theta-Dev Theta-Dev commented Jan 19, 2025

I have fixed the issue with the iOS client returning invalid responses
Apparently the only issue with the iOS client is that we were not sending it visitor data cookies. Since the visitor data cookies are just protobuf objects with a random ID, timestamp and country code, they can be randomly generated and dont need to be fetched from YouTube.

Fixes #1259
Fixes TeamNewPipe/NewPipe#11934

@gechoto
Copy link
Contributor

gechoto commented Jan 19, 2025

Does it only work with visitor data for you? What happens only with an updated IOS client but no visitor data?

Btw the visitor data could also be extracted from https://www.youtube.com/sw.js_data

@Stypox
Copy link
Member

Stypox commented Jan 19, 2025

I just tested in NewPipe and it works, thank you!

@Theta-Dev
Copy link
Contributor Author

Yes, it only works with the visitor data cookie. I first tried updating the client version and the issue was still there.

You can extract the visitor data cookie from YouTube, but that requires an extra request. I have been using random visitor data cookies in my own YouTube client for a few months now and they work without issues.

@gechoto gechoto mentioned this pull request Jan 19, 2025
3 tasks
@gechoto
Copy link
Contributor

gechoto commented Jan 19, 2025

Yes, it only works with the visitor data

Okay. I closed my PR, let's go with visitor data. Cool stuff, thank you.

You can extract the visitor data cookie from YouTube, but that requires an extra request.

I know I wanted to leave this info here just in case as a backup plan. If the format of the visitor data changes your solution can break. Fetching it from YT ensures it will always follow the official and up-to-date format.
(But with that the extraction might fail at some point.)

I'm not sure what is better but the random generator seems okay for now.

visitor data cookie

just out of curiosity why do you refer to it as "cookie"?
I do not see this being handled or sent as a cookie in code. Am I missing something or is this due to translation problems / lack of a better word?

@Theta-Dev
Copy link
Contributor Author

YouTube does store the visitor data as a cookie (__Secure-YEC), but probably also in local storage so it can be sent as an API parameter by the player code. It fulfills the role of an unique session ID so I call it a cookie. I dont know if there are better terms for it.

@ShareASmile ShareASmile added bug Issue is related to a bug ASAP Issue needs to be fixed as soon as possible youtube service, https://www.youtube.com/ labels Jan 20, 2025
@Theta-Dev Theta-Dev force-pushed the fix/ios-client-vdata branch from 28a9bdf to 65d888f Compare January 21, 2025 02:06
@@ -222,28 +223,28 @@ private YoutubeParsingHelper() {
private static final String IOS_DEVICE_MODEL = "iPhone16,2";
Copy link
Contributor

@gechoto gechoto Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The device used here is an iPhone 15 Pro Max but the comments are incorrectly update to "iPhone 16".

Either change/revert the comments to iPhone 15 Pro Max or update the device model to "iPhone17,2" to match the iPhone 16 Pro Max.

The mapping can be found here: https://gist.github.com/adamawolf/3048717
or: https://theapplewiki.com/wiki/Firmware/iPhone/18.x#iPhone_16_Pro_Max

jdesgats added a commit to jdesgats/golang-youtube that referenced this pull request Jan 21, 2025
This is a nearly verbatim copy of [1], for now the code is pretty rough and
I'm not even sure that this data should be passed for all requests but it
does seem to unblock the iOS client for now.

[1] TeamNewPipe/NewPipeExtractor#1262
}
}
} catch (final IOException e) {
throw new RuntimeException(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: It may be better to use UncheckedIOException here since it's more specific
This might be also relevant for the rest of the file ;)

Copy link
Member

@litetex litetex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor things that I would change.
But anyway nice PR!

@@ -1256,6 +1275,7 @@ public static JsonBuilder<JsonObject> prepareIosMobileJsonBuilder(
.value("platform", "MOBILE")
.value("osName", "iOS")
.value("osVersion", IOS_OS_VERSION)
.value("visitorData", randomVisitorData(contentCountry))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be the same as vData?

Maybe add a short comment into the code that documents this

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class ProtoBuilder {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some documentation would be nice, e.g. what this class does

jdesgats added a commit to jdesgats/golang-youtube that referenced this pull request Jan 21, 2025
This is a nearly verbatim copy of [1], for now the code is pretty rough and
I'm not even sure that this data should be passed for all requests but it
does seem to unblock the iOS client for now.

[1] TeamNewPipe/NewPipeExtractor#1262
…youtube/YoutubeParsingHelper.java

Co-authored-by: Stypox <[email protected]>
Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you a lot! I am going to release a new version right now, as I don't have too much time in the next few days and don't want to keep users waiting. So I'm merging this PR despite there being some finishing touches to do still.

@Theta-Dev please open a new PR to address the review comments. And @litetex @gechoto please continue the review in the other PR that is going to be opened. And thanks for reviewing :-)

@Stypox Stypox merged commit 4c72032 into TeamNewPipe:dev Jan 21, 2025
3 checks passed
@jamesdrake101
Copy link

Thank you 💯 for fast-tracking this

@AudricV AudricV changed the title [YouTube] update iOS client, add visitor data to requests [YouTube] Update iOS client and add visitor data to InnerTube requests Jan 24, 2025
Stypox added a commit that referenced this pull request Jan 26, 2025
@Stypox
Copy link
Member

Stypox commented Feb 4, 2025

@Theta-Dev friendly reminder to open a follow-up PR to add more documentation

nonya123456 pushed a commit to nonya123456/youtube that referenced this pull request Feb 4, 2025
This is a nearly verbatim copy of [1], for now the code is pretty rough and
I'm not even sure that this data should be passed for all requests but it
does seem to unblock the iOS client for now.

[1] TeamNewPipe/NewPipeExtractor#1262
@Theta-Dev
Copy link
Contributor Author

Theta-Dev commented Feb 4, 2025

AFAIK using random visitor data IDs with the iOS client stopped working this week, so I guess we can remove the visitor data generator again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASAP Issue needs to be fixed as soon as possible bug Issue is related to a bug youtube service, https://www.youtube.com/
Projects
None yet
7 participants