-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[YouTube] Add support for showRenderers in search results
- Loading branch information
Showing
2 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...i/newpipe/extractor/services/youtube/extractors/YoutubeShowRendererInfoItemExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.schabi.newpipe.extractor.services.youtube.extractors; | ||
|
||
import com.grack.nanojson.JsonObject; | ||
import org.schabi.newpipe.extractor.exceptions.ParsingException; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; | ||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromObject; | ||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; | ||
|
||
/** | ||
* A {@link YoutubeBaseShowInfoItemExtractor} implementation for {@code showRenderer}s. | ||
*/ | ||
class YoutubeShowRendererInfoItemExtractor extends YoutubeBaseShowInfoItemExtractor { | ||
|
||
@Nonnull | ||
private final JsonObject shortBylineText; | ||
@Nonnull | ||
private final JsonObject longBylineText; | ||
|
||
YoutubeShowRendererInfoItemExtractor(@Nonnull final JsonObject showRenderer) { | ||
super(showRenderer); | ||
this.shortBylineText = showRenderer.getObject("shortBylineText"); | ||
this.longBylineText = showRenderer.getObject("longBylineText"); | ||
} | ||
|
||
@Override | ||
public String getUploaderName() throws ParsingException { | ||
String name = getTextFromObject(longBylineText); | ||
if (isNullOrEmpty(name)) { | ||
name = getTextFromObject(shortBylineText); | ||
if (isNullOrEmpty(name)) { | ||
throw new ParsingException("Could not get uploader name"); | ||
} | ||
} | ||
return name; | ||
} | ||
|
||
@Override | ||
public String getUploaderUrl() throws ParsingException { | ||
String uploaderUrl = getUrlFromObject(longBylineText); | ||
if (uploaderUrl == null) { | ||
uploaderUrl = getUrlFromObject(shortBylineText); | ||
if (uploaderUrl == null) { | ||
throw new ParsingException("Could not get uploader URL"); | ||
} | ||
} | ||
return uploaderUrl; | ||
} | ||
|
||
@Override | ||
public boolean isUploaderVerified() throws ParsingException { | ||
// We do not have this information in showRenderers | ||
return false; | ||
} | ||
} |