Taylor Fox Dahlin commited on
Commit
c19b467
·
unverified ·
1 Parent(s): b4ef682

Added new itags, adjusted tests accordingly. (#865)

Browse files
Files changed (2) hide show
  1. pytube/itags.py +83 -85
  2. tests/test_query.py +7 -7
pytube/itags.py CHANGED
@@ -2,7 +2,7 @@
2
  """This module contains a lookup table of YouTube's itag values."""
3
  from typing import Dict
4
 
5
- ITAGS = {
6
  5: ("240p", "64kbps"),
7
  6: ("270p", "64kbps"),
8
  13: ("144p", None),
@@ -35,93 +35,91 @@ ITAGS = {
35
  102: ("720p", "192kbps"),
36
  132: ("240p", "48kbps"),
37
  151: ("720p", "24kbps"),
 
 
 
 
 
38
  # DASH Video
39
- 133: ("240p", None),
40
- 134: ("360p", None),
41
- 135: ("480p", None),
42
- 136: ("720p", None),
43
- 137: ("1080p", None),
44
- 138: ("2160p", None),
45
- 160: ("144p", None),
46
- 167: ("360p", None),
47
- 168: ("480p", None),
48
- 169: ("720p", None),
49
- 170: ("1080p", None),
50
- 212: ("480p", None),
51
- 218: ("480p", None),
52
- 219: ("480p", None),
53
- 242: ("240p", None),
54
- 243: ("360p", None),
55
- 244: ("480p", None),
56
- 245: ("480p", None),
57
- 246: ("480p", None),
58
- 247: ("720p", None),
59
- 248: ("1080p", None),
60
- 264: ("1440p", None),
61
- 266: ("2160p", None),
62
- 271: ("1440p", None),
63
- 272: ("2160p", None),
64
- 278: ("144p", None),
65
- 298: ("720p", None),
66
- 299: ("1080p", None),
67
- 302: ("720p", None),
68
- 303: ("1080p", None),
69
- 308: ("1440p", None),
70
- 313: ("2160p", None),
71
- 315: ("2160p", None),
72
- 330: ("144p", None),
73
- 331: ("240p", None),
74
- 332: ("360p", None),
75
- 333: ("480p", None),
76
- 334: ("720p", None),
77
- 335: ("1080p", None),
78
- 336: ("1440p", None),
79
- 337: ("2160p", None),
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  # DASH Audio
81
- 139: (None, "48kbps"),
82
- 140: (None, "128kbps"),
83
- 141: (None, "256kbps"),
84
- 171: (None, "128kbps"),
85
- 172: (None, "256kbps"),
86
- 249: (None, "50kbps"),
87
- 250: (None, "70kbps"),
88
- 251: (None, "160kbps"),
89
- 256: (None, None),
90
- 258: (None, None),
91
- 325: (None, None),
92
- 328: (None, None),
 
 
 
 
 
 
93
  }
94
 
95
  HDR = [330, 331, 332, 333, 334, 335, 336, 337]
96
- _60FPS = [298, 299, 302, 303, 308, 315] + HDR
97
  _3D = [82, 83, 84, 85, 100, 101, 102]
98
  LIVE = [91, 92, 93, 94, 95, 96, 132, 151]
99
- DASH_MP4_VIDEO = [133, 134, 135, 136, 137, 138, 160, 212, 264, 266, 298, 299]
100
- DASH_MP4_AUDIO = [139, 140, 141, 256, 258, 325, 328]
101
- DASH_WEBM_VIDEO = [
102
- 167,
103
- 168,
104
- 169,
105
- 170,
106
- 218,
107
- 219,
108
- 278,
109
- 242,
110
- 243,
111
- 244,
112
- 245,
113
- 246,
114
- 247,
115
- 248,
116
- 271,
117
- 272,
118
- 302,
119
- 303,
120
- 308,
121
- 313,
122
- 315,
123
- ]
124
- DASH_WEBM_AUDIO = [171, 172, 249, 250, 251]
125
 
126
 
127
  def get_format_profile(itag: int) -> Dict:
@@ -142,8 +140,8 @@ def get_format_profile(itag: int) -> Dict:
142
  "is_3d": itag in _3D,
143
  "is_hdr": itag in HDR,
144
  "fps": 60 if itag in _60FPS else 30,
145
- "is_dash": itag in DASH_MP4_VIDEO
146
- or itag in DASH_MP4_AUDIO
147
- or itag in DASH_WEBM_VIDEO
148
- or itag in DASH_WEBM_AUDIO,
149
  }
 
2
  """This module contains a lookup table of YouTube's itag values."""
3
  from typing import Dict
4
 
5
+ PROGRESSIVE_VIDEO = {
6
  5: ("240p", "64kbps"),
7
  6: ("270p", "64kbps"),
8
  13: ("144p", None),
 
35
  102: ("720p", "192kbps"),
36
  132: ("240p", "48kbps"),
37
  151: ("720p", "24kbps"),
38
+ 300: ("720p", "128kbps"),
39
+ 301: ("1080p", "128kbps"),
40
+ }
41
+
42
+ DASH_VIDEO = {
43
  # DASH Video
44
+ 133: ("240p", None), # MP4
45
+ 134: ("360p", None), # MP4
46
+ 135: ("480p", None), # MP4
47
+ 136: ("720p", None), # MP4
48
+ 137: ("1080p", None), # MP4
49
+ 138: ("2160p", None), # MP4
50
+ 160: ("144p", None), # MP4
51
+ 167: ("360p", None), # WEBM
52
+ 168: ("480p", None), # WEBM
53
+ 169: ("720p", None), # WEBM
54
+ 170: ("1080p", None), # WEBM
55
+ 212: ("480p", None), # MP4
56
+ 218: ("480p", None), # WEBM
57
+ 219: ("480p", None), # WEBM
58
+ 242: ("240p", None), # WEBM
59
+ 243: ("360p", None), # WEBM
60
+ 244: ("480p", None), # WEBM
61
+ 245: ("480p", None), # WEBM
62
+ 246: ("480p", None), # WEBM
63
+ 247: ("720p", None), # WEBM
64
+ 248: ("1080p", None), # WEBM
65
+ 264: ("1440p", None), # MP4
66
+ 266: ("2160p", None), # MP4
67
+ 271: ("1440p", None), # WEBM
68
+ 272: ("4320p", None), # WEBM
69
+ 278: ("144p", None), # WEBM
70
+ 298: ("720p", None), # MP4
71
+ 299: ("1080p", None), # MP4
72
+ 302: ("720p", None), # WEBM
73
+ 303: ("1080p", None), # WEBM
74
+ 308: ("1440p", None), # WEBM
75
+ 313: ("2160p", None), # WEBM
76
+ 315: ("2160p", None), # WEBM
77
+ 330: ("144p", None), # WEBM
78
+ 331: ("240p", None), # WEBM
79
+ 332: ("360p", None), # WEBM
80
+ 333: ("480p", None), # WEBM
81
+ 334: ("720p", None), # WEBM
82
+ 335: ("1080p", None), # WEBM
83
+ 336: ("1440p", None), # WEBM
84
+ 337: ("2160p", None), # WEBM
85
+ 394: ("144p", None), # MP4
86
+ 395: ("240p", None), # MP4
87
+ 396: ("360p", None), # MP4
88
+ 397: ("480p", None), # MP4
89
+ 398: ("720p", None), # MP4
90
+ 399: ("1080p", None), # MP4
91
+ 400: ("1440p", None), # MP4
92
+ 401: ("2160p", None), # MP4
93
+ 402: ("4320p", None), # MP4
94
+ 571: ("4320p", None), # MP4
95
+ }
96
+
97
+ DASH_AUDIO = {
98
  # DASH Audio
99
+ 139: (None, "48kbps"), # MP4
100
+ 140: (None, "128kbps"), # MP4
101
+ 141: (None, "256kbps"), # MP4
102
+ 171: (None, "128kbps"), # WEBM
103
+ 172: (None, "256kbps"), # WEBM
104
+ 249: (None, "50kbps"), # WEBM
105
+ 250: (None, "70kbps"), # WEBM
106
+ 251: (None, "160kbps"), # WEBM
107
+ 256: (None, "192kbps"), # MP4
108
+ 258: (None, "384kbps"), # MP4
109
+ 325: (None, None), # MP4
110
+ 328: (None, None), # MP4
111
+ }
112
+
113
+ ITAGS = {
114
+ **PROGRESSIVE_VIDEO,
115
+ **DASH_VIDEO,
116
+ **DASH_AUDIO,
117
  }
118
 
119
  HDR = [330, 331, 332, 333, 334, 335, 336, 337]
120
+ _60FPS = [272, 298, 299, 302, 303, 308, 315, 398, 399, 400, 401, 402, 571] + HDR
121
  _3D = [82, 83, 84, 85, 100, 101, 102]
122
  LIVE = [91, 92, 93, 94, 95, 96, 132, 151]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
 
125
  def get_format_profile(itag: int) -> Dict:
 
140
  "is_3d": itag in _3D,
141
  "is_hdr": itag in HDR,
142
  "fps": 60 if itag in _60FPS else 30,
143
+ "is_dash": (
144
+ itag in DASH_AUDIO
145
+ or itag in DASH_VIDEO
146
+ ),
147
  }
tests/test_query.py CHANGED
@@ -7,9 +7,9 @@ import pytest
7
  ("test_input", "expected"),
8
  [
9
  ({"progressive": True}, [18, 22]),
10
- ({"resolution": "720p"}, [22, 136, 247]),
11
- ({"res": "720p"}, [22, 136, 247]),
12
- ({"fps": 30, "resolution": "480p"}, [135, 244]),
13
  ({"mime_type": "audio/mp4"}, [140]),
14
  ({"type": "audio"}, [140, 249, 250, 251]),
15
  ({"subtype": "3gpp"}, []),
@@ -19,7 +19,7 @@ import pytest
19
  ({"video_codec": "vp9"}, [248, 247, 244, 243, 242, 278]),
20
  ({"only_audio": True}, [140, 249, 250, 251]),
21
  ({"only_video": True, "video_codec": "avc1.4d4015"}, [133]),
22
- ({"adaptive": True, "resolution": "1080p"}, [137, 248]),
23
  ({"custom_filter_functions": [lambda s: s.itag == 18]}, [18]),
24
  ],
25
  )
@@ -86,7 +86,7 @@ def test_order_by_non_numerical(cipher_signature):
86
  .order_by("mime_type")
87
  .desc()
88
  ]
89
- assert mime_types == ["video/webm", "video/mp4", "video/mp4"]
90
 
91
 
92
  def test_order_by_ascending(cipher_signature):
@@ -110,7 +110,7 @@ def test_order_by_non_numerical_ascending(cipher_signature):
110
  .order_by("mime_type")
111
  .asc()
112
  ]
113
- assert mime_types == ["video/mp4", "video/mp4", "video/webm"]
114
 
115
 
116
  def test_order_by_with_none_values(cipher_signature):
@@ -144,7 +144,7 @@ def test_get_highest_resolution(cipher_signature):
144
  def test_filter_is_dash(cipher_signature):
145
  streams = cipher_signature.streams.filter(is_dash=False)
146
  itags = [s.itag for s in streams]
147
- assert itags == [18, 22, 399, 398, 397, 396, 395, 394]
148
 
149
 
150
  def test_get_audio_only(cipher_signature):
 
7
  ("test_input", "expected"),
8
  [
9
  ({"progressive": True}, [18, 22]),
10
+ ({"resolution": "720p"}, [22, 136, 247, 398]),
11
+ ({"res": "720p"}, [22, 136, 247, 398]),
12
+ ({"fps": 30, "resolution": "480p"}, [135, 244, 397]),
13
  ({"mime_type": "audio/mp4"}, [140]),
14
  ({"type": "audio"}, [140, 249, 250, 251]),
15
  ({"subtype": "3gpp"}, []),
 
19
  ({"video_codec": "vp9"}, [248, 247, 244, 243, 242, 278]),
20
  ({"only_audio": True}, [140, 249, 250, 251]),
21
  ({"only_video": True, "video_codec": "avc1.4d4015"}, [133]),
22
+ ({"adaptive": True, "resolution": "1080p"}, [137, 248, 399]),
23
  ({"custom_filter_functions": [lambda s: s.itag == 18]}, [18]),
24
  ],
25
  )
 
86
  .order_by("mime_type")
87
  .desc()
88
  ]
89
+ assert mime_types == ["video/webm", "video/mp4", "video/mp4", "video/mp4"]
90
 
91
 
92
  def test_order_by_ascending(cipher_signature):
 
110
  .order_by("mime_type")
111
  .asc()
112
  ]
113
+ assert mime_types == ["video/mp4", "video/mp4", "video/mp4", "video/webm"]
114
 
115
 
116
  def test_order_by_with_none_values(cipher_signature):
 
144
  def test_filter_is_dash(cipher_signature):
145
  streams = cipher_signature.streams.filter(is_dash=False)
146
  itags = [s.itag for s in streams]
147
+ assert itags == [18, 22]
148
 
149
 
150
  def test_get_audio_only(cipher_signature):