Skip to content

Commit ae2755b

Browse files
authored
Merge pull request #1412 from FineFindus/feat/additional-itag-data
[YouTube] extract additional stream information
2 parents f5676c2 + 0617c88 commit ae2755b

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/ItagItem.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public static ItagItem getItag(final int itagId) throws ParsingException {
134134
public static final int AUDIO_CHANNELS_NOT_APPLICABLE_OR_UNKNOWN = -1;
135135
public static final long CONTENT_LENGTH_UNKNOWN = -1;
136136
public static final long APPROX_DURATION_MS_UNKNOWN = -1;
137+
public static final long LAST_MODIFIED_UNKOWN = -1;
137138

138139
/*//////////////////////////////////////////////////////////////////////////
139140
// Constructors and misc
@@ -266,6 +267,9 @@ public MediaFormat getMediaFormat() {
266267
private AudioTrackType audioTrackType;
267268
@Nullable
268269
private Locale audioLocale;
270+
private boolean isDrc;
271+
private long lastModified;
272+
private String xtags;
269273

270274
public int getBitrate() {
271275
return bitrate;
@@ -647,4 +651,77 @@ public Locale getAudioLocale() {
647651
public void setAudioLocale(@Nullable final Locale audioLocale) {
648652
this.audioLocale = audioLocale;
649653
}
654+
655+
/**
656+
* Whether the audio is using dynamic range compression (DRC).
657+
*
658+
* <p>
659+
* https://en.wikipedia.org/wiki/Dynamic_range_compression
660+
* </p>
661+
*
662+
* @return whether the audio is using DRC
663+
*/
664+
public Boolean isDrc() {
665+
return isDrc;
666+
}
667+
668+
/**
669+
* Sets whether the audio is using dynamic range compression (DRC).
670+
*
671+
* <p>
672+
* https://en.wikipedia.org/wiki/Dynamic_range_compression
673+
* </p>
674+
*
675+
* @param isDrc whether the audio has DRC applied
676+
*/
677+
public void setIsDrc(final Boolean isDrc) {
678+
this.isDrc = isDrc;
679+
}
680+
681+
682+
/**
683+
* When the stream was last modified.
684+
*
685+
* <p>
686+
* If the timestamp is unknown, {@link #LAST_MODIFIED_UNKOWN} is returned.
687+
* </p>
688+
*
689+
* @return unix timestamp of when the stream was last modified or
690+
* {@link #LAST_MODIFIED_UNKOWN} if the timestamp is unknown.
691+
*/
692+
public long getLastModified() {
693+
return lastModified;
694+
}
695+
696+
/**
697+
* Sets the timestamp when the stream was last modified.
698+
*
699+
* @param lastModified unix timestamp of when the stream was last modified
700+
*/
701+
public void setLastModified(final long lastModified) {
702+
this.lastModified = lastModified;
703+
}
704+
705+
/**
706+
* Extra tags about the stream.
707+
*
708+
* <p>
709+
* Contains a Base64 encoded protobuf key-value list of additional tags for the stream,
710+
* such as whether the stream is using {@link #isDrc()}.
711+
* </p>
712+
*
713+
* @return Base64-encoded extra tags.
714+
*/
715+
public String getXtags() {
716+
return xtags;
717+
}
718+
719+
/**
720+
* Sets extra tags of the stream.
721+
*
722+
* @param xtags extra tags of the stream
723+
*/
724+
public void setXtags(final String xtags) {
725+
this.xtags = xtags;
726+
}
650727
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,9 @@ private ItagInfo buildAndAddItagInfoToList(
14211421
itagItem.setIndexEnd(Integer.parseInt(indexRange.getString("end", "-1")));
14221422
itagItem.setQuality(formatData.getString("quality"));
14231423
itagItem.setCodec(codec);
1424+
itagItem.setIsDrc(formatData.getBoolean("isDrc", false));
1425+
itagItem.setLastModified(Long.parseLong(formatData.getString("lastModified", "-1")));
1426+
itagItem.setXtags(formatData.getString("xtags"));
14241427

14251428
if (streamType == StreamType.LIVE_STREAM || streamType == StreamType.POST_LIVE_STREAM) {
14261429
itagItem.setTargetDurationSec(formatData.getInt("targetDurationSec"));

0 commit comments

Comments
 (0)