Skip to content

Commit f924265

Browse files
committed
Add descriptive audio properties
Also improve AudioStream's audio language documentation
1 parent 99ab977 commit f924265

1 file changed

Lines changed: 65 additions & 8 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/stream/AudioStream.java

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ public final class AudioStream extends Stream {
4343
private String codec;
4444

4545
// Fields about the audio track id/name
46-
private String audioTrackId;
47-
private String audioTrackName;
46+
@Nullable
47+
private final String audioTrackId;
48+
@Nullable
49+
private final String audioTrackName;
50+
private final boolean isDescriptive;
51+
4852
@Nullable
4953
private ItagItem itagItem;
5054

@@ -66,6 +70,7 @@ public static final class Builder {
6670
private String audioTrackId;
6771
@Nullable
6872
private String audioTrackName;
73+
private boolean isDescriptive;
6974
@Nullable
7075
private ItagItem itagItem;
7176

@@ -185,7 +190,11 @@ public Builder setAverageBitrate(final int averageBitrate) {
185190
/**
186191
* Set the audio track id of the {@link AudioStream}.
187192
*
188-
* @param audioTrackId the audio track id of the {@link AudioStream}
193+
* <p>
194+
* The default value is {@code null}.
195+
* </p>
196+
*
197+
* @param audioTrackId the audio track id of the {@link AudioStream}, which can be null
189198
* @return this {@link Builder} instance
190199
*/
191200
public Builder setAudioTrackId(@Nullable final String audioTrackId) {
@@ -196,14 +205,41 @@ public Builder setAudioTrackId(@Nullable final String audioTrackId) {
196205
/**
197206
* Set the audio track name of the {@link AudioStream}.
198207
*
199-
* @param audioTrackName the audio track name of the {@link AudioStream}
208+
* <p>
209+
* The default value is {@code null}.
210+
* </p>
211+
*
212+
* @param audioTrackName the audio track name of the {@link AudioStream}, which can be null
200213
* @return this {@link Builder} instance
201214
*/
202215
public Builder setAudioTrackName(@Nullable final String audioTrackName) {
203216
this.audioTrackName = audioTrackName;
204217
return this;
205218
}
206219

220+
/**
221+
* Set whether this {@link AudioStream} is a descriptive audio.
222+
*
223+
* <p>
224+
* A descriptive audio is an audio in which descriptions of visual elements of a video are
225+
* added in the original audio, with the goal to make a video more accessible to blind and
226+
* visually impaired people.
227+
* </p>
228+
*
229+
* <p>
230+
* The default value is {@code false}.
231+
* </p>
232+
*
233+
* @param isDescriptive whether this {@link AudioStream} is a descriptive audio
234+
* @return this {@link Builder} instance
235+
* @see <a href="https://en.wikipedia.org/wiki/Audio_description">
236+
* https://en.wikipedia.org/wiki/Audio_description</a>
237+
*/
238+
public Builder setIsDescriptive(final boolean isDescriptive) {
239+
this.isDescriptive = isDescriptive;
240+
return this;
241+
}
242+
207243
/**
208244
* Set the {@link ItagItem} corresponding to the {@link AudioStream}.
209245
*
@@ -257,7 +293,7 @@ public AudioStream build() {
257293
}
258294

259295
return new AudioStream(id, content, isUrl, mediaFormat, deliveryMethod, averageBitrate,
260-
manifestUrl, audioTrackId, audioTrackName, itagItem);
296+
manifestUrl, audioTrackId, audioTrackName, isDescriptive, itagItem);
261297
}
262298
}
263299

@@ -291,6 +327,7 @@ private AudioStream(@Nonnull final String id,
291327
@Nullable final String manifestUrl,
292328
@Nullable final String audioTrackId,
293329
@Nullable final String audioTrackName,
330+
final boolean isDescriptive,
294331
@Nullable final ItagItem itagItem) {
295332
super(id, content, isUrl, format, deliveryMethod, manifestUrl);
296333
if (itagItem != null) {
@@ -307,6 +344,7 @@ private AudioStream(@Nonnull final String id,
307344
this.averageBitrate = averageBitrate;
308345
this.audioTrackId = audioTrackId;
309346
this.audioTrackName = audioTrackName;
347+
this.isDescriptive = isDescriptive;
310348
}
311349

312350
/**
@@ -316,7 +354,8 @@ private AudioStream(@Nonnull final String id,
316354
public boolean equalStats(final Stream cmp) {
317355
return super.equalStats(cmp) && cmp instanceof AudioStream
318356
&& averageBitrate == ((AudioStream) cmp).averageBitrate
319-
&& Objects.equals(audioTrackId, ((AudioStream) cmp).audioTrackId);
357+
&& Objects.equals(audioTrackId, ((AudioStream) cmp).audioTrackId)
358+
&& isDescriptive == ((AudioStream) cmp).isDescriptive;
320359
}
321360

322361
/**
@@ -421,15 +460,33 @@ public String getAudioTrackId() {
421460
}
422461

423462
/**
424-
* Get the name of the audio track.
463+
* Get the name of the audio track, which may be {@code null} if this information is not
464+
* provided by the service.
425465
*
426-
* @return the name of the audio track
466+
* @return the name of the audio track or {@code null}
427467
*/
428468
@Nullable
429469
public String getAudioTrackName() {
430470
return audioTrackName;
431471
}
432472

473+
/**
474+
* Returns whether this stream is a descriptive audio.
475+
*
476+
* <p>
477+
* A descriptive audio is an audio in which descriptions of visual elements of a video are
478+
* added in the original audio, with the goal to make a video more accessible to blind and
479+
* visually impaired people.
480+
* </p>
481+
*
482+
* @return {@code true} this audio stream is a descriptive audio, {@code false} otherwise
483+
* @see <a href="https://en.wikipedia.org/wiki/Audio_description">
484+
* https://en.wikipedia.org/wiki/Audio_description</a>
485+
*/
486+
public boolean isDescriptive() {
487+
return isDescriptive;
488+
}
489+
433490
/**
434491
* {@inheritDoc}
435492
*/

0 commit comments

Comments
 (0)