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] Fix getting the comment text if the comment contains a hashtag #1021

Merged
merged 1 commit into from
Jan 29, 2023

Conversation

TobiGr
Copy link
Member

@TobiGr TobiGr commented Jan 24, 2023

  • I carefully read the contribution guidelines and agree to them.
  • I have tested the API against NewPipe.
  • I agree to create a pull request for NewPipe as soon as possible to make it compatible with the changed API.

This fix needs further investigation.
The current approach is very strict and throws a ParsingException if the webCommandMetadata is present, but no URL field is given. I was not able to find any other occurrences of that field, but that does not mean there aren't any (I don't know much about the navigationEndpoint, maybe somebody can help us out here). A possibly better solution is to put the condition before the if () else if ... block as shown below to prevent any unintentional exceptions.

@Nullable
public static String getUrlFromNavigationEndpoint(@Nonnull final JsonObject navigationEndpoint)
        throws ParsingException {
   if (navigationEndpoint.has("webCommandMetadata")) {
        // this case needs to be handled before the browseEndpoint,
        // e.g. for hashtags in comments
        final JsonObject metadata = navigationEndpoint.getObject("webCommandMetadata");
        if (metadata.has("url")) {
            return "https://www.youtube.com" + metadata.getString("url");
        }
    }
    if (navigationEndpoint.has("urlEndpoint")) {
        // ...
    } else if (navigationEndpoint.has("browseEndpoint")) {
    // ...

Fixes #1019

@TobiGr TobiGr added bug youtube service, https://www.youtube.com/ labels Jan 24, 2023
@Stypox
Copy link
Member

Stypox commented Jan 29, 2023

I think the solution you propose in the PR body is better. In the end, I don't think anything could go wrong if webCommandMetadata is actually supposed to appear when the other two aren't there. But if this wasn't actually the case, we would be more future-proof.

@TobiGr TobiGr force-pushed the fix/yt-comment-text-hashtag branch from f5e7d4a to 3f7df95 Compare January 29, 2023 19:34
@TobiGr TobiGr marked this pull request as ready for review January 29, 2023 20:46
@Stypox Stypox merged commit e920ab3 into dev Jan 29, 2023
@TobiGr TobiGr deleted the fix/yt-comment-text-hashtag branch January 29, 2023 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug youtube service, https://www.youtube.com/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[YouTube] ParsingException for hashtags links in descriptions and comments
2 participants