1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-03-10 04:43:21 +08:00

Extract additional playlist page type

Some user pages have a different playlist format, e.g.:
http://www.youtube.com/user/stanforduniversity#g/c/9D558D49CA734A02
There is also a related URL format which refers to a single video
within that playlist. Both playlist and video ids are included in
the URL:
http://www.youtube.com/user/stanforduniversity#p/c/9D558D49CA734A02/0/Ps8jOj7diA0
Extract playlist or video id and turn the URL into a format that is
already understood.
This commit is contained in:
Gergely Imreh 2011-02-09 13:22:17 +08:00
parent f74e22ae28
commit 68bafdebc6

View File

@ -2096,7 +2096,8 @@ class YahooSearchIE(InfoExtractor):
class YoutubePlaylistIE(InfoExtractor): class YoutubePlaylistIE(InfoExtractor):
"""Information Extractor for YouTube playlists.""" """Information Extractor for YouTube playlists."""
_VALID_URL = r'(?:http://)?(?:\w+\.)?youtube.com/(?:(?:view_play_list|my_playlists|artist)\?.*?(p|a)=|user/.*?/user/|p/)([^&]+).*' _VALID_URL = r'(?:http://)?(?:\w+\.)?youtube.com/(?:(?:view_play_list|my_playlists|artist)\?.*?(?P<Pre1>p|a)=|user/.*?/user/|p/|user/.*?#(?P<Pre2>g|p)/c/)(?P<ID>[^&]+).*'
_COMBO_ID = r'(?:[^&]+)/(?:[^&]+)/(?P<ID>[^&]+)'
_TEMPLATE_URL = 'http://www.youtube.com/%s?%s=%s&page=%s&gl=US&hl=en' _TEMPLATE_URL = 'http://www.youtube.com/%s?%s=%s&page=%s&gl=US&hl=en'
_VIDEO_INDICATOR = r'/watch\?v=(.+?)&' _VIDEO_INDICATOR = r'/watch\?v=(.+?)&'
_MORE_PAGES_INDICATOR = r'(?m)>\s*Next\s*</a>' _MORE_PAGES_INDICATOR = r'(?m)>\s*Next\s*</a>'
@ -2125,17 +2126,29 @@ class YoutubePlaylistIE(InfoExtractor):
return return
# Download playlist pages # Download playlist pages
playlist_prefix = mobj.group('Pre1')
playlist_altprefix = mobj.group('Pre2')
playlist_id = mobj.group('ID')
is_playlist = True
video_ids = []
pagenum = 1
# prefix is 'p' as default for playlists but there are other types that need extra care # prefix is 'p' as default for playlists but there are other types that need extra care
playlist_prefix = mobj.group(1)
if playlist_prefix == 'a': if playlist_prefix == 'a':
playlist_access = 'artist' playlist_access = 'artist'
else: else:
# Not really a playlist but single video within the list:
if playlist_altprefix == 'p':
is_playlist = False
ids = re.match(self._COMBO_ID, playlist_id)
if ids is None:
self._downloader.trouble(u'ERROR: invalid url: %s' % url)
return
video_ids = [ids.group('ID')]
else:
playlist_prefix = 'p'
playlist_access = 'view_play_list' playlist_access = 'view_play_list'
playlist_id = mobj.group(2)
video_ids = []
pagenum = 1
while True: while is_playlist:
self.report_download_page(playlist_id, pagenum) self.report_download_page(playlist_id, pagenum)
request = urllib2.Request(self._TEMPLATE_URL % (playlist_access, playlist_prefix, playlist_id, pagenum)) request = urllib2.Request(self._TEMPLATE_URL % (playlist_access, playlist_prefix, playlist_id, pagenum))
try: try:
@ -2155,6 +2168,7 @@ class YoutubePlaylistIE(InfoExtractor):
break break
pagenum = pagenum + 1 pagenum = pagenum + 1
if is_playlist:
playliststart = self._downloader.params.get('playliststart', 1) - 1 playliststart = self._downloader.params.get('playliststart', 1) - 1
playlistend = self._downloader.params.get('playlistend', -1) playlistend = self._downloader.params.get('playlistend', -1)
video_ids = video_ids[playliststart:playlistend] video_ids = video_ids[playliststart:playlistend]