1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-03-14 09:17:20 +08:00

[YoutubeDL] videos inherit parameters when they are contained in a playlist

This commit is contained in:
Jaime Marquínez Ferrándiz 2016-03-19 12:49:12 +01:00
parent 09495f1d12
commit e2887bb044
3 changed files with 34 additions and 5 deletions

View File

@ -710,6 +710,7 @@ class TestYoutubeDL(unittest.TestCase):
ydl = YoutubeDL(params, auto_init=False)
ydl.downloads = []
real_process_info = ydl.process_info
def process_info(info_dict, params):
r = real_process_info(info_dict, params)
ydl.downloads.append(info_dict)
@ -728,7 +729,6 @@ class TestYoutubeDL(unittest.TestCase):
'url': 'http://example.com',
}
ie = ExampleIE()
ydl.add_info_extractor(ie)
pars = ie.params
@ -740,6 +740,23 @@ class TestYoutubeDL(unittest.TestCase):
ydl.extract_info('example')
self.assertEqual(ydl.downloads[-1]['_filename'], 'foo.mp4')
class ExamplePlaylistIE(InfoExtractor):
IE_NAME = 'example.com:playlist'
_VALID_URL = r'example:playlist'
def _real_extract(self, url):
return {
'_type': 'playlist',
'title': 'example playlist',
'entries': [self.url_result('example')],
}
playlist_params = {'outtmpl': '%(playlist)s/%(title)s.%(ext)s'}
ydl.params = Params(
{'skip_download': True}, {'example.com:playlist': playlist_params})
ydl.add_info_extractor(ExamplePlaylistIE())
ydl.extract_info('example:playlist')
self.assertEqual(ydl.downloads[-1]['_filename'], 'example playlist/example.mp4')
if __name__ == '__main__':
unittest.main()

View File

@ -650,13 +650,16 @@ class YoutubeDL(object):
info_dict.setdefault(key, value)
def extract_info(self, url, download=True, ie_key=None, extra_info={},
process=True, force_generic_extractor=False):
process=True, force_generic_extractor=False, params=None):
'''
Returns a list with a dictionary for each video we find.
If 'download', also downloads the videos.
extra_info is a dict containing the extra values to add to each result
'''
if params is None:
params = self.params
if not ie_key and force_generic_extractor:
ie_key = 'Generic'
@ -687,7 +690,7 @@ class YoutubeDL(object):
if process:
return self.process_ie_result(
ie_result, download, extra_info,
params=self.params.section(ie.IE_NAME))
params=params.section(ie.IE_NAME))
else:
return ie_result
except ExtractorError as e: # An error we somewhat expected
@ -741,12 +744,14 @@ class YoutubeDL(object):
return self.extract_info(ie_result['url'],
download,
ie_key=ie_result.get('ie_key'),
extra_info=extra_info)
extra_info=extra_info,
params=params)
elif result_type == 'url_transparent':
# Use the information from the embedding page
info = self.extract_info(
ie_result['url'], ie_key=ie_result.get('ie_key'),
extra_info=extra_info, download=False, process=False)
extra_info=extra_info, download=False, process=False,
params=params)
force_properties = dict(
(k, v) for k, v in ie_result.items() if v is not None)

View File

@ -41,3 +41,10 @@ class ParamsSection(object):
return self[key]
except KeyError:
return default
@property
def sections(self):
return self.parent.sections
def section(self, section):
return ParamsSection(self.parent.sections.get(section, {}), self)