Add playlist-end option (courtesy of Nevar Angelo)

This commit is contained in:
Ricardo Garcia 2010-11-04 23:19:09 +01:00
parent 893a13df55
commit 8cc4434116

View File

@ -204,6 +204,7 @@ class FileDownloader(object):
continuedl: Try to continue downloads if possible. continuedl: Try to continue downloads if possible.
noprogress: Do not print the progress bar. noprogress: Do not print the progress bar.
playliststart: Playlist item to start at. playliststart: Playlist item to start at.
playlistend: Playlist item to end at.
logtostderr: Log messages to stderr instead of stdout. logtostderr: Log messages to stderr instead of stdout.
""" """
@ -1966,11 +1967,10 @@ class YoutubePlaylistIE(InfoExtractor):
break break
pagenum = pagenum + 1 pagenum = pagenum + 1
playliststart = self._downloader.params.get('playliststart', 1) playliststart = self._downloader.params.get('playliststart', 1) - 1
playliststart -= 1 #our arrays are zero-based but the playlist is 1-based playlistend = self._downloader.params.get('playlistend', -1)
if playliststart > 0: video_ids = video_ids[playliststart:playlistend]
video_ids = video_ids[playliststart:]
for id in video_ids: for id in video_ids:
self._youtube_ie.extract('http://www.youtube.com/watch?v=%s' % id) self._youtube_ie.extract('http://www.youtube.com/watch?v=%s' % id)
return return
@ -2026,10 +2026,9 @@ class YoutubeUserIE(InfoExtractor):
ids_in_page.append(mobj.group(1)) ids_in_page.append(mobj.group(1))
video_ids.extend(ids_in_page) video_ids.extend(ids_in_page)
playliststart = self._downloader.params.get('playliststart', 1) playliststart = self._downloader.params.get('playliststart', 1) - 1
playliststart = playliststart-1 #our arrays are zero-based but the playlist is 1-based playlistend = self._downloader.params.get('playlistend', -1)
if playliststart > 0: video_ids = video_ids[playliststart:playlistend]
video_ids = video_ids[playliststart:]
for id in video_ids: for id in video_ids:
self._youtube_ie.extract('http://www.youtube.com/watch?v=%s' % id) self._youtube_ie.extract('http://www.youtube.com/watch?v=%s' % id)
@ -2125,6 +2124,8 @@ if __name__ == '__main__':
dest='retries', metavar='RETRIES', help='number of retries (default is 10)', default=10) dest='retries', metavar='RETRIES', help='number of retries (default is 10)', default=10)
parser.add_option('--playlist-start', parser.add_option('--playlist-start',
dest='playliststart', metavar='NUMBER', help='playlist video to start at (default is 1)', default=1) dest='playliststart', metavar='NUMBER', help='playlist video to start at (default is 1)', default=1)
parser.add_option('--playlist-end',
dest='playlistend', metavar='NUMBER', help='playlist video to end at (default is last)', default=-1)
authentication = optparse.OptionGroup(parser, 'Authentication Options') authentication = optparse.OptionGroup(parser, 'Authentication Options')
authentication.add_option('-u', '--username', authentication.add_option('-u', '--username',
@ -2239,11 +2240,18 @@ if __name__ == '__main__':
opts.retries = long(opts.retries) opts.retries = long(opts.retries)
except (TypeError, ValueError), err: except (TypeError, ValueError), err:
parser.error(u'invalid retry count specified') parser.error(u'invalid retry count specified')
if opts.playliststart is not None: try:
try: opts.playliststart = long(opts.playliststart)
opts.playliststart = long(opts.playliststart) if opts.playliststart <= 0:
except (TypeError, ValueError), err: raise ValueError
parser.error(u'invalid playlist page specified') except (TypeError, ValueError), err:
parser.error(u'invalid playlist start number specified')
try:
opts.playlistend = long(opts.playlistend)
if opts.playlistend != -1 and (opts.playlistend <= 0 or opts.playlistend < opts.playliststart):
raise ValueError
except (TypeError, ValueError), err:
parser.error(u'invalid playlist end number specified')
# Information extractors # Information extractors
youtube_ie = YoutubeIE() youtube_ie = YoutubeIE()
@ -2286,6 +2294,7 @@ if __name__ == '__main__':
'continuedl': opts.continue_dl, 'continuedl': opts.continue_dl,
'noprogress': opts.noprogress, 'noprogress': opts.noprogress,
'playliststart': opts.playliststart, 'playliststart': opts.playliststart,
'playlistend': opts.playlistend,
'logtostderr': opts.outtmpl == '-', 'logtostderr': opts.outtmpl == '-',
}) })
fd.add_info_extractor(youtube_search_ie) fd.add_info_extractor(youtube_search_ie)