mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-13 22:00:32 +05:30
Add checks if page is fetched
This commit is contained in:
parent
23231732ca
commit
f037f67a15
@ -105,6 +105,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
String name = getStringFromMetaData("title");
|
String name = getStringFromMetaData("title");
|
||||||
if(name == null) {
|
if(name == null) {
|
||||||
// Fallback to HTML method
|
// Fallback to HTML method
|
||||||
@ -123,6 +124,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getUploadDate() throws ParsingException {
|
public String getUploadDate() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
try {
|
try {
|
||||||
return doc.select("meta[itemprop=datePublished]").attr(CONTENT);
|
return doc.select("meta[itemprop=datePublished]").attr(CONTENT);
|
||||||
} catch (Exception e) {//todo: add fallback method
|
} catch (Exception e) {//todo: add fallback method
|
||||||
@ -133,6 +135,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getThumbnailUrl() throws ParsingException {
|
public String getThumbnailUrl() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
// Try to get high resolution thumbnail first, if it fails, use low res from the player instead
|
// Try to get high resolution thumbnail first, if it fails, use low res from the player instead
|
||||||
try {
|
try {
|
||||||
return doc.select("link[itemprop=\"thumbnailUrl\"]").first().attr("abs:href");
|
return doc.select("link[itemprop=\"thumbnailUrl\"]").first().attr("abs:href");
|
||||||
@ -156,6 +159,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() throws ParsingException {
|
public String getDescription() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
try {
|
try {
|
||||||
return doc.select("p[id=\"eow-description\"]").first().html();
|
return doc.select("p[id=\"eow-description\"]").first().html();
|
||||||
} catch (Exception e) {//todo: add fallback method <-- there is no ... as long as i know
|
} catch (Exception e) {//todo: add fallback method <-- there is no ... as long as i know
|
||||||
@ -165,6 +169,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAgeLimit() throws ParsingException {
|
public int getAgeLimit() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
if (!isAgeRestricted) {
|
if (!isAgeRestricted) {
|
||||||
return NO_AGE_LIMIT;
|
return NO_AGE_LIMIT;
|
||||||
}
|
}
|
||||||
@ -178,6 +183,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLength() throws ParsingException {
|
public long getLength() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
if(playerArgs != null) {
|
if(playerArgs != null) {
|
||||||
try {
|
try {
|
||||||
long returnValue = Long.parseLong(playerArgs.get("length_seconds") + "");
|
long returnValue = Long.parseLong(playerArgs.get("length_seconds") + "");
|
||||||
@ -216,6 +222,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getViewCount() throws ParsingException {
|
public long getViewCount() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
try {
|
try {
|
||||||
return Long.parseLong(doc.select("meta[itemprop=interactionCount]").attr(CONTENT));
|
return Long.parseLong(doc.select("meta[itemprop=interactionCount]").attr(CONTENT));
|
||||||
} catch (Exception e) {//todo: find fallback method
|
} catch (Exception e) {//todo: find fallback method
|
||||||
@ -225,6 +232,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLikeCount() throws ParsingException {
|
public long getLikeCount() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
String likesString = "";
|
String likesString = "";
|
||||||
try {
|
try {
|
||||||
Element button = doc.select("button.like-button-renderer-like-button").first();
|
Element button = doc.select("button.like-button-renderer-like-button").first();
|
||||||
@ -244,6 +252,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDislikeCount() throws ParsingException {
|
public long getDislikeCount() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
String dislikesString = "";
|
String dislikesString = "";
|
||||||
try {
|
try {
|
||||||
Element button = doc.select("button.like-button-renderer-dislike-button").first();
|
Element button = doc.select("button.like-button-renderer-dislike-button").first();
|
||||||
@ -264,6 +273,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderUrl() throws ParsingException {
|
public String getUploaderUrl() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
try {
|
try {
|
||||||
return doc.select("div[class=\"yt-user-info\"]").first().children()
|
return doc.select("div[class=\"yt-user-info\"]").first().children()
|
||||||
.select("a").first().attr("abs:href");
|
.select("a").first().attr("abs:href");
|
||||||
@ -275,6 +285,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String getStringFromMetaData(String field) {
|
private String getStringFromMetaData(String field) {
|
||||||
|
assertPageFetched();
|
||||||
String value = null;
|
String value = null;
|
||||||
if(playerArgs != null) {
|
if(playerArgs != null) {
|
||||||
// This can not fail
|
// This can not fail
|
||||||
@ -290,6 +301,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderName() throws ParsingException {
|
public String getUploaderName() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
String name = getStringFromMetaData("author");
|
String name = getStringFromMetaData("author");
|
||||||
|
|
||||||
if(name == null) {
|
if(name == null) {
|
||||||
@ -309,6 +321,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderAvatarUrl() throws ParsingException {
|
public String getUploaderAvatarUrl() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
try {
|
try {
|
||||||
return doc.select("a[class*=\"yt-user-photo\"]").first()
|
return doc.select("a[class*=\"yt-user-photo\"]").first()
|
||||||
.select("img").first()
|
.select("img").first()
|
||||||
@ -320,6 +333,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDashMpdUrl() throws ParsingException {
|
public String getDashMpdUrl() throws ParsingException {
|
||||||
|
assertPageFetched();
|
||||||
try {
|
try {
|
||||||
String dashManifestUrl;
|
String dashManifestUrl;
|
||||||
if (videoInfoPage.containsKey("dashmpd")) {
|
if (videoInfoPage.containsKey("dashmpd")) {
|
||||||
@ -346,6 +360,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AudioStream> getAudioStreams() throws IOException, ExtractionException {
|
public List<AudioStream> getAudioStreams() throws IOException, ExtractionException {
|
||||||
|
assertPageFetched();
|
||||||
List<AudioStream> audioStreams = new ArrayList<>();
|
List<AudioStream> audioStreams = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
for (Map.Entry<String, ItagItem> entry : getItags(ADAPTIVE_FMTS, ItagItem.ItagType.AUDIO).entrySet()) {
|
for (Map.Entry<String, ItagItem> entry : getItags(ADAPTIVE_FMTS, ItagItem.ItagType.AUDIO).entrySet()) {
|
||||||
@ -365,6 +380,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VideoStream> getVideoStreams() throws IOException, ExtractionException {
|
public List<VideoStream> getVideoStreams() throws IOException, ExtractionException {
|
||||||
|
assertPageFetched();
|
||||||
List<VideoStream> videoStreams = new ArrayList<>();
|
List<VideoStream> videoStreams = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
for (Map.Entry<String, ItagItem> entry : getItags(URL_ENCODED_FMT_STREAM_MAP, ItagItem.ItagType.VIDEO).entrySet()) {
|
for (Map.Entry<String, ItagItem> entry : getItags(URL_ENCODED_FMT_STREAM_MAP, ItagItem.ItagType.VIDEO).entrySet()) {
|
||||||
@ -384,6 +400,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException {
|
public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException {
|
||||||
|
assertPageFetched();
|
||||||
List<VideoStream> videoOnlyStreams = new ArrayList<>();
|
List<VideoStream> videoOnlyStreams = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
for (Map.Entry<String, ItagItem> entry : getItags(ADAPTIVE_FMTS, ItagItem.ItagType.VIDEO_ONLY).entrySet()) {
|
for (Map.Entry<String, ItagItem> entry : getItags(ADAPTIVE_FMTS, ItagItem.ItagType.VIDEO_ONLY).entrySet()) {
|
||||||
@ -410,6 +427,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException {
|
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException {
|
||||||
|
assertPageFetched();
|
||||||
if(isAgeRestricted) {
|
if(isAgeRestricted) {
|
||||||
// If the video is age restricted getPlayerConfig will fail
|
// If the video is age restricted getPlayerConfig will fail
|
||||||
return null;
|
return null;
|
||||||
@ -459,6 +477,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamInfoItem getNextVideo() throws IOException, ExtractionException {
|
public StreamInfoItem getNextVideo() throws IOException, ExtractionException {
|
||||||
|
assertPageFetched();
|
||||||
try {
|
try {
|
||||||
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
|
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
|
||||||
collector.commit(extractVideoPreviewInfo(doc.select("div[class=\"watch-sidebar-section\"]")
|
collector.commit(extractVideoPreviewInfo(doc.select("div[class=\"watch-sidebar-section\"]")
|
||||||
@ -472,6 +491,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamInfoItemCollector getRelatedVideos() throws IOException, ExtractionException {
|
public StreamInfoItemCollector getRelatedVideos() throws IOException, ExtractionException {
|
||||||
|
assertPageFetched();
|
||||||
try {
|
try {
|
||||||
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
|
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
|
||||||
Element ul = doc.select("ul[id=\"watch-related\"]").first();
|
Element ul = doc.select("ul[id=\"watch-related\"]").first();
|
||||||
|
Loading…
Reference in New Issue
Block a user