File tree Expand file tree Collapse file tree 13 files changed +74
-14
lines changed Expand file tree Collapse file tree 13 files changed +74
-14
lines changed Original file line number Diff line number Diff line change 44import org .schabi .newpipe .extractor .exceptions .ReCaptchaException ;
55import org .schabi .newpipe .extractor .localization .Localization ;
66
7- import javax .annotation .Nonnull ;
8- import javax .annotation .Nullable ;
97import java .io .IOException ;
108import java .util .List ;
119import java .util .Map ;
1210
11+ import javax .annotation .Nonnull ;
12+ import javax .annotation .Nullable ;
13+
1314/**
1415 * A base for downloader implementations that NewPipe will use
1516 * to download needed resources during extraction.
@@ -148,8 +149,27 @@ public Response post(final String url,
148149 /**
149150 * Do a request using the specified {@link Request} object.
150151 *
152+ * @param request The request to process
151153 * @return the result of the request
152154 */
153155 public abstract Response execute (@ Nonnull Request request )
154156 throws IOException , ReCaptchaException ;
157+
158+ /**
159+ * Get the size of the content that the url is pointing by firing a HEAD request.
160+ *
161+ * @param url an url pointing to the content
162+ * @return the size of the content, in bytes or -1 if unknown
163+ */
164+ public long getContentLength (final String url ) {
165+ try {
166+ final String contentLengthHeader = head (url ).getHeader ("Content-Length" );
167+ if (contentLengthHeader == null ) {
168+ return -1 ;
169+ }
170+ return Long .parseLong (contentLengthHeader );
171+ } catch (final Exception e ) {
172+ return -1 ;
173+ }
174+ }
155175}
Original file line number Diff line number Diff line change @@ -102,6 +102,11 @@ protected AbstractYoutubeDashManifestCreator(
102102 this .durationSecondsFallback = durationSecondsFallback ;
103103 }
104104
105+ @ Override
106+ public long getExpectedContentLength (final Downloader downloader ) {
107+ return downloader .getContentLength (itagInfo .getStreamUrl ());
108+ }
109+
105110 protected boolean isLiveDelivery () {
106111 return false ;
107112 }
Original file line number Diff line number Diff line change 2929 * Info object for previews of unopened videos, eg search results, related videos
3030 */
3131public class StreamInfoItem extends InfoItem {
32- private final boolean audioOnly ;
3332 private final boolean live ;
33+ private final boolean audioOnly ;
3434
3535 private String uploaderName ;
3636 private String shortDescription ;
@@ -47,11 +47,11 @@ public class StreamInfoItem extends InfoItem {
4747 public StreamInfoItem (final int serviceId ,
4848 final String url ,
4949 final String name ,
50- final boolean audioOnly ,
51- final boolean live ) {
50+ final boolean live ,
51+ final boolean audioOnly ) {
5252 super (InfoType .STREAM , serviceId , url , name );
53- this .audioOnly = audioOnly ;
5453 this .live = live ;
54+ this .audioOnly = audioOnly ;
5555 }
5656
5757 public boolean isAudioOnly () {
Original file line number Diff line number Diff line change @@ -48,8 +48,8 @@ public StreamInfoItem extract(final StreamInfoItemExtractor extractor) throws Pa
4848 getServiceId (),
4949 extractor .getUrl (),
5050 extractor .getName (),
51- extractor .isAudioOnly (),
52- extractor .isLive ());
51+ extractor .isLive (),
52+ extractor .isAudioOnly ());
5353
5454 // optional information
5555 try {
Original file line number Diff line number Diff line change 11package org .schabi .newpipe .extractor .streamdata .delivery ;
22
3+ import org .schabi .newpipe .extractor .downloader .Downloader ;
34import org .schabi .newpipe .extractor .streamdata .delivery .dashmanifestcreator .DashManifestCreator ;
45
56import javax .annotation .Nonnull ;
@@ -9,4 +10,9 @@ public interface DASHManifestDeliveryData extends DASHDeliveryData {
910 DashManifestCreator dashManifestCreator ();
1011
1112 String getCachedDashManifestAsString ();
13+
14+ @ Override
15+ default long getExpectedContentLength (final Downloader downloader ) {
16+ return dashManifestCreator ().getExpectedContentLength (downloader );
17+ }
1218}
Original file line number Diff line number Diff line change 11package org .schabi .newpipe .extractor .streamdata .delivery ;
22
3+ import org .schabi .newpipe .extractor .downloader .Downloader ;
4+
35public interface DeliveryData {
4- // Only a marker so far
6+ /**
7+ * Returns the expected content length/size of the data.
8+ *
9+ * @param downloader The downloader that may be used for fetching (HTTP HEAD).
10+ * @return the expected size/content length or <code>-1</code> if unknown
11+ */
12+ long getExpectedContentLength (Downloader downloader );
513}
Original file line number Diff line number Diff line change 11package org .schabi .newpipe .extractor .streamdata .delivery ;
22
3+ import org .schabi .newpipe .extractor .downloader .Downloader ;
4+
35import javax .annotation .Nonnull ;
46
57public interface UrlBasedDeliveryData extends DeliveryData {
68 @ Nonnull
79 String url ();
10+
11+ @ Override
12+ default long getExpectedContentLength (final Downloader downloader ) {
13+ return downloader .getContentLength (url ());
14+ }
815}
Original file line number Diff line number Diff line change 11package org .schabi .newpipe .extractor .streamdata .delivery .dashmanifestcreator ;
22
3+ import org .schabi .newpipe .extractor .downloader .Downloader ;
4+
35import javax .annotation .Nonnull ;
46
57public interface DashManifestCreator {
68
79 /**
810 * Generates the DASH manifest.
11+ *
912 * @return The dash manifest as string.
1013 * @throws DashManifestCreationException May throw a CreationException
1114 */
1215 @ Nonnull
1316 String generateManifest ();
17+
18+ /**
19+ * See
20+ * {@link org.schabi.newpipe.extractor.streamdata.delivery.DeliveryData#getExpectedContentLength(Downloader)}
21+ */
22+ long getExpectedContentLength (Downloader downloader );
1423}
Original file line number Diff line number Diff line change @@ -39,5 +39,10 @@ default boolean autoGenerated() {
3939 *
4040 * @return the {@link Locale locale} of the subtitles
4141 */
42+ @ Nonnull
4243 Locale locale ();
44+
45+ default String getDisplayLanguageName () {
46+ return locale ().getDisplayName (locale ());
47+ }
4348}
Original file line number Diff line number Diff line change 1010 */
1111public interface VideoStream extends Stream <VideoAudioMediaFormat > {
1212 @ Nonnull
13- VideoQualityData videoQualityData ();
13+ VideoQualityData qualityData ();
1414}
You can’t perform that action at this time.
0 commit comments