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

Fix all tests #882

Merged
merged 21 commits into from
Aug 23, 2022
Merged

Fix all tests #882

merged 21 commits into from
Aug 23, 2022

Conversation

litetex
Copy link
Member

@litetex litetex commented Jul 30, 2022

This PR fixes all tests.

It also introduces an option to change the YouTube consent cookie value, to allow fixing mixes extraction in EU.

Supersedes #871, fixes #820.

Stypox
Stypox previously requested changes Aug 4, 2022
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.

I rebased and added a commit for #877 (comment). Now all tests succeed on my PC. The code you changed also looks good; now we should handle ContentRequiredExceptions in NewPipe and allow users to grant consent.

@@ -73,8 +66,13 @@
import java.util.Random;
import java.util.regex.Pattern;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.schabi.newpipe.extractor.NewPipe.getDownloader;
Copy link
Member

@Stypox Stypox Aug 4, 2022

Choose a reason for hiding this comment

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

Why does your editor keep moving these around? (do not do anything about it, I just see a lot of these changes in your PRs)

Copy link
Member Author

@litetex litetex Aug 7, 2022

Choose a reason for hiding this comment

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

Looks like IntelliJ uses a different code style than Android studio (despite being based on the same IDE):
grafik

I will reconfigure my IntelliJ so that it uses Android Studio's settings.
I'm not sure what settings we should use here? IntelliJ's or Android Studios?

Maybe we should also track these settings in Git so that they are consistent between developers.

Copy link
Member Author

Choose a reason for hiding this comment

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

For now I used Android Studios code format, since it's already used in the files.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should also track these settings in Git so that they are consistent between developers.

Yeah, good idea. Could you do that, since you already looked into how it works? Thanks

Copy link
Member Author

Choose a reason for hiding this comment

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

Not in this PR but I created an issue: #892

@AudricV
Copy link
Member

AudricV commented Aug 4, 2022

The consent is only required for some playlists (#876) and mixes (#820) in EU.

That's why I'm strongly against allowing tracking in all YouTube requests we made. We should only do so where it is needed.

Remember that one of the main goals of the NewPipe projects is to enhance privacy.

@Stypox
Copy link
Member

Stypox commented Aug 4, 2022

Yes. This PR does not allow any new consent, as it is false by default.

@opusforlife2
Copy link
Collaborator

What I see is that the consent variable has been wrapped in a setter/getter. I assume this is so that other NPE consumers can easily show a consent prompt, e.g. Piped?

@litetex
Copy link
Member Author

litetex commented Aug 7, 2022

What I see is that the consent variable has been wrapped in a setter/getter. I assume this is so that other NPE consumers can easily show a consent prompt, e.g. Piped?

  1. Yes, in theory this should be possible now
  2. The variable is static so it's technically no getter or setter
  3. The static variable might change in the future for now it's primarily designed as a workaround so that the tests work again

@opusforlife2
Copy link
Collaborator

The variable is static so it's technically no getter or setter

I didn't get this bit.

@litetex
Copy link
Member Author

litetex commented Aug 12, 2022

@Stypox I'm done with my changes you can review again if you have time.

litetex and others added 13 commits August 14, 2022 14:48
The "Lofi Girl"-stream got interrupted by a copyright strike and had to be restarted. Because of this a new id is now used.
Also removed the unnecessary ``public``
Also removed the unnecessary ``public`` and reformatted the code a bit
* Removed the unnecessary ``public``
* Use parameterized tests
* One song got removed (which caused the test failure), replaced it with another song
The renderers and queries got changed.
Added option to choose if you want to consent or not - currently this is done by a static variable in ``YoutubeParsingHelper`` - may not be the best long-term solution but for now the tests work again (in EU countries) 🥳
Doesn't work for kurgesagt videos anymore, used music video (copyright free) instead
@litetex
Copy link
Member Author

litetex commented Aug 14, 2022

Update: So there have been a bunch of merge conflicts due to the recent hotfix.

These should be fixed now.

While fixing the conflicts I also fixed 2 additional problems:

  1. YouTube Mixes no longer work for the specified (kurzgesagt) video
  2. The suggestion/"Did you mean..." now longer works for the specified search term

@AudricV
Copy link
Member

AudricV commented Aug 14, 2022

For #882 (comment), it seems you don't have to change something, as addYoutubeHeaders() is never called except by YoutubeMixPlaylistExtractor (this method should be called everywhere, don't touch anything here because in order to respect what I said, additional changes would be needed1), so the consent cookie is only sent on mixes.

Note that the current code as it is would not fix #876, as this consent is not applied on regular playlists.

1Here is my idea:

  • Change generateConsentCookie() to generateConsentCookie(boolean), where the boolean parameter would be something like useYesValue. If useYesValue is true, return YES+; otherwise return PENDING= and the three random digits;
  • Change addCookieHeader(@Nonnull final Map<String, List<String>> headers) to addCookieHeader(@Nonnull final Map<String, List<String>> headers, final boolean consentValue);
  • Use the boolean value provided to call generateConsentCookie(boolean);
  • Change addYoutubeHeaders(@Nonnull final Map<String, List<String>> headers) to addYoutubeHeaders(@Nonnull final Map<String, List<String>> headers, final boolean consentValue);
  • Call addCookieHeader(headers, consentValue) in this method;
  • Use addYoutubeHeaders(headers, YoutubeParsingHelper.isConsentAccepted()) in playlists and mixes (addYoutubeHeaders should be used anywhere, but that's not related to your PR at all);
  • Note: singleton lists should not be used on Cookie header, to allow putting a reCAPTCHA one.

@litetex
Copy link
Member Author

litetex commented Aug 21, 2022

For #882 (comment), it seems you don't have to change something, as addYoutubeHeaders() is never called except by YoutubeMixPlaylistExtractor (this method should be called everywhere, don't touch anything here because in order to respect what I said, additional changes would be needed1), so the consent cookie is only sent on mixes.

Note that the current code as it is would not fix #876, as this consent is not applied on regular playlists.

1Here is my idea:

Should I react to this?

If yes: Your solution doesn't make much sense to me, you can simply call addCookieHeader or not ;)
It also adds a lot of overhead for doing technically the same.

Also with foresighted to #833:
This would be an instance specific property and I think it can be handled in the settings of an instance with e.g. a toggle.

@litetex
Copy link
Member Author

litetex commented Aug 21, 2022

Note: I also fixed #902 by

  1. doing a check if the extracted JS is valid JavaScript and if not try the fallback (Regex)
  2. Removing a } from the regex so that it matches correctly

@AudricV AudricV requested a review from Stypox August 21, 2022 19:37
@litetex litetex merged commit d6577e5 into TeamNewPipe:dev Aug 23, 2022
@litetex litetex deleted the fix-all-tests branch August 23, 2022 14:19
@AudricV AudricV removed the request for review from Stypox August 24, 2022 13:08
@opusforlife2
Copy link
Collaborator

@litetex Could you update the PR description to mention all the changes this makes, such as #882 (comment)?

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.

Mix-Playlist extraction is broken in EU
4 participants