mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-13 05:40:34 +05:30
added comments to stream info
This commit is contained in:
parent
06898f47b2
commit
f62f147ea0
@ -44,6 +44,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
|
||||
public InfoItemsPage<CommentsInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
// initial page does not load any comments but is required to get session token
|
||||
// and cookies
|
||||
super.fetchPage();
|
||||
return getPage(getNextPageUrl());
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
package org.schabi.newpipe.extractor.stream;
|
||||
|
||||
import org.schabi.newpipe.extractor.*;
|
||||
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.utils.DashMpdParser;
|
||||
@ -247,6 +251,19 @@ public class StreamInfo extends Info {
|
||||
}
|
||||
|
||||
streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor));
|
||||
|
||||
CommentsExtractor commentsExtractor = null;
|
||||
try {
|
||||
commentsExtractor = NewPipe.getService(streamInfo.getServiceId()).getCommentsExtractor(streamInfo.getUrl());
|
||||
} catch (ExtractionException e) {
|
||||
streamInfo.addError(e);
|
||||
}
|
||||
|
||||
if(null != commentsExtractor) {
|
||||
InfoItemsPage<CommentsInfoItem> initialCommentsPage = ExtractorHelper.getItemsPageOrLogError(streamInfo, commentsExtractor);
|
||||
streamInfo.setComments(initialCommentsPage.getItems());
|
||||
}
|
||||
|
||||
return streamInfo;
|
||||
}
|
||||
|
||||
@ -273,6 +290,7 @@ public class StreamInfo extends Info {
|
||||
private String hlsUrl;
|
||||
private StreamInfoItem nextVideo;
|
||||
private List<InfoItem> relatedStreams;
|
||||
private List<CommentsInfoItem> comments;
|
||||
|
||||
private long startPosition = 0;
|
||||
private List<Subtitles> subtitles;
|
||||
@ -470,4 +488,14 @@ public class StreamInfo extends Info {
|
||||
this.subtitles = subtitles;
|
||||
}
|
||||
|
||||
public List<CommentsInfoItem> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public void setComments(List<CommentsInfoItem> comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.schabi.newpipe.extractor.InfoItem;
|
||||
import org.schabi.newpipe.extractor.InfoItemsCollector;
|
||||
import org.schabi.newpipe.extractor.ListExtractor;
|
||||
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||
|
||||
@ -39,4 +40,5 @@ public class ExtractorHelper {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -184,10 +185,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
|
||||
|
||||
@Override
|
||||
public DownloadResponse get(String siteUrl) throws IOException, ReCaptchaException {
|
||||
URL url = new URL(siteUrl);
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
|
||||
String responseBody = dl(con);
|
||||
return new DownloadResponse(responseBody, con.getHeaderFields());
|
||||
return get(siteUrl, Collections.emptyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +23,6 @@ public class YoutubeCommentsExtractorTest {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
extractor = (YoutubeCommentsExtractor) YouTube
|
||||
.getCommentsExtractor("https://www.youtube.com/watch?v=rrgFN3AxGfs");
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user