[Youtube] Extract initial playlist info
This commit is contained in:
parent
a376792a5d
commit
0ff054acb4
|
@ -1,5 +1,9 @@
|
||||||
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
|
||||||
|
|
||||||
|
import com.grack.nanojson.JsonArray;
|
||||||
|
import com.grack.nanojson.JsonObject;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -24,6 +28,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||||
*/
|
*/
|
||||||
public class YoutubeMixPlaylistExtractor extends PlaylistExtractor {
|
public class YoutubeMixPlaylistExtractor extends PlaylistExtractor {
|
||||||
|
|
||||||
|
private JsonObject initialData;
|
||||||
private Document doc;
|
private Document doc;
|
||||||
|
|
||||||
public YoutubeMixPlaylistExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
public YoutubeMixPlaylistExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
||||||
|
@ -32,9 +37,14 @@ public class YoutubeMixPlaylistExtractor extends PlaylistExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||||
final String url = getUrl();
|
final String url = getUrl() + "&pbj=1";
|
||||||
final Response response = downloader.get(url, getExtractorLocalization());
|
final JsonArray ajaxJson = getJsonResponse(url, getExtractorLocalization());
|
||||||
doc = YoutubeParsingHelper.parseAndCheckPage(url, response);
|
initialData = ajaxJson.getObject(3).getObject("response");
|
||||||
|
JsonObject a = initialData.getObject("contents");
|
||||||
|
JsonObject b = initialData.getObject("contents").getObject("twoColumnWatchNextResults");
|
||||||
|
JsonObject c = initialData.getObject("contents");
|
||||||
|
JsonObject playlist = initialData.getObject("contents").getObject("twoColumnWatchNextResults").getObject("playlist").getObject("playlist");
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -127,76 +137,76 @@ public class YoutubeMixPlaylistExtractor extends PlaylistExtractor {
|
||||||
final LinkHandlerFactory streamLinkHandlerFactory = getService().getStreamLHFactory();
|
final LinkHandlerFactory streamLinkHandlerFactory = getService().getStreamLHFactory();
|
||||||
final TimeAgoParser timeAgoParser = getTimeAgoParser();
|
final TimeAgoParser timeAgoParser = getTimeAgoParser();
|
||||||
|
|
||||||
for (final Element li : element.children()) {
|
// for (final Element li : element.children()) {
|
||||||
|
//
|
||||||
collector.commit(new YoutubeStreamInfoItemExtractor(li, timeAgoParser) {
|
// collector.commit(new YoutubeStreamInfoItemExtractor(li, timeAgoParser) {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public boolean isAd() {
|
// public boolean isAd() {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public String getUrl() throws ParsingException {
|
// public String getUrl() throws ParsingException {
|
||||||
try {
|
// try {
|
||||||
return streamLinkHandlerFactory.fromId(li.attr("data-video-id")).getUrl();
|
// return streamLinkHandlerFactory.fromId(li.attr("data-video-id")).getUrl();
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new ParsingException("Could not get web page url for the video", e);
|
// throw new ParsingException("Could not get web page url for the video", e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public String getName() throws ParsingException {
|
// public String getName() throws ParsingException {
|
||||||
try {
|
// try {
|
||||||
return li.attr("data-video-title");
|
// return li.attr("data-video-title");
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new ParsingException("Could not get name", e);
|
// throw new ParsingException("Could not get name", e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public long getDuration() {
|
// public long getDuration() {
|
||||||
//Not present in doc
|
// //Not present in doc
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public String getUploaderName() throws ParsingException {
|
// public String getUploaderName() throws ParsingException {
|
||||||
String uploaderName = li.attr("data-video-username");
|
// String uploaderName = li.attr("data-video-username");
|
||||||
if (uploaderName == null || uploaderName.isEmpty()) {
|
// if (uploaderName == null || uploaderName.isEmpty()) {
|
||||||
throw new ParsingException("Could not get uploader name");
|
// throw new ParsingException("Could not get uploader name");
|
||||||
} else {
|
// } else {
|
||||||
return uploaderName;
|
// return uploaderName;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public String getUploaderUrl() {
|
// public String getUploaderUrl() {
|
||||||
//Not present in doc
|
// //Not present in doc
|
||||||
return "";
|
// return "";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public String getTextualUploadDate() {
|
// public String getTextualUploadDate() {
|
||||||
//Not present in doc
|
// //Not present in doc
|
||||||
return "";
|
// return "";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public long getViewCount() {
|
// public long getViewCount() {
|
||||||
return -1;
|
// return -1;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public String getThumbnailUrl() throws ParsingException {
|
// public String getThumbnailUrl() throws ParsingException {
|
||||||
try {
|
// try {
|
||||||
return getThumbnailUrlFromId(streamLinkHandlerFactory.fromUrl(getUrl()).getId());
|
// return getThumbnailUrlFromId(streamLinkHandlerFactory.fromUrl(getUrl()).getId());
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new ParsingException("Could not get thumbnail url", e);
|
// throw new ParsingException("Could not get thumbnail url", e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getThumbnailUrlFromId(String videoId) {
|
private String getThumbnailUrlFromId(String videoId) {
|
||||||
|
|
Loading…
Reference in New Issue