Merge pull request #507 from vkay94/add-interval-to-stream-frames

Add durationPerFrame to Frameset
This commit is contained in:
Tobias Groza 2021-01-14 20:27:40 +01:00 committed by GitHub
commit cc51c5f6a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 2 deletions

View File

@ -992,7 +992,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
for (int i = 1; i < spec.length; ++i) { for (int i = 1; i < spec.length; ++i) {
final String[] parts = spec[i].split("#"); final String[] parts = spec[i].split("#");
if (parts.length != 8) { if (parts.length != 8 || Integer.parseInt(parts[5]) == 0) {
continue; continue;
} }
final int frameWidth = Integer.parseInt(parts[0]); final int frameWidth = Integer.parseInt(parts[0]);
@ -1016,6 +1016,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
frameWidth, frameWidth,
frameHeight, frameHeight,
totalCount, totalCount,
Integer.parseInt(parts[5]),
framesPerPageX, framesPerPageX,
framesPerPageY framesPerPageY
)); ));

View File

@ -8,12 +8,14 @@ public final class Frameset {
private int frameWidth; private int frameWidth;
private int frameHeight; private int frameHeight;
private int totalCount; private int totalCount;
private int durationPerFrame;
private int framesPerPageX; private int framesPerPageX;
private int framesPerPageY; private int framesPerPageY;
public Frameset(List<String> urls, int frameWidth, int frameHeight, int totalCount, int framesPerPageX, 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.frameWidth = frameWidth; this.frameWidth = frameWidth;
this.frameHeight = frameHeight; this.frameHeight = frameHeight;
this.framesPerPageX = framesPerPageX; this.framesPerPageX = framesPerPageX;
@ -61,4 +63,48 @@ public final class Frameset {
public int getFrameHeight() { public int getFrameHeight() {
return frameHeight; return frameHeight;
} }
/**
* @return duration per frame in milliseconds
*/
public int getDurationPerFrame() {
return durationPerFrame;
}
/**
* Returns the information for the frame at stream position.
*
* @param position Position in milliseconds
* @return An <code>int</code>-array containing the bounds and URL where the indexes are specified as
* followed:
*
* <ul>
* <li><code>0</code>: Index of the URL</li>
* <li><code>1</code>: Left bound</li>
* <li><code>2</code>: Top bound</li>
* <li><code>3</code>: Right bound</li>
* <li><code>4</code>: Bottom bound</li>
* </ul>
*/
public int[] getFrameBoundsAt(long position) {
if (position < 0 || position > ((totalCount + 1) * durationPerFrame)) {
// Return the first frame as fallback
return new int[] { 0, 0, 0, frameWidth, frameHeight };
}
final int framesPerStoryboard = framesPerPageX * framesPerPageY;
final int absoluteFrameNumber = Math.min((int) (position / durationPerFrame), totalCount);
final int relativeFrameNumber = absoluteFrameNumber % framesPerStoryboard;
final int rowIndex = Math.floorDiv(relativeFrameNumber, framesPerPageX);
final int columnIndex = relativeFrameNumber % framesPerPageY;
return new int[] {
/* storyboardIndex */ Math.floorDiv(absoluteFrameNumber, framesPerStoryboard),
/* left */ columnIndex * frameWidth,
/* top */ rowIndex * frameHeight,
/* right */ columnIndex * frameWidth + frameWidth,
/* bottom */ rowIndex * frameHeight + frameHeight };
}
} }

View File

@ -338,6 +338,8 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
assertIsValidUrl(url); assertIsValidUrl(url);
assertIsSecureUrl(url); assertIsSecureUrl(url);
} }
assertTrue(f.getDurationPerFrame() > 0);
assertEquals(f.getFrameBoundsAt(0)[3], f.getFrameWidth());
} }
} else { } else {
assertTrue(frames.isEmpty()); assertTrue(frames.isEmpty());