juhee
commited on
Revise Playlist Extraction to YouTubes architecture changes (#805)
Browse files* Revise playlist extraction
* Regenerated playlist_long mock
* Adjusted unit test to account for changes
pytube/contrib/playlist.py
CHANGED
@@ -179,21 +179,24 @@ class Playlist(Sequence):
|
|
179 |
][
|
180 |
"playlistVideoListRenderer"
|
181 |
]
|
|
|
182 |
except (KeyError, IndexError, TypeError):
|
183 |
try:
|
184 |
# this is the json tree structure, if the json was directly sent
|
185 |
# by the server in a continuation response
|
186 |
-
important_content = initial_data[1][
|
187 |
-
|
188 |
-
][
|
|
|
189 |
except (KeyError, IndexError, TypeError) as p:
|
190 |
print(p)
|
191 |
return [], None
|
192 |
-
|
193 |
try:
|
194 |
-
continuation =
|
195 |
-
|
196 |
-
][
|
|
|
197 |
except (KeyError, IndexError):
|
198 |
# if there is an error, no continuation is available
|
199 |
continuation = None
|
|
|
179 |
][
|
180 |
"playlistVideoListRenderer"
|
181 |
]
|
182 |
+
videos = important_content["contents"]
|
183 |
except (KeyError, IndexError, TypeError):
|
184 |
try:
|
185 |
# this is the json tree structure, if the json was directly sent
|
186 |
# by the server in a continuation response
|
187 |
+
important_content = initial_data[1]['response']['onResponseReceivedActions'][
|
188 |
+
0
|
189 |
+
]['appendContinuationItemsAction']['continuationItems']
|
190 |
+
videos = important_content
|
191 |
except (KeyError, IndexError, TypeError) as p:
|
192 |
print(p)
|
193 |
return [], None
|
194 |
+
|
195 |
try:
|
196 |
+
continuation = videos[-1]['continuationItemRenderer'][
|
197 |
+
'continuationEndpoint'
|
198 |
+
]['continuationCommand']['token']
|
199 |
+
videos = videos[:-1]
|
200 |
except (KeyError, IndexError):
|
201 |
# if there is an error, no continuation is available
|
202 |
continuation = None
|
tests/contrib/test_playlist.py
CHANGED
@@ -224,7 +224,7 @@ def test_trimmed_pagination(request_get, playlist_html, playlist_long_html):
|
|
224 |
"{}",
|
225 |
]
|
226 |
playlist = Playlist(url)
|
227 |
-
assert len(list(playlist.trimmed("
|
228 |
assert request_get.call_count == 1
|
229 |
|
230 |
|
|
|
224 |
"{}",
|
225 |
]
|
226 |
playlist = Playlist(url)
|
227 |
+
assert len(list(playlist.trimmed("GTpl5yq3bvk"))) == 3
|
228 |
assert request_get.call_count == 1
|
229 |
|
230 |
|
tests/mocks/playlist_long.html.gz
CHANGED
Binary files a/tests/mocks/playlist_long.html.gz and b/tests/mocks/playlist_long.html.gz differ
|
|