Skip to content

Commit 14ba193

Browse files
committed
Added VideoQualityData
1 parent 2f2b188 commit 14ba193

File tree

7 files changed

+88
-37
lines changed

7 files changed

+88
-37
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.schabi.newpipe.extractor.streamdata.format.registry.VideoAudioFormatRegistry;
2020
import org.schabi.newpipe.extractor.streamdata.stream.AudioStream;
2121
import org.schabi.newpipe.extractor.streamdata.stream.VideoAudioStream;
22+
import org.schabi.newpipe.extractor.streamdata.stream.quality.VideoQualityData;
2223
import org.schabi.newpipe.extractor.streamdata.stream.simpleimpl.SimpleAudioStreamImpl;
2324
import org.schabi.newpipe.extractor.streamdata.stream.simpleimpl.SimpleVideoAudioStreamImpl;
2425

@@ -198,7 +199,10 @@ public List<VideoAudioStream> getVideoStreams() throws IOException, ExtractionEx
198199
deliveryData,
199200
// TODO: This looks wrong
200201
new VideoAudioFormatRegistry().getFromSuffix(dto.getUrlKey()),
201-
videoSize.getInt(0) + "x" + videoSize.getInt(1)
202+
new VideoQualityData(
203+
/*height=*/videoSize.getInt(1, VideoQualityData.UNKNOWN),
204+
/*width=*/videoSize.getInt(0, VideoQualityData.UNKNOWN),
205+
VideoQualityData.UNKNOWN)
202206
);
203207
})
204208
.collect(Collectors.toList());

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.schabi.newpipe.extractor.streamdata.format.registry.VideoAudioFormatRegistry;
2222
import org.schabi.newpipe.extractor.streamdata.stream.AudioStream;
2323
import org.schabi.newpipe.extractor.streamdata.stream.VideoAudioStream;
24+
import org.schabi.newpipe.extractor.streamdata.stream.quality.VideoQualityData;
2425
import org.schabi.newpipe.extractor.streamdata.stream.simpleimpl.SimpleAudioStreamImpl;
2526
import org.schabi.newpipe.extractor.streamdata.stream.simpleimpl.SimpleVideoAudioStreamImpl;
2627
import org.schabi.newpipe.extractor.utils.JsonUtils;
@@ -112,7 +113,11 @@ public List<VideoAudioStream> getVideoStreams() throws ExtractionException {
112113
null,
113114
AudioStream.UNKNOWN_BITRATE,
114115
new VideoAudioFormatRegistry().getFromMimeType(o.getString("mime_type")),
115-
o.getInt("height") + "p"
116+
new VideoQualityData(
117+
o.getInt("height", VideoQualityData.UNKNOWN),
118+
o.getInt("width", VideoQualityData.UNKNOWN),
119+
VideoQualityData.UNKNOWN
120+
)
116121
))
117122
.collect(Collectors.toList());
118123
}
@@ -139,8 +144,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
139144
conferenceData = JsonParser.object()
140145
.from(downloader.get(data.getString("conference_url")).responseBody());
141146
} catch (final JsonParserException jpe) {
142-
throw new ExtractionException("Could not parse json returned by URL: " + videoUrl,
143-
jpe);
147+
throw new ExtractionException("Could not parse json returned by URL: " + videoUrl, jpe);
144148
}
145149
}
146150

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.schabi.newpipe.extractor.streamdata.stream.Stream;
3737
import org.schabi.newpipe.extractor.streamdata.stream.SubtitleStream;
3838
import org.schabi.newpipe.extractor.streamdata.stream.VideoAudioStream;
39+
import org.schabi.newpipe.extractor.streamdata.stream.quality.VideoQualityData;
3940
import org.schabi.newpipe.extractor.streamdata.stream.simpleimpl.SimpleAudioStreamImpl;
4041
import org.schabi.newpipe.extractor.streamdata.stream.simpleimpl.SimpleSubtitleStreamImpl;
4142
import org.schabi.newpipe.extractor.streamdata.stream.simpleimpl.SimpleVideoAudioStreamImpl;
@@ -466,6 +467,7 @@ private void extractLiveVideoStreams() throws ParsingException {
466467
.stream()
467468
.filter(JsonObject.class::isInstance)
468469
.map(JsonObject.class::cast)
470+
// TODO Check! This is the master playlist!
469471
.map(stream -> new SimpleVideoAudioStreamImpl(
470472
new SimpleHLSDeliveryDataImpl(stream.getString(PLAYLIST_URL, "")),
471473
VideoAudioFormatRegistry.MPEG_4)
@@ -490,9 +492,10 @@ private void addStreamsFromArray(
490492
.map(JsonObject.class::cast)
491493
.filter(stream -> !isNullOrEmpty(getUrlFromStream(stream)))
492494
.forEach(stream -> {
493-
final String resolution = getResolutionFromStream(stream);
494-
495-
if (resolution.toLowerCase().contains("audio")) {
495+
final JsonObject resJson = stream.getObject("resolution");
496+
if (resJson.getString("label", "")
497+
.toLowerCase()
498+
.contains("audio")) {
496499
// An audio stream
497500
addNewStreams(
498501
this.audioStreams,
@@ -515,17 +518,15 @@ private void addStreamsFromArray(
515518
dd,
516519
new VideoAudioFormatRegistry()
517520
.getFromSuffix(getExtensionFromStream(s)),
518-
resolution
521+
new VideoQualityData(
522+
resJson.getInt("id", VideoQualityData.UNKNOWN),
523+
stream.getInt("fps", VideoQualityData.UNKNOWN))
519524
)
520525
);
521526
}
522527
});
523528
}
524529

525-
private static String getResolutionFromStream(@Nonnull final JsonObject stream) {
526-
return stream.getObject("resolution")
527-
.getString("label");
528-
}
529530

530531
private static String getStreamUrlKeyFromStream(@Nonnull final JsonObject stream) {
531532
return stream.has(FILE_URL) ? FILE_URL : FILE_DOWNLOAD_URL;
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
package org.schabi.newpipe.extractor.streamdata.stream;
22

33
import org.schabi.newpipe.extractor.streamdata.format.VideoAudioMediaFormat;
4+
import org.schabi.newpipe.extractor.streamdata.stream.quality.VideoQualityData;
45

56
import java.util.Objects;
67

7-
import javax.annotation.Nonnull;
88
import javax.annotation.Nullable;
99

1010
/**
1111
* Represents a video (only) stream.
1212
*/
1313
public interface VideoStream extends Stream {
14-
String UNKNOWN_RESOLUTION = "";
15-
1614
// TODO: Check if this can be non-null
1715
@Nullable
1816
default VideoAudioMediaFormat videoMediaFormat() {
1917
return null;
2018
}
2119

22-
// TODO: This should be a separate entity (containing e.g. height x width + fps)
23-
@Nonnull
24-
default String resolution() {
25-
return UNKNOWN_RESOLUTION;
26-
}
20+
VideoQualityData videoQualityData();
2721

2822
@Override
2923
default boolean equalsStream(@Nullable final Stream other) {
@@ -33,6 +27,6 @@ default boolean equalsStream(@Nullable final Stream other) {
3327

3428
final VideoStream otherVideoStream = (VideoStream) other;
3529
return Objects.equals(videoMediaFormat(), otherVideoStream.videoMediaFormat())
36-
&& Objects.equals(resolution(), otherVideoStream.resolution());
30+
&& videoQualityData().equalsVideoQualityData(otherVideoStream.videoQualityData());
3731
}
3832
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.schabi.newpipe.extractor.streamdata.stream.quality;
2+
3+
public class VideoQualityData {
4+
public static int UNKNOWN = -1;
5+
6+
private final int height;
7+
private final int width;
8+
private final int fps;
9+
10+
public VideoQualityData(final int height, final int width, final int fps) {
11+
this.height = height;
12+
this.width = width;
13+
this.fps = fps;
14+
}
15+
16+
public VideoQualityData(final int height, final int fps) {
17+
this(height, UNKNOWN, fps);
18+
}
19+
20+
public VideoQualityData(final int height) {
21+
this(height, UNKNOWN);
22+
}
23+
24+
public VideoQualityData() {
25+
this(UNKNOWN);
26+
}
27+
28+
29+
public int height() {
30+
return height;
31+
}
32+
33+
public int width() {
34+
return width;
35+
}
36+
37+
public int fps() {
38+
return fps;
39+
}
40+
41+
public boolean equalsVideoQualityData(final VideoQualityData other) {
42+
return height() == other.height()
43+
&& width() == other.width()
44+
&& fps() == other.fps();
45+
}
46+
}

extractor/src/main/java/org/schabi/newpipe/extractor/streamdata/stream/simpleimpl/SimpleVideoAudioStreamImpl.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.schabi.newpipe.extractor.streamdata.format.AudioMediaFormat;
55
import org.schabi.newpipe.extractor.streamdata.format.VideoAudioMediaFormat;
66
import org.schabi.newpipe.extractor.streamdata.stream.VideoAudioStream;
7+
import org.schabi.newpipe.extractor.streamdata.stream.quality.VideoQualityData;
78

89
import java.util.Objects;
910

@@ -18,35 +19,35 @@ public class SimpleVideoAudioStreamImpl extends AbstractStreamImpl implements Vi
1819
@Nullable
1920
private final VideoAudioMediaFormat videoAudioMediaFormat;
2021
@Nonnull
21-
private final String resolution;
22+
private final VideoQualityData videoQualityData;
2223

2324
public SimpleVideoAudioStreamImpl(
2425
@Nonnull final DeliveryData deliveryData,
2526
@Nullable final AudioMediaFormat audioMediaFormat,
2627
final int averageBitrate,
2728
@Nullable final VideoAudioMediaFormat videoAudioMediaFormat,
28-
@Nonnull final String resolution
29+
@Nonnull final VideoQualityData videoQualityData
2930
) {
3031
super(deliveryData);
3132
this.audioMediaFormat = audioMediaFormat;
3233
this.averageBitrate = averageBitrate;
3334
this.videoAudioMediaFormat = videoAudioMediaFormat;
34-
this.resolution = Objects.requireNonNull(resolution);
35+
this.videoQualityData = Objects.requireNonNull(videoQualityData);
3536
}
3637

3738
public SimpleVideoAudioStreamImpl(
3839
@Nonnull final DeliveryData deliveryData,
3940
@Nullable final VideoAudioMediaFormat videoAudioMediaFormat,
40-
@Nonnull final String resolution
41+
@Nonnull final VideoQualityData videoQualityData
4142
) {
42-
this(deliveryData, null, UNKNOWN_BITRATE, videoAudioMediaFormat, resolution);
43+
this(deliveryData, null, UNKNOWN_BITRATE, videoAudioMediaFormat, videoQualityData);
4344
}
4445

4546
public SimpleVideoAudioStreamImpl(
4647
@Nonnull final DeliveryData deliveryData,
4748
@Nullable final VideoAudioMediaFormat videoAudioMediaFormat
4849
) {
49-
this(deliveryData, videoAudioMediaFormat, UNKNOWN_RESOLUTION);
50+
this(deliveryData, videoAudioMediaFormat, new VideoQualityData());
5051
}
5152

5253
@Nullable
@@ -68,7 +69,7 @@ public VideoAudioMediaFormat videoMediaFormat() {
6869

6970
@Nonnull
7071
@Override
71-
public String resolution() {
72-
return resolution;
72+
public VideoQualityData videoQualityData() {
73+
return videoQualityData;
7374
}
7475
}

extractor/src/main/java/org/schabi/newpipe/extractor/streamdata/stream/simpleimpl/SimpleVideoStreamImpl.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.schabi.newpipe.extractor.streamdata.delivery.DeliveryData;
44
import org.schabi.newpipe.extractor.streamdata.format.VideoAudioMediaFormat;
55
import org.schabi.newpipe.extractor.streamdata.stream.VideoStream;
6+
import org.schabi.newpipe.extractor.streamdata.stream.quality.VideoQualityData;
67

78
import java.util.Objects;
89

@@ -13,27 +14,27 @@ public class SimpleVideoStreamImpl extends AbstractStreamImpl implements VideoSt
1314
@Nullable
1415
private final VideoAudioMediaFormat videoAudioMediaFormat;
1516
@Nonnull
16-
private final String resolution;
17+
private final VideoQualityData videoQualityData;
1718

1819
public SimpleVideoStreamImpl(
1920
@Nonnull final DeliveryData deliveryData,
2021
@Nullable final VideoAudioMediaFormat videoAudioMediaFormat,
21-
@Nonnull final String resolution
22+
@Nonnull final VideoQualityData videoQualityData
2223
) {
2324
super(deliveryData);
2425
this.videoAudioMediaFormat = videoAudioMediaFormat;
25-
this.resolution = Objects.requireNonNull(resolution);
26+
this.videoQualityData = Objects.requireNonNull(videoQualityData);
2627
}
2728

2829
public SimpleVideoStreamImpl(
2930
@Nonnull final DeliveryData deliveryData,
30-
@Nonnull final String resolution
31+
@Nonnull final VideoQualityData videoQualityData
3132
) {
32-
this(deliveryData, null, resolution);
33+
this(deliveryData, null, videoQualityData);
3334
}
3435

3536
public SimpleVideoStreamImpl(@Nonnull final DeliveryData deliveryData) {
36-
this(deliveryData, null, UNKNOWN_RESOLUTION);
37+
this(deliveryData, new VideoQualityData());
3738
}
3839

3940
@Nullable
@@ -44,7 +45,7 @@ public VideoAudioMediaFormat videoMediaFormat() {
4445

4546
@Nonnull
4647
@Override
47-
public String resolution() {
48-
return resolution;
48+
public VideoQualityData videoQualityData() {
49+
return videoQualityData;
4950
}
5051
}

0 commit comments

Comments
 (0)