Skip to content

Commit 8a7ac03

Browse files
committed
[YouTube] Mark auto-dubbed streams as auto-generated
Marks auto-dubbed audio tracks as auto-generated. This allows applications to handle them differently to non-auto-generated audio tracks, e.g. display this information to the user.
1 parent 741f967 commit 8a7ac03

5 files changed

Lines changed: 1477 additions & 2 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ public ItagItem(@Nonnull final ItagItem itagItem) {
218218
this.isDrc = itagItem.isDrc;
219219
this.lastModified = itagItem.lastModified;
220220
this.xtags = itagItem.xtags;
221+
this.autoGenerated = itagItem.autoGenerated;
221222
}
222223

223224
public MediaFormat getMediaFormat() {
@@ -273,6 +274,7 @@ public MediaFormat getMediaFormat() {
273274
private boolean isDrc;
274275
private long lastModified;
275276
private String xtags;
277+
private boolean autoGenerated;
276278

277279
public int getBitrate() {
278280
return bitrate;
@@ -727,4 +729,23 @@ public String getXtags() {
727729
public void setXtags(final String xtags) {
728730
this.xtags = xtags;
729731
}
732+
733+
/**
734+
* Return whether the stream is auto-generated.
735+
*
736+
* @return {@code true} if the stream is auto-generated, {@code false} otherwise
737+
*/
738+
public boolean isAutoGenerated() {
739+
return autoGenerated;
740+
}
741+
742+
743+
/**
744+
* Set whether the stream has been auto-generated.
745+
*
746+
* @param autoGenerated whether the stream has been automatically generated
747+
*/
748+
public void setAutoGenerated(final boolean autoGenerated) {
749+
this.autoGenerated = autoGenerated;
750+
}
730751
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,8 +1365,9 @@ private ItagInfo buildAndAddItagInfoToList(
13651365
itagItem.setAudioTrackType(YoutubeParsingHelper.extractAudioTrackType(streamUrl));
13661366
}
13671367

1368-
itagItem.setAudioTrackName(formatData.getObject("audioTrack")
1369-
.getString("displayName"));
1368+
final JsonObject audioTrack = formatData.getObject("audioTrack");
1369+
itagItem.setAudioTrackName(audioTrack.getString("displayName"));
1370+
itagItem.setAutoGenerated(audioTrack.getBoolean("isAutoDubbed", false));
13701371
}
13711372

13721373
// YouTube return the content length and the approximate duration as strings

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,4 +622,24 @@ void testCheckDescriptiveAudio() throws Exception {
622622
.anyMatch(s -> s.getAudioTrackType() == AudioTrackType.DESCRIPTIVE));
623623
}
624624
}
625+
626+
public static class AutoGeneratedAudio extends DefaultSimpleExtractorTest<StreamExtractor>
627+
implements InitYoutubeTest {
628+
private static final String ID = "3JW3J4_Ukrs";
629+
private static final String URL = BASE_URL + ID;
630+
631+
@Override
632+
protected StreamExtractor createExtractor() throws Exception {
633+
return YouTube.getStreamExtractor(URL);
634+
}
635+
636+
@Test
637+
void testAutogeneratedTracks() throws Exception {
638+
assertFalse(extractor().getAudioStreams().isEmpty());
639+
640+
assertTrue(extractor().getAudioStreams()
641+
.stream()
642+
.anyMatch(s -> s.getItagItem().isAutoGenerated()));
643+
}
644+
}
625645
}

0 commit comments

Comments
 (0)