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"); 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 String url = spec[0];
final ArrayList<Frameset> result = new ArrayList<>(spec.length - 1); final ArrayList<Frameset> result = new ArrayList<>(spec.length - 1);

View File

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

View File

@ -335,6 +335,12 @@ public class StreamInfo extends Info {
streamInfo.addError(e); streamInfo.addError(e);
} }
try {
streamInfo.setPreviewFrames(extractor.getFrames());
} catch (Exception e) {
streamInfo.addError(e);
}
streamInfo.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo, extractor)); streamInfo.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo, extractor));
return streamInfo; return streamInfo;
@ -386,6 +392,11 @@ public class StreamInfo extends Info {
private List<StreamSegment> streamSegments = new ArrayList<>(); private List<StreamSegment> streamSegments = new ArrayList<>();
private List<MetaInfo> metaInfo = 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 * Get the stream type
* *
@ -711,6 +722,14 @@ public class StreamInfo extends Info {
this.metaInfo = metaInfo; this.metaInfo = metaInfo;
} }
public List<Frameset> getPreviewFrames() {
return previewFrames;
}
public void setPreviewFrames(final List<Frameset> previewFrames) {
this.previewFrames = previewFrames;
}
@Nonnull @Nonnull
public List<MetaInfo> getMetaInfo() { public List<MetaInfo> getMetaInfo() {
return this.metaInfo; return this.metaInfo;