X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2F__init__.py;h=306ecca51341884f4a7d0ada17b467db912b6710;hb=23e6b8adc8197da4cfaa831c08f3c2e627bbabdd;hp=96e2f0f8971ef5c327c2d61b0fb97e1469bc510e;hpb=dd17922afc3f005129e8c8bad2f4104169a14348;p=youtube-dl diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 96e2f0f89..306ecca51 100755 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -282,6 +282,14 @@ def _simplify_title(title): expr = re.compile(ur'[^\w\d_\-]+', flags=re.UNICODE) return expr.sub(u'_', title).strip(u'_') +def _orderedSet(iterable): + """ Remove all duplicates from the input iterable """ + res = [] + for el in iterable: + if el not in res: + res.append(el) + return res + class DownloadError(Exception): """Download Error exception. @@ -309,6 +317,10 @@ class PostProcessingError(Exception): """ pass +class MaxDownloadsReached(Exception): + """ --max-downloads limit has been reached. """ + pass + class UnavailableVideoError(Exception): """Unavailable Format exception. @@ -711,25 +723,6 @@ class FileDownloader(object): return u'"' + title + '" title matched reject pattern "' + rejecttitle + '"' return None - def process_dict(self, info_dict): - """ Download and handle the extracted information. - For details on the specification of the various types of content, refer to the _process_* functions. """ - if info_dict['type'] == 'playlist': - self._process_playlist(info_dict) - elif info_dict['type'] == 'legacy-video': - self.process_info(info_dict) - else: - raise ValueError('Invalid item type') - - def _process_playlist(self, info_dict): - assert info_dict['type'] == 'playlist' - assert 'title' in info_dict - assert 'stitle' in info_dict - entries = info_dict['list'] - - for e in entries: - self.process_dict(e) - def process_info(self, info_dict): """Process a single dictionary returned by an InfoExtractor.""" @@ -741,8 +734,7 @@ class FileDownloader(object): max_downloads = self.params.get('max_downloads') if max_downloads is not None: if self._num_downloads > int(max_downloads): - self.to_screen(u'[download] Maximum number of downloads reached. Skipping ' + info_dict['title']) - return + raise MaxDownloadsReached() filename = self.prepare_filename(info_dict) @@ -1129,6 +1121,7 @@ class YoutubeIE(InfoExtractor): _NETRC_MACHINE = 'youtube' # Listed in order of quality _available_formats = ['38', '37', '22', '45', '35', '44', '34', '18', '43', '6', '5', '17', '13'] + _available_formats_prefer_free = ['38', '37', '45', '22', '44', '35', '43', '34', '18', '6', '5', '17', '13'] _video_extensions = { '13': '3gp', '17': 'mp4', @@ -1378,10 +1371,11 @@ class YoutubeIE(InfoExtractor): url_map = dict((ud['itag'][0], ud['url'][0]) for ud in url_data) format_limit = self._downloader.params.get('format_limit', None) - if format_limit is not None and format_limit in self._available_formats: - format_list = self._available_formats[self._available_formats.index(format_limit):] + available_formats = self._available_formats_prefer_free if self._downloader.params.get('prefer_free_formats', False) else self._available_formats + if format_limit is not None and format_limit in available_formats: + format_list = available_formats[available_formats.index(format_limit):] else: - format_list = self._available_formats + format_list = available_formats existing_formats = [x for x in format_list if x in url_map] if len(existing_formats) == 0: self._downloader.trouble(u'ERROR: no known formats available for video') @@ -3766,9 +3760,13 @@ class MixcloudIE(InfoExtractor): class StanfordOpenClassroomIE(InfoExtractor): """Information extractor for Stanford's Open ClassRoom""" - _VALID_URL = r'^(?:https?://)?openclassroom.stanford.edu(?P/|(/MainFolder/(?:HomePage|CoursePage|VideoPage)\.php([?]course=(?P[^&]+)(&video=(?P