Added new --playlist-items option
This commit is contained in:
parent
1cbd410620
commit
aac67bc576
@ -113,6 +113,7 @@ class YoutubeDL(object):
|
|||||||
nooverwrites: Prevent overwriting files.
|
nooverwrites: Prevent overwriting files.
|
||||||
playliststart: Playlist item to start at.
|
playliststart: Playlist item to start at.
|
||||||
playlistend: Playlist item to end at.
|
playlistend: Playlist item to end at.
|
||||||
|
playlistitems: Specific items of playlist to download.
|
||||||
matchtitle: Download only matching titles.
|
matchtitle: Download only matching titles.
|
||||||
rejecttitle: Reject downloads for matching titles.
|
rejecttitle: Reject downloads for matching titles.
|
||||||
logger: Log messages to a logging.Logger instance.
|
logger: Log messages to a logging.Logger instance.
|
||||||
@ -603,8 +604,24 @@ class YoutubeDL(object):
|
|||||||
if playlistend == -1:
|
if playlistend == -1:
|
||||||
playlistend = None
|
playlistend = None
|
||||||
|
|
||||||
|
playlistitems = self.params.get('playlistitems', None)
|
||||||
|
if playlistitems:
|
||||||
|
if bool(re.compile(r'[^0-9,-]').search(playlistitems)):
|
||||||
|
raise ValueError('Invalid charecters in --playlist-items argument.')
|
||||||
|
_playlistitems = playlistitems.split(',')
|
||||||
|
playlistitems = []
|
||||||
|
for item in _playlistitems:
|
||||||
|
if '-' in item:
|
||||||
|
start, end = item.split('-')
|
||||||
|
playlistitems.extend(list(range(int(start), int(end) + 1)))
|
||||||
|
else:
|
||||||
|
playlistitems.append(int(item))
|
||||||
|
|
||||||
if isinstance(ie_result['entries'], list):
|
if isinstance(ie_result['entries'], list):
|
||||||
n_all_entries = len(ie_result['entries'])
|
n_all_entries = len(ie_result['entries'])
|
||||||
|
if playlistitems:
|
||||||
|
entries = [e for i, e in enumerate(ie_result['entries'], 1) if i in playlistitems]
|
||||||
|
else:
|
||||||
entries = ie_result['entries'][playliststart:playlistend]
|
entries = ie_result['entries'][playliststart:playlistend]
|
||||||
n_entries = len(entries)
|
n_entries = len(entries)
|
||||||
self.to_screen(
|
self.to_screen(
|
||||||
@ -612,6 +629,13 @@ class YoutubeDL(object):
|
|||||||
(ie_result['extractor'], playlist, n_all_entries, n_entries))
|
(ie_result['extractor'], playlist, n_all_entries, n_entries))
|
||||||
else:
|
else:
|
||||||
assert isinstance(ie_result['entries'], PagedList)
|
assert isinstance(ie_result['entries'], PagedList)
|
||||||
|
if playlistitems:
|
||||||
|
entries = []
|
||||||
|
for item in playlistitems:
|
||||||
|
entries.append(ie_result.getslice(
|
||||||
|
item, item + 1
|
||||||
|
))
|
||||||
|
else:
|
||||||
entries = ie_result['entries'].getslice(
|
entries = ie_result['entries'].getslice(
|
||||||
playliststart, playlistend)
|
playliststart, playlistend)
|
||||||
n_entries = len(entries)
|
n_entries = len(entries)
|
||||||
|
@ -52,6 +52,7 @@ __authors__ = (
|
|||||||
'Juan C. Olivares',
|
'Juan C. Olivares',
|
||||||
'Mattias Harrysson',
|
'Mattias Harrysson',
|
||||||
'phaer',
|
'phaer',
|
||||||
|
'Enam Mijbah Noor'
|
||||||
)
|
)
|
||||||
|
|
||||||
__license__ = 'Public Domain'
|
__license__ = 'Public Domain'
|
||||||
@ -276,6 +277,10 @@ def parseOpts(overrideArguments=None):
|
|||||||
'--playlist-end',
|
'--playlist-end',
|
||||||
dest='playlistend', metavar='NUMBER', default=None, type=int,
|
dest='playlistend', metavar='NUMBER', default=None, type=int,
|
||||||
help='playlist video to end at (default is last)')
|
help='playlist video to end at (default is last)')
|
||||||
|
selection.add_option(
|
||||||
|
'--playlist-items',
|
||||||
|
dest='playlistitems', metavar='FORMAT', default=None,
|
||||||
|
help='playlist video items to download. Specify items seperated by commas like: "--playlist-items 1,2,5,8". You can specify range: "--playlist-items 1-4,7,10,12-15,20".')
|
||||||
selection.add_option('--match-title', dest='matchtitle', metavar='REGEX',help='download only matching titles (regex or caseless sub-string)')
|
selection.add_option('--match-title', dest='matchtitle', metavar='REGEX',help='download only matching titles (regex or caseless sub-string)')
|
||||||
selection.add_option('--reject-title', dest='rejecttitle', metavar='REGEX',help='skip download for matching titles (regex or caseless sub-string)')
|
selection.add_option('--reject-title', dest='rejecttitle', metavar='REGEX',help='skip download for matching titles (regex or caseless sub-string)')
|
||||||
selection.add_option('--max-downloads', metavar='NUMBER',
|
selection.add_option('--max-downloads', metavar='NUMBER',
|
||||||
@ -744,6 +749,7 @@ def _real_main(argv=None):
|
|||||||
'progress_with_newline': opts.progress_with_newline,
|
'progress_with_newline': opts.progress_with_newline,
|
||||||
'playliststart': opts.playliststart,
|
'playliststart': opts.playliststart,
|
||||||
'playlistend': opts.playlistend,
|
'playlistend': opts.playlistend,
|
||||||
|
'playlistitems': opts.playlistitems,
|
||||||
'noplaylist': opts.noplaylist,
|
'noplaylist': opts.noplaylist,
|
||||||
'logtostderr': opts.outtmpl == '-',
|
'logtostderr': opts.outtmpl == '-',
|
||||||
'consoletitle': opts.consoletitle,
|
'consoletitle': opts.consoletitle,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user