Skip to content

Commit 16ae77e

Browse files
committed
Re-Implemented Itags
1 parent 8d9313f commit 16ae77e

17 files changed

+371
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.schabi.newpipe.extractor.services.youtube.itag;
2+
3+
import org.schabi.newpipe.extractor.streamdata.format.AudioMediaFormat;
4+
5+
import javax.annotation.Nonnull;
6+
7+
public interface AudioItagFormat extends ItagFormat {
8+
@Nonnull
9+
AudioMediaFormat audioMediaFormat();
10+
11+
int averageBitrate();
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.schabi.newpipe.extractor.services.youtube.itag;
2+
3+
import org.schabi.newpipe.extractor.services.youtube.itag.delivery.ItagFormatDeliveryData;
4+
5+
public interface ItagFormat {
6+
int id();
7+
8+
ItagFormatDeliveryData deliveryData();
9+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package org.schabi.newpipe.extractor.services.youtube.itag;
2+
3+
import static org.schabi.newpipe.extractor.services.youtube.itag.delivery.simpleimpl.SimpleItagDeliveryDataBuilder.dash;
4+
import static org.schabi.newpipe.extractor.services.youtube.itag.delivery.simpleimpl.SimpleItagDeliveryDataBuilder.hls;
5+
import static org.schabi.newpipe.extractor.streamdata.format.registry.VideoAudioFormatRegistry.MPEG_4;
6+
import static org.schabi.newpipe.extractor.streamdata.format.registry.VideoAudioFormatRegistry.V3GPP;
7+
import static org.schabi.newpipe.extractor.streamdata.format.registry.VideoAudioFormatRegistry.WEBM;
8+
import static org.schabi.newpipe.extractor.streamdata.stream.quality.VideoQualityData.fromHeight;
9+
import static org.schabi.newpipe.extractor.streamdata.stream.quality.VideoQualityData.fromHeightFps;
10+
import static org.schabi.newpipe.extractor.streamdata.stream.quality.VideoQualityData.fromHeightWidth;
11+
12+
import org.schabi.newpipe.extractor.services.youtube.itag.simpleimpl.SimpleAudioItagFormat;
13+
import org.schabi.newpipe.extractor.services.youtube.itag.simpleimpl.SimpleVideoAudioItagFormat;
14+
import org.schabi.newpipe.extractor.services.youtube.itag.simpleimpl.SimpleVideoItagFormat;
15+
import org.schabi.newpipe.extractor.streamdata.format.registry.AudioFormatRegistry;
16+
17+
/**
18+
* https://github.com/ytdl-org/youtube-dl/blob/9aa8e5340f3d5ece372b983f8e399277ca1f1fe4/youtube_dl/extractor/youtube.py#L1195
19+
*/
20+
public final class ItagFormatRegistry {
21+
22+
public static final VideoAudioItagFormat[] VIDEO_AUDIO_FORMATS = new VideoAudioItagFormat[] {
23+
// v-- Video-codec: mp4v; Audio-codec: aac --v
24+
new SimpleVideoAudioItagFormat(17, V3GPP, fromHeightWidth(144, 176), 24),
25+
// v-- Video-codec: h264; Audio-codec: aac --v
26+
new SimpleVideoAudioItagFormat(18, MPEG_4, fromHeightWidth(360, 640), 96),
27+
new SimpleVideoAudioItagFormat(22, MPEG_4, fromHeightWidth(720, 1280), 192),
28+
29+
// Note: According to yt-dl Itag 34 and 35 are flv-files
30+
new SimpleVideoAudioItagFormat(34, MPEG_4, fromHeightWidth(360, 640), 128),
31+
new SimpleVideoAudioItagFormat(35, MPEG_4, fromHeightWidth(480, 854), 128),
32+
33+
// Itag 36 is no longer used because the height is unstable and it's not returned by YT
34+
// see also: https://github.com/ytdl-org/youtube-dl/blob/9aa8e5340f3d5ece372b983f8e399277ca1f1fe4/youtube_dl/extractor/youtube.py#L1204
35+
new SimpleVideoAudioItagFormat(37, MPEG_4, fromHeightWidth(1080, 1920), 192),
36+
new SimpleVideoAudioItagFormat(38, MPEG_4, fromHeightWidth(3072, 4092), 192),
37+
38+
// v-- Video-codec: vp8; Audio-codec: vorbis --v
39+
new SimpleVideoAudioItagFormat(43, WEBM, fromHeightWidth(360, 640), 128),
40+
new SimpleVideoAudioItagFormat(44, WEBM, fromHeightWidth(480, 854), 128),
41+
new SimpleVideoAudioItagFormat(45, WEBM, fromHeightWidth(720, 1280), 192),
42+
new SimpleVideoAudioItagFormat(46, WEBM, fromHeightWidth(1080, 1920), 192),
43+
44+
// HLS (used for live streaming)
45+
// v-- Video-codec: h264; Audio-codec: acc --v
46+
new SimpleVideoAudioItagFormat(91, MPEG_4, fromHeight(144), 48, hls()),
47+
new SimpleVideoAudioItagFormat(92, MPEG_4, fromHeight(240), 48, hls()),
48+
new SimpleVideoAudioItagFormat(93, MPEG_4, fromHeight(360), 128, hls()),
49+
new SimpleVideoAudioItagFormat(94, MPEG_4, fromHeight(480), 128, hls()),
50+
new SimpleVideoAudioItagFormat(95, MPEG_4, fromHeight(720), 256, hls()),
51+
new SimpleVideoAudioItagFormat(96, MPEG_4, fromHeight(1080), 256, hls()),
52+
new SimpleVideoAudioItagFormat(132, MPEG_4, fromHeight(240), 48, hls()),
53+
new SimpleVideoAudioItagFormat(151, MPEG_4, fromHeight(72), 24, hls())
54+
};
55+
56+
public static final AudioItagFormat[] AUDIO_FORMATS = new AudioItagFormat[] {
57+
// DASH MP4 audio
58+
// v-- Audio-codec: aac --v
59+
new SimpleAudioItagFormat(139, AudioFormatRegistry.M4A, 48, dash()),
60+
new SimpleAudioItagFormat(140, AudioFormatRegistry.M4A, 128, dash()),
61+
new SimpleAudioItagFormat(141, AudioFormatRegistry.M4A, 256, dash()),
62+
63+
// DASH WEBM audio
64+
// v-- Audio-codec: vorbis --v
65+
new SimpleAudioItagFormat(171, AudioFormatRegistry.WEBMA, 128, dash()),
66+
new SimpleAudioItagFormat(172, AudioFormatRegistry.WEBMA, 256, dash()),
67+
68+
// DASH WEBM audio with opus inside
69+
// v-- Audio-codec: opus --v
70+
new SimpleAudioItagFormat(249, AudioFormatRegistry.WEBMA_OPUS, 50, dash()),
71+
new SimpleAudioItagFormat(250, AudioFormatRegistry.WEBMA_OPUS, 70, dash()),
72+
new SimpleAudioItagFormat(251, AudioFormatRegistry.WEBMA_OPUS, 160, dash())
73+
};
74+
75+
public static final VideoItagFormat[] VIDEO_FORMATS = new VideoItagFormat[] {
76+
// DASH MP4 video
77+
// v-- Video-codec: h264 --v
78+
new SimpleVideoItagFormat(133, MPEG_4, fromHeight(240), dash()),
79+
new SimpleVideoItagFormat(134, MPEG_4, fromHeight(360), dash()),
80+
new SimpleVideoItagFormat(135, MPEG_4, fromHeight(480), dash()),
81+
new SimpleVideoItagFormat(136, MPEG_4, fromHeight(720), dash()),
82+
new SimpleVideoItagFormat(137, MPEG_4, fromHeight(1080), dash()),
83+
// Itag 138 has an unknown height and is ignored
84+
new SimpleVideoItagFormat(160, MPEG_4, fromHeight(144), dash()),
85+
new SimpleVideoItagFormat(212, MPEG_4, fromHeight(480), dash()),
86+
new SimpleVideoItagFormat(298, MPEG_4, fromHeightFps(720, 60), dash()),
87+
new SimpleVideoItagFormat(299, MPEG_4, fromHeightFps(1080, 60), dash()),
88+
new SimpleVideoItagFormat(266, MPEG_4, fromHeight(2160), dash()),
89+
90+
// DASH WEBM video
91+
// v-- Video-codec: vp9 --v
92+
new SimpleVideoItagFormat(278, WEBM, fromHeight(144), dash()),
93+
new SimpleVideoItagFormat(242, WEBM, fromHeight(240), dash()),
94+
new SimpleVideoItagFormat(243, WEBM, fromHeight(360), dash()),
95+
// Itag 244, 245 and 246 are identical?
96+
new SimpleVideoItagFormat(244, WEBM, fromHeight(480), dash()),
97+
new SimpleVideoItagFormat(245, WEBM, fromHeight(480), dash()),
98+
new SimpleVideoItagFormat(246, WEBM, fromHeight(480), dash()),
99+
new SimpleVideoItagFormat(247, WEBM, fromHeight(720), dash()),
100+
new SimpleVideoItagFormat(248, WEBM, fromHeight(1080), dash()),
101+
new SimpleVideoItagFormat(271, WEBM, fromHeight(1440), dash()),
102+
// Itag 272 is either 3840x2160 (RtoitU2A-3E) or 7680x4320 (sLprVF6d7Ug)
103+
new SimpleVideoItagFormat(272, WEBM, fromHeight(2160), dash()),
104+
105+
new SimpleVideoItagFormat(302, WEBM, fromHeightFps(720, 60), dash()),
106+
new SimpleVideoItagFormat(303, WEBM, fromHeightFps(1080, 60), dash()),
107+
new SimpleVideoItagFormat(308, WEBM, fromHeightFps(1440, 60), dash()),
108+
new SimpleVideoItagFormat(312, WEBM, fromHeight(2160), dash()),
109+
new SimpleVideoItagFormat(315, WEBM, fromHeightFps(2160, 60), dash()),
110+
};
111+
112+
113+
private ItagFormatRegistry() {
114+
// No impl
115+
}
116+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.schabi.newpipe.extractor.services.youtube.itag;
2+
3+
public interface VideoAudioItagFormat extends VideoItagFormat {
4+
int averageBitrate();
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.schabi.newpipe.extractor.services.youtube.itag;
2+
3+
import org.schabi.newpipe.extractor.streamdata.format.VideoAudioMediaFormat;
4+
import org.schabi.newpipe.extractor.streamdata.stream.quality.VideoQualityData;
5+
6+
import javax.annotation.Nonnull;
7+
8+
public interface VideoItagFormat extends ItagFormat {
9+
@Nonnull
10+
VideoAudioMediaFormat videoMediaFormat();
11+
12+
@Nonnull
13+
VideoQualityData videoQualityData();
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.schabi.newpipe.extractor.services.youtube.itag.delivery;
2+
3+
public interface DASHItagFormatDeliveryData extends ItagFormatDeliveryData {
4+
// Just a marker interface for now
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.schabi.newpipe.extractor.services.youtube.itag.delivery;
2+
3+
public interface HLSItagFormatDeliveryData extends ItagFormatDeliveryData {
4+
// Just a marker interface for now
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.schabi.newpipe.extractor.services.youtube.itag.delivery;
2+
3+
public interface ItagFormatDeliveryData {
4+
// Just a marker interface
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.schabi.newpipe.extractor.services.youtube.itag.delivery;
2+
3+
public interface ProgressiveHTTPItagFormatDeliveryData extends ItagFormatDeliveryData {
4+
// Just a marker interface for now
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.schabi.newpipe.extractor.services.youtube.itag.delivery.simpleimpl;
2+
3+
import org.schabi.newpipe.extractor.services.youtube.itag.delivery.DASHItagFormatDeliveryData;
4+
5+
public class SimpleDASHItagFormatDeliveryData implements DASHItagFormatDeliveryData {
6+
// Just a marker for now
7+
}

0 commit comments

Comments
 (0)