Skip to content

Commit b90a0df

Browse files
committed
YT: Use new DASHManifestCreators
1 parent fecd409 commit b90a0df

File tree

4 files changed

+48
-25
lines changed

4 files changed

+48
-25
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/dashmanifestcreator/YoutubePostLiveStreamDvrDashManifestCreator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
public class YoutubePostLiveStreamDvrDashManifestCreator extends AbstractYoutubeDashManifestCreator {
1919

20-
protected YoutubePostLiveStreamDvrDashManifestCreator(@Nonnull final ItagInfo<?> itagInfo,
21-
final long durationSecondsFallback) {
20+
public YoutubePostLiveStreamDvrDashManifestCreator(@Nonnull final ItagInfo<?> itagInfo,
21+
final long durationSecondsFallback) {
2222
super(itagInfo, durationSecondsFallback);
2323
}
2424

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
import org.schabi.newpipe.extractor.services.youtube.YoutubeJavaScriptExtractor;
6868
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
6969
import org.schabi.newpipe.extractor.services.youtube.YoutubeThrottlingDecrypter;
70+
import org.schabi.newpipe.extractor.services.youtube.dashmanifestcreator.YoutubeOtfDashManifestCreator;
71+
import org.schabi.newpipe.extractor.services.youtube.dashmanifestcreator.YoutubePostLiveStreamDvrDashManifestCreator;
72+
import org.schabi.newpipe.extractor.services.youtube.dashmanifestcreator.YoutubeProgressiveDashManifestCreator;
7073
import org.schabi.newpipe.extractor.services.youtube.itag.delivery.HLSItagFormatDeliveryData;
7174
import org.schabi.newpipe.extractor.services.youtube.itag.delivery.ItagFormatDeliveryData;
7275
import org.schabi.newpipe.extractor.services.youtube.itag.delivery.ProgressiveHTTPItagFormatDeliveryData;
@@ -83,6 +86,8 @@
8386
import org.schabi.newpipe.extractor.stream.StreamExtractor;
8487
import org.schabi.newpipe.extractor.stream.StreamSegment;
8588
import org.schabi.newpipe.extractor.streamdata.delivery.DeliveryData;
89+
import org.schabi.newpipe.extractor.streamdata.delivery.dashmanifestcreator.DashManifestCreator;
90+
import org.schabi.newpipe.extractor.streamdata.delivery.simpleimpl.SimpleDASHManifestDeliveryDataImpl;
8691
import org.schabi.newpipe.extractor.streamdata.delivery.simpleimpl.SimpleHLSDeliveryDataImpl;
8792
import org.schabi.newpipe.extractor.streamdata.delivery.simpleimpl.SimpleProgressiveHTTPDeliveryDataImpl;
8893
import org.schabi.newpipe.extractor.streamdata.format.registry.SubtitleFormatRegistry;
@@ -1204,16 +1209,27 @@ private <I extends ItagFormat<?>> DeliveryData buildDeliveryData(final ItagInfo<
12041209
}
12051210

12061211
// DASH
1207-
// TODO
1208-
if ("FORMAT_STREAM_TYPE_OTF".equalsIgnoreCase(itagInfo.getType())) {
1209-
// OTF DASH MANIFEST
1210-
} else if (isPostLive()) {
1211-
// YoutubePostLiveStreamDvrDashManifestCreator
1212+
// Duration in seconds used as fallback inside the dashManifestCreators
1213+
long durationInSec;
1214+
try {
1215+
durationInSec = getLength();
1216+
} catch (final ParsingException e) {
1217+
durationInSec = -1;
12121218
}
1213-
// YoutubeProgressiveDashManifestCreator
12141219

1220+
return new SimpleDASHManifestDeliveryDataImpl(
1221+
getDashManifestCreatorConstructor(itagInfo).apply(itagInfo, durationInSec));
1222+
}
12151223

1216-
return null;
1224+
private BiFunction<ItagInfo<?>, Long, DashManifestCreator> getDashManifestCreatorConstructor(
1225+
final ItagInfo<?> itagInfo
1226+
) {
1227+
if ("FORMAT_STREAM_TYPE_OTF".equalsIgnoreCase(itagInfo.getType())) {
1228+
return YoutubeOtfDashManifestCreator::new;
1229+
} else if (isPostLive()) {
1230+
return YoutubePostLiveStreamDvrDashManifestCreator::new;
1231+
}
1232+
return YoutubeProgressiveDashManifestCreator::new;
12171233
}
12181234

12191235
@Nonnull
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
package org.schabi.newpipe.extractor.streamdata.delivery;
22

3+
import org.schabi.newpipe.extractor.streamdata.delivery.dashmanifestcreator.DashManifestCreator;
4+
35
import javax.annotation.Nonnull;
46

57
public interface DASHManifestDeliveryData extends DASHDeliveryData {
6-
/**
7-
* Returns the base url for the DashManifest.
8-
*
9-
* @return
10-
*/
11-
// TODO: Check removal
128
@Nonnull
13-
default String getBaseUrl() {
14-
return "";
15-
}
9+
DashManifestCreator getDashManifestCreator();
1610

17-
String getManifestAsString();
11+
String getCachedDashManifestAsString();
1812
}

extractor/src/main/java/org/schabi/newpipe/extractor/streamdata/delivery/simpleimpl/SimpleDASHManifestDeliveryDataImpl.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.schabi.newpipe.extractor.streamdata.delivery.simpleimpl;
22

33
import org.schabi.newpipe.extractor.streamdata.delivery.DASHManifestDeliveryData;
4+
import org.schabi.newpipe.extractor.streamdata.delivery.dashmanifestcreator.DashManifestCreator;
45

56
import java.util.Objects;
6-
import java.util.function.Supplier;
77

88
import javax.annotation.Nonnull;
99

@@ -21,14 +21,27 @@
2121
public class SimpleDASHManifestDeliveryDataImpl extends AbstractDeliveryDataImpl
2222
implements DASHManifestDeliveryData {
2323
@Nonnull
24-
private final Supplier<String> dashManifestBuilder;
24+
private final DashManifestCreator dashManifestCreator;
2525

26-
public SimpleDASHManifestDeliveryDataImpl(@Nonnull final Supplier<String> dashManifestBuilder) {
27-
this.dashManifestBuilder = Objects.requireNonNull(dashManifestBuilder);
26+
private String cachedDashManifest;
27+
28+
public SimpleDASHManifestDeliveryDataImpl(
29+
@Nonnull final DashManifestCreator dashManifestCreator
30+
) {
31+
this.dashManifestCreator = Objects.requireNonNull(dashManifestCreator);
32+
}
33+
34+
@Override
35+
@Nonnull
36+
public DashManifestCreator getDashManifestCreator() {
37+
return dashManifestCreator;
2838
}
2939

3040
@Override
31-
public String getManifestAsString() {
32-
return dashManifestBuilder.get();
41+
public String getCachedDashManifestAsString() {
42+
if (cachedDashManifest != null) {
43+
cachedDashManifest = getDashManifestCreator().generateManifest();
44+
}
45+
return cachedDashManifest;
3346
}
3447
}

0 commit comments

Comments
 (0)