diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index 86be58dcb..638979a05 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -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() diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index e5e7482f6..8a1f56222 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -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) diff --git a/youtube_dl/params.py b/youtube_dl/params.py index 03d2f2f2e..8b1e92d8d 100644 --- a/youtube_dl/params.py +++ b/youtube_dl/params.py @@ -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)