|
| 1 | +package org.schabi.newpipe.extractor.services.youtube.extractors; |
| 2 | + |
| 3 | +import com.grack.nanojson.JsonObject; |
| 4 | +import org.schabi.newpipe.extractor.exceptions.ParsingException; |
| 5 | + |
| 6 | +import javax.annotation.Nonnull; |
| 7 | + |
| 8 | +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; |
| 9 | +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromObject; |
| 10 | +import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; |
| 11 | + |
| 12 | +/** |
| 13 | + * A {@link YoutubeBaseShowInfoItemExtractor} implementation for {@code showRenderer}s. |
| 14 | + */ |
| 15 | +class YoutubeShowRendererInfoItemExtractor extends YoutubeBaseShowInfoItemExtractor { |
| 16 | + |
| 17 | + @Nonnull |
| 18 | + private final JsonObject shortBylineText; |
| 19 | + @Nonnull |
| 20 | + private final JsonObject longBylineText; |
| 21 | + |
| 22 | + YoutubeShowRendererInfoItemExtractor(@Nonnull final JsonObject showRenderer) { |
| 23 | + super(showRenderer); |
| 24 | + this.shortBylineText = showRenderer.getObject("shortBylineText"); |
| 25 | + this.longBylineText = showRenderer.getObject("longBylineText"); |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public String getUploaderName() throws ParsingException { |
| 30 | + String name = getTextFromObject(longBylineText); |
| 31 | + if (isNullOrEmpty(name)) { |
| 32 | + name = getTextFromObject(shortBylineText); |
| 33 | + if (isNullOrEmpty(name)) { |
| 34 | + throw new ParsingException("Could not get uploader name"); |
| 35 | + } |
| 36 | + } |
| 37 | + return name; |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public String getUploaderUrl() throws ParsingException { |
| 42 | + String uploaderUrl = getUrlFromObject(longBylineText); |
| 43 | + if (uploaderUrl == null) { |
| 44 | + uploaderUrl = getUrlFromObject(shortBylineText); |
| 45 | + if (uploaderUrl == null) { |
| 46 | + throw new ParsingException("Could not get uploader URL"); |
| 47 | + } |
| 48 | + } |
| 49 | + return uploaderUrl; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public boolean isUploaderVerified() throws ParsingException { |
| 54 | + // We do not have this information in showRenderers |
| 55 | + return false; |
| 56 | + } |
| 57 | +} |
0 commit comments