mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-28 16:00:33 +05:30
Implement @TobiGr's suggestions
This commit is contained in:
parent
979c5a7502
commit
b51699a20e
@ -309,8 +309,9 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
|||||||
if (getTextFromObject(videoTab.getObject("content").getObject("sectionListRenderer")
|
if (getTextFromObject(videoTab.getObject("content").getObject("sectionListRenderer")
|
||||||
.getArray("contents").getObject(0).getObject("itemSectionRenderer")
|
.getArray("contents").getObject(0).getObject("itemSectionRenderer")
|
||||||
.getArray("contents").getObject(0).getObject("messageRenderer")
|
.getArray("contents").getObject(0).getObject("messageRenderer")
|
||||||
.getObject("text")).equals("This channel has no videos."))
|
.getObject("text")).equals("This channel has no videos.")) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
this.videoTab = videoTab;
|
this.videoTab = videoTab;
|
||||||
return videoTab;
|
return videoTab;
|
||||||
|
@ -5,7 +5,6 @@ import com.grack.nanojson.JsonObject;
|
|||||||
import com.grack.nanojson.JsonParser;
|
import com.grack.nanojson.JsonParser;
|
||||||
import com.grack.nanojson.JsonParserException;
|
import com.grack.nanojson.JsonParserException;
|
||||||
import com.grack.nanojson.JsonWriter;
|
import com.grack.nanojson.JsonWriter;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
@ -20,18 +19,17 @@ import org.schabi.newpipe.extractor.search.SearchExtractor;
|
|||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.fixThumbnailUrl;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.fixThumbnailUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getValidJsonResponseBody;
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getUrlFromNavigationEndpoint;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getUrlFromNavigationEndpoint;
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getValidJsonResponseBody;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_ALBUMS;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_ALBUMS;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_ARTISTS;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_ARTISTS;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_PLAYLISTS;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_PLAYLISTS;
|
||||||
@ -251,7 +249,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
final String name = getTextFromObject(info.getArray("flexColumns").getObject(0)
|
final String name = getTextFromObject(info.getArray("flexColumns").getObject(0)
|
||||||
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
||||||
if (name != null && !name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
throw new ParsingException("Could not get name");
|
throw new ParsingException("Could not get name");
|
||||||
@ -261,7 +259,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
public long getDuration() throws ParsingException {
|
public long getDuration() throws ParsingException {
|
||||||
final String duration = getTextFromObject(info.getArray("flexColumns").getObject(3)
|
final String duration = getTextFromObject(info.getArray("flexColumns").getObject(3)
|
||||||
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
||||||
if (duration != null && !duration.isEmpty()) {
|
if (!duration.isEmpty()) {
|
||||||
return YoutubeParsingHelper.parseDurationString(duration);
|
return YoutubeParsingHelper.parseDurationString(duration);
|
||||||
}
|
}
|
||||||
throw new ParsingException("Could not get duration");
|
throw new ParsingException("Could not get duration");
|
||||||
@ -271,7 +269,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
public String getUploaderName() throws ParsingException {
|
public String getUploaderName() throws ParsingException {
|
||||||
final String name = getTextFromObject(info.getArray("flexColumns").getObject(1)
|
final String name = getTextFromObject(info.getArray("flexColumns").getObject(1)
|
||||||
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
||||||
if (name != null && !name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
throw new ParsingException("Could not get uploader name");
|
throw new ParsingException("Could not get uploader name");
|
||||||
@ -294,7 +292,13 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
.getObject(1).getObject("musicResponsiveListItemFlexColumnRenderer")
|
.getObject(1).getObject("musicResponsiveListItemFlexColumnRenderer")
|
||||||
.getObject("text").getArray("runs").getObject(0).getObject("navigationEndpoint");
|
.getObject("text").getArray("runs").getObject(0).getObject("navigationEndpoint");
|
||||||
|
|
||||||
return getUrlFromNavigationEndpoint(navigationEndpoint);
|
final String url = getUrlFromNavigationEndpoint(navigationEndpoint);
|
||||||
|
|
||||||
|
if (url != null && !url.isEmpty()) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ParsingException("Could not get uploader URL");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,7 +319,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
}
|
}
|
||||||
final String viewCount = getTextFromObject(info.getArray("flexColumns").getObject(2)
|
final String viewCount = getTextFromObject(info.getArray("flexColumns").getObject(2)
|
||||||
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
||||||
if (viewCount != null && !viewCount.isEmpty()) {
|
if (!viewCount.isEmpty()) {
|
||||||
return Utils.mixedNumberWordToLong(viewCount);
|
return Utils.mixedNumberWordToLong(viewCount);
|
||||||
}
|
}
|
||||||
throw new ParsingException("Could not get view count");
|
throw new ParsingException("Could not get view count");
|
||||||
@ -355,7 +359,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
final String name = getTextFromObject(info.getArray("flexColumns").getObject(0)
|
final String name = getTextFromObject(info.getArray("flexColumns").getObject(0)
|
||||||
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
||||||
if (name != null && !name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
throw new ParsingException("Could not get name");
|
throw new ParsingException("Could not get name");
|
||||||
@ -374,7 +378,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
public long getSubscriberCount() throws ParsingException {
|
public long getSubscriberCount() throws ParsingException {
|
||||||
final String viewCount = getTextFromObject(info.getArray("flexColumns").getObject(2)
|
final String viewCount = getTextFromObject(info.getArray("flexColumns").getObject(2)
|
||||||
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
||||||
if (viewCount != null && !viewCount.isEmpty()) {
|
if (!viewCount.isEmpty()) {
|
||||||
return Utils.mixedNumberWordToLong(viewCount);
|
return Utils.mixedNumberWordToLong(viewCount);
|
||||||
}
|
}
|
||||||
throw new ParsingException("Could not get subscriber count");
|
throw new ParsingException("Could not get subscriber count");
|
||||||
@ -410,7 +414,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
final String name = getTextFromObject(info.getArray("flexColumns").getObject(0)
|
final String name = getTextFromObject(info.getArray("flexColumns").getObject(0)
|
||||||
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
||||||
if (name != null && !name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
throw new ParsingException("Could not get name");
|
throw new ParsingException("Could not get name");
|
||||||
@ -435,7 +439,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
name = getTextFromObject(info.getArray("flexColumns").getObject(1)
|
name = getTextFromObject(info.getArray("flexColumns").getObject(1)
|
||||||
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
||||||
}
|
}
|
||||||
if (name != null && !name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
throw new ParsingException("Could not get uploader name");
|
throw new ParsingException("Could not get uploader name");
|
||||||
@ -448,7 +452,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
}
|
}
|
||||||
final String count = getTextFromObject(info.getArray("flexColumns").getObject(2)
|
final String count = getTextFromObject(info.getArray("flexColumns").getObject(2)
|
||||||
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
||||||
if (count != null && !count.isEmpty()) {
|
if (!count.isEmpty()) {
|
||||||
if (count.contains("100+")) {
|
if (count.contains("100+")) {
|
||||||
return ITEM_COUNT_MORE_THAN_100;
|
return ITEM_COUNT_MORE_THAN_100;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,7 +2,6 @@ package org.schabi.newpipe.extractor.services.youtube.extractors;
|
|||||||
|
|
||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
@ -15,9 +14,8 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.fixThumbnailUrl;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.fixThumbnailUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
|
||||||
@ -83,7 +81,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
|||||||
@Override
|
@Override
|
||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
String name = getTextFromObject(playlistInfo.getObject("title"));
|
String name = getTextFromObject(playlistInfo.getObject("title"));
|
||||||
if (name == null || !name.isEmpty()) return name;
|
if (!name.isEmpty()) return name;
|
||||||
|
|
||||||
return initialData.getObject("microformat").getObject("microformatDataRenderer").getString("title");
|
return initialData.getObject("microformat").getObject("microformatDataRenderer").getString("title");
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package org.schabi.newpipe.extractor.services.youtube.extractors;
|
|||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
import com.grack.nanojson.JsonParser;
|
import com.grack.nanojson.JsonParser;
|
||||||
|
|
||||||
import org.mozilla.javascript.Context;
|
import org.mozilla.javascript.Context;
|
||||||
import org.mozilla.javascript.Function;
|
import org.mozilla.javascript.Function;
|
||||||
import org.mozilla.javascript.ScriptableObject;
|
import org.mozilla.javascript.ScriptableObject;
|
||||||
@ -33,10 +32,11 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
|||||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
|
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
|
||||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
|
||||||
import org.schabi.newpipe.extractor.utils.Parser;
|
import org.schabi.newpipe.extractor.utils.Parser;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -50,9 +50,6 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.fixThumbnailUrl;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.fixThumbnailUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
|
||||||
@ -120,7 +117,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
String title = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("title"));
|
String title = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("title"));
|
||||||
|
|
||||||
if (title == null || title.isEmpty()) {
|
if (title.isEmpty()) {
|
||||||
title = playerResponse.getObject("videoDetails").getString("title");
|
title = playerResponse.getObject("videoDetails").getString("title");
|
||||||
|
|
||||||
if (title == null || title.isEmpty()) throw new ParsingException("Could not get name");
|
if (title == null || title.isEmpty()) throw new ParsingException("Could not get name");
|
||||||
@ -200,7 +197,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
// description with more info on links
|
// description with more info on links
|
||||||
String description = getTextFromObject(getVideoSecondaryInfoRenderer().getObject("description"), true);
|
String description = getTextFromObject(getVideoSecondaryInfoRenderer().getObject("description"), true);
|
||||||
if (description != null && !description.isEmpty()) return new Description(description, Description.HTML);
|
if (!description.isEmpty()) return new Description(description, Description.HTML);
|
||||||
|
|
||||||
// raw non-html description
|
// raw non-html description
|
||||||
return new Description(playerResponse.getObject("videoDetails").getString("shortDescription"), Description.PLAIN_TEXT);
|
return new Description(playerResponse.getObject("videoDetails").getString("shortDescription"), Description.PLAIN_TEXT);
|
||||||
@ -252,7 +249,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
String views = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("viewCount")
|
String views = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("viewCount")
|
||||||
.getObject("videoViewCountRenderer").getObject("viewCount"));
|
.getObject("videoViewCountRenderer").getObject("viewCount"));
|
||||||
|
|
||||||
if (views == null || views.isEmpty()) {
|
if (views.isEmpty()) {
|
||||||
views = playerResponse.getObject("videoDetails").getString("viewCount");
|
views = playerResponse.getObject("videoDetails").getString("viewCount");
|
||||||
|
|
||||||
if (views == null || views.isEmpty()) throw new ParsingException("Could not get view count");
|
if (views == null || views.isEmpty()) throw new ParsingException("Could not get view count");
|
||||||
@ -333,7 +330,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
String uploaderName = getTextFromObject(getVideoSecondaryInfoRenderer().getObject("owner")
|
String uploaderName = getTextFromObject(getVideoSecondaryInfoRenderer().getObject("owner")
|
||||||
.getObject("videoOwnerRenderer").getObject("title"));
|
.getObject("videoOwnerRenderer").getObject("title"));
|
||||||
|
|
||||||
if (uploaderName == null || uploaderName.isEmpty()) {
|
if (uploaderName.isEmpty()) {
|
||||||
uploaderName = playerResponse.getObject("videoDetails").getString("author");
|
uploaderName = playerResponse.getObject("videoDetails").getString("author");
|
||||||
|
|
||||||
if (uploaderName == null || uploaderName.isEmpty()) throw new ParsingException("Could not get uploader name");
|
if (uploaderName == null || uploaderName.isEmpty()) throw new ParsingException("Could not get uploader name");
|
||||||
|
@ -93,7 +93,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
|||||||
@Override
|
@Override
|
||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
String name = getTextFromObject(videoInfo.getObject("title"));
|
String name = getTextFromObject(videoInfo.getObject("title"));
|
||||||
if (name == null || !name.isEmpty()) return name;
|
if (!name.isEmpty()) return name;
|
||||||
throw new ParsingException("Could not get name");
|
throw new ParsingException("Could not get name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
|||||||
|
|
||||||
String duration = getTextFromObject(videoInfo.getObject("lengthText"));
|
String duration = getTextFromObject(videoInfo.getObject("lengthText"));
|
||||||
|
|
||||||
if (duration == null || duration.isEmpty()) {
|
if (duration.isEmpty()) {
|
||||||
for (Object thumbnailOverlay : videoInfo.getArray("thumbnailOverlays")) {
|
for (Object thumbnailOverlay : videoInfo.getArray("thumbnailOverlays")) {
|
||||||
if (((JsonObject) thumbnailOverlay).has("thumbnailOverlayTimeStatusRenderer")) {
|
if (((JsonObject) thumbnailOverlay).has("thumbnailOverlayTimeStatusRenderer")) {
|
||||||
duration = getTextFromObject(((JsonObject) thumbnailOverlay)
|
duration = getTextFromObject(((JsonObject) thumbnailOverlay)
|
||||||
@ -113,7 +113,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (duration == null || duration.isEmpty()) throw new ParsingException("Could not get duration");
|
if (duration.isEmpty()) throw new ParsingException("Could not get duration");
|
||||||
}
|
}
|
||||||
|
|
||||||
return YoutubeParsingHelper.parseDurationString(duration);
|
return YoutubeParsingHelper.parseDurationString(duration);
|
||||||
@ -123,13 +123,13 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
|||||||
public String getUploaderName() throws ParsingException {
|
public String getUploaderName() throws ParsingException {
|
||||||
String name = getTextFromObject(videoInfo.getObject("longBylineText"));
|
String name = getTextFromObject(videoInfo.getObject("longBylineText"));
|
||||||
|
|
||||||
if (name == null || name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
name = getTextFromObject(videoInfo.getObject("ownerText"));
|
name = getTextFromObject(videoInfo.getObject("ownerText"));
|
||||||
|
|
||||||
if (name == null || name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
name = getTextFromObject(videoInfo.getObject("shortBylineText"));
|
name = getTextFromObject(videoInfo.getObject("shortBylineText"));
|
||||||
|
|
||||||
if (name == null || name.isEmpty()) throw new ParsingException("Could not get uploader name");
|
if (name.isEmpty()) throw new ParsingException("Could not get uploader name");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String publishedTimeText = getTextFromObject(videoInfo.getObject("publishedTimeText"));
|
final String publishedTimeText = getTextFromObject(videoInfo.getObject("publishedTimeText"));
|
||||||
if (publishedTimeText != null && !publishedTimeText.isEmpty()) return publishedTimeText;
|
if (!publishedTimeText.isEmpty()) return publishedTimeText;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ package org.schabi.newpipe.extractor.services.youtube.extractors;
|
|||||||
|
|
||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
@ -33,9 +32,8 @@ import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
|||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
|
||||||
@ -72,13 +70,8 @@ public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
String name;
|
String name = getTextFromObject(initialData.getObject("header").getObject("feedTabbedHeaderRenderer").getObject("title"));
|
||||||
try {
|
if (!name.isEmpty()) {
|
||||||
name = getTextFromObject(initialData.getObject("header").getObject("feedTabbedHeaderRenderer").getObject("title"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ParsingException("Could not get Trending name", e);
|
|
||||||
}
|
|
||||||
if (name != null && !name.isEmpty()) {
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
throw new ParsingException("Could not get Trending name");
|
throw new ParsingException("Could not get Trending name");
|
||||||
|
@ -384,6 +384,12 @@ public class YoutubeParsingHelper {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the text from a JSON object that has either a simpleText or a runs array.
|
||||||
|
* @param textObject JSON object to get the text from
|
||||||
|
* @param html whether to return HTML, by parsing the navigationEndpoint
|
||||||
|
* @return text in the JSON object or an empty string
|
||||||
|
*/
|
||||||
public static String getTextFromObject(JsonObject textObject, boolean html) throws ParsingException {
|
public static String getTextFromObject(JsonObject textObject, boolean html) throws ParsingException {
|
||||||
if (textObject.has("simpleText")) return textObject.getString("simpleText");
|
if (textObject.has("simpleText")) return textObject.getString("simpleText");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user