mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-14 14:20:33 +05:30
Merge pull request #582 from Stypox/fix-trending
[YouTube] Fix trending getName()
This commit is contained in:
commit
cae6cea551
@ -571,6 +571,16 @@ public class YoutubeParsingHelper {
|
|||||||
return getTextFromObject(textObject, false);
|
return getTextFromObject(textObject, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static String getTextAtKey(final JsonObject jsonObject, final String key)
|
||||||
|
throws ParsingException {
|
||||||
|
if (jsonObject.isString(key)) {
|
||||||
|
return jsonObject.getString(key);
|
||||||
|
} else {
|
||||||
|
return getTextFromObject(jsonObject.getObject(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String fixThumbnailUrl(String thumbnailUrl) {
|
public static String fixThumbnailUrl(String thumbnailUrl) {
|
||||||
if (thumbnailUrl.startsWith("//")) {
|
if (thumbnailUrl.startsWith("//")) {
|
||||||
thumbnailUrl = thumbnailUrl.substring(2);
|
thumbnailUrl = thumbnailUrl.substring(2);
|
||||||
|
@ -39,6 +39,7 @@ import java.io.IOException;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonResponse;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonResponse;
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextAtKey;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
@ -70,19 +71,18 @@ public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
|||||||
@Override
|
@Override
|
||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
final JsonObject header = initialData.getObject("header");
|
final JsonObject header = initialData.getObject("header");
|
||||||
JsonObject title = null;
|
String name = null;
|
||||||
if (header.has("feedTabbedHeaderRenderer")) {
|
if (header.has("feedTabbedHeaderRenderer")) {
|
||||||
title = header.getObject("feedTabbedHeaderRenderer").getObject("title");
|
name = getTextAtKey(header.getObject("feedTabbedHeaderRenderer"), "title");
|
||||||
} else if (header.has("c4TabbedHeaderRenderer")) {
|
} else if (header.has("c4TabbedHeaderRenderer")) {
|
||||||
title = header.getObject("c4TabbedHeaderRenderer").getObject("title");
|
name = getTextAtKey(header.getObject("c4TabbedHeaderRenderer"), "title");
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = getTextFromObject(title);
|
if (isNullOrEmpty(name)) {
|
||||||
if (!isNullOrEmpty(name)) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
throw new ParsingException("Could not get Trending name");
|
throw new ParsingException("Could not get Trending name");
|
||||||
}
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user