From 3513ce074f8dc69ae92e1545bacbc9365cea07bb Mon Sep 17 00:00:00 2001 From: "me@disf.asia" Date: Mon, 19 May 2014 14:11:19 +0700 Subject: [PATCH 1/4] [youtube_dl] Added cancelable metadata / playlist downlod progress hook --- youtube_dl/YoutubeDL.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index f3666573a..5f0dde682 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -188,6 +188,7 @@ class YoutubeDL(object): self._ies_instances = {} self._pps = [] self._progress_hooks = [] + self._metadata_hooks = [] self._download_retcode = 0 self._num_downloads = 0 self._screen_file = [sys.stdout, sys.stderr][params.get('logtostderr', False)] @@ -266,8 +267,12 @@ class YoutubeDL(object): self._pps.append(pp) pp.set_downloader(self) + def add_metadata_hook(self, ph): + """Add the metadata progress hook""" + self._metadata_hooks.append(ph) + def add_progress_hook(self, ph): - """Add the progress hook (currently only for the file downloader)""" + """Add the download progress hook""" self._progress_hooks.append(ph) def _bidi_workaround(self, message): @@ -634,6 +639,21 @@ class YoutubeDL(object): 'webpage_url_basename': url_basename(ie_result['webpage_url']), 'extractor_key': ie_result['extractor_key'], } + playlistProgress = { + 'current': i, + 'total': n_entries, + 'playlist': ie_result['webpage_url'], + 'next': entry + } + skipNext = False + for ph in self._metadata_hooks: + skipNext = skipNext or ph(playlistProgress) == False + if skipNext: + break + + if skipNext: + self.to_screen('[skip] Skipping next (id: %s)' % entry['id']) + continue reason = self._match_entry(entry) if reason is not None: From 272ad7045eea46f81aa4b4af614bc2f40648464b Mon Sep 17 00:00:00 2001 From: "me@disf.asia" Date: Thu, 22 May 2014 12:08:52 +0700 Subject: [PATCH 2/4] Added playlist hook for last entry --- youtube_dl/YoutubeDL.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 5f0dde682..0b270ba49 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -640,9 +640,10 @@ class YoutubeDL(object): 'extractor_key': ie_result['extractor_key'], } playlistProgress = { - 'current': i, + 'current': i-1, 'total': n_entries, 'playlist': ie_result['webpage_url'], + 'currentData': playlist_results[-1] if len(playlist_results) > 0 else None, 'next': entry } skipNext = False @@ -664,6 +665,21 @@ class YoutubeDL(object): download=download, extra_info=extra) playlist_results.append(entry_result) + + + playlistProgress = { + 'current': n_entries, + 'total': n_entries, + 'playlist': ie_result['webpage_url'], + 'currentData': playlist_results[-1] if len(playlist_results) > 0 else None, + 'next': None + } + + for ph in self._metadata_hooks: + ph(playlistProgress) + + + ie_result['entries'] = playlist_results return ie_result elif result_type == 'compat_list': From cb844616d3fd99493dd4bc463470c968ffa411a3 Mon Sep 17 00:00:00 2001 From: "me@disf.asia" Date: Thu, 22 May 2014 15:31:14 +0700 Subject: [PATCH 3/4] Parameter "playlistonly" makes YoutubeDL skip fetching data for each playlist entry --- youtube_dl/YoutubeDL.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 0b270ba49..a0d2975f5 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -114,6 +114,7 @@ class YoutubeDL(object): nooverwrites: Prevent overwriting files. playliststart: Playlist item to start at. playlistend: Playlist item to end at. + playlistonly: Stops after getting the playlist entries matchtitle: Download only matching titles. rejecttitle: Reject downloads for matching titles. logger: Log messages to a logging.Logger instance. @@ -661,11 +662,13 @@ class YoutubeDL(object): self.to_screen('[download] ' + reason) continue - entry_result = self.process_ie_result(entry, + if not self.params.get('playlistonly', False): + entry_result = self.process_ie_result(entry, download=download, extra_info=extra) - playlist_results.append(entry_result) - + playlist_results.append(entry_result) + else: + playlist_results.append(entry) playlistProgress = { 'current': n_entries, @@ -678,10 +681,9 @@ class YoutubeDL(object): for ph in self._metadata_hooks: ph(playlistProgress) - - ie_result['entries'] = playlist_results return ie_result + elif result_type == 'compat_list': def _fixup(r): self.add_extra_info(r, From 5749faaa79db368404ab7c0970189602a681a53c Mon Sep 17 00:00:00 2001 From: "me@disf.asia" Date: Wed, 28 May 2014 11:19:02 +0700 Subject: [PATCH 4/4] Init file in main folder --- __init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 000000000..e69de29bb