Merge pull request #647 from litetex/playerSeekbarPreview

Code changes to enable player thumbnail seekbar preview in NewPipe
This commit is contained in:
Tobi 2021-07-17 17:49:54 +02:00 committed by GitHub
commit ada67d136a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 11 deletions

View File

@ -1049,7 +1049,16 @@ public class YoutubeStreamExtractor extends StreamExtractor {
storyboardsRenderer = storyboards.getObject("playerStoryboardSpecRenderer");
}
final String[] spec = storyboardsRenderer.getString("spec").split("\\|");
if (storyboardsRenderer == null) {
return Collections.emptyList();
}
final String storyboardsRendererSpec = storyboardsRenderer.getString("spec");
if (storyboardsRendererSpec == null) {
return Collections.emptyList();
}
final String[] spec = storyboardsRendererSpec.split("\\|");
final String url = spec[0];
final ArrayList<Frameset> result = new ArrayList<>(spec.length - 1);

View File

@ -1,18 +1,27 @@
package org.schabi.newpipe.extractor.stream;
import java.io.Serializable;
import java.util.List;
public final class Frameset {
public final class Frameset implements Serializable {
private List<String> urls;
private int frameWidth;
private int frameHeight;
private int totalCount;
private int durationPerFrame;
private int framesPerPageX;
private int framesPerPageY;
private final List<String> urls;
private final int frameWidth;
private final int frameHeight;
private final int totalCount;
private final int durationPerFrame;
private final int framesPerPageX;
private final int framesPerPageY;
public Frameset(List<String> urls, int frameWidth, int frameHeight, int totalCount, int durationPerFrame, int framesPerPageX, int framesPerPageY) {
public Frameset(
final List<String> urls,
final int frameWidth,
final int frameHeight,
final int totalCount,
final int durationPerFrame,
final int framesPerPageX,
final int framesPerPageY) {
this.urls = urls;
this.totalCount = totalCount;
this.durationPerFrame = durationPerFrame;
@ -86,7 +95,7 @@ public final class Frameset {
* <li><code>4</code>: Bottom bound</li>
* </ul>
*/
public int[] getFrameBoundsAt(long position) {
public int[] getFrameBoundsAt(final long position) {
if (position < 0 || position > ((totalCount + 1) * durationPerFrame)) {
// Return the first frame as fallback
return new int[] { 0, 0, 0, frameWidth, frameHeight };

View File

@ -335,6 +335,12 @@ public class StreamInfo extends Info {
streamInfo.addError(e);
}
try {
streamInfo.setPreviewFrames(extractor.getFrames());
} catch (Exception e) {
streamInfo.addError(e);
}
streamInfo.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo, extractor));
return streamInfo;
@ -386,6 +392,11 @@ public class StreamInfo extends Info {
private List<StreamSegment> streamSegments = new ArrayList<>();
private List<MetaInfo> metaInfo = new ArrayList<>();
/**
* Preview frames, e.g. for the storyboard / seekbar thumbnail preview
*/
private List<Frameset> previewFrames = Collections.emptyList();
/**
* Get the stream type
*
@ -711,6 +722,14 @@ public class StreamInfo extends Info {
this.metaInfo = metaInfo;
}
public List<Frameset> getPreviewFrames() {
return previewFrames;
}
public void setPreviewFrames(final List<Frameset> previewFrames) {
this.previewFrames = previewFrames;
}
@Nonnull
public List<MetaInfo> getMetaInfo() {
return this.metaInfo;