From cc93a9a1afc36f5e959bf2f38a4d5f7bcb57620c Mon Sep 17 00:00:00 2001 From: Dylan Wenzlau Date: Mon, 17 Feb 2014 17:32:47 -0800 Subject: [PATCH] Added --get-filesize option --- README.md | 1 + youtube_dl/YoutubeDL.py | 2 +- youtube_dl/__init__.py | 6 +++++- youtube_dl/downloader/common.py | 1 + youtube_dl/downloader/http.py | 3 +++ 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd091be86..24be9bd71 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,7 @@ which means you can modify it, redistribute it or use it however you like. --get-duration simulate, quiet but print video length --get-filename simulate, quiet but print output filename --get-format simulate, quiet but print output format + --get-filesize simulate, quiet but print video filesize -j, --dump-json simulate, quiet but print JSON information --newline output progress bar as new lines --no-progress do not print progress bar diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 42cbcf699..25e19d80c 100644 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -159,7 +159,7 @@ class YoutubeDL(object): The following parameters are not used by YoutubeDL itself, they are used by the FileDownloader: nopart, updatetime, buffersize, ratelimit, min_filesize, max_filesize, test, - noresizebuffer, retries, continuedl, noprogress, consoletitle + noresizebuffer, retries, continuedl, noprogress, consoletitle, get_filesize The following options are used by the post processors: prefer_ffmpeg: If True, use ffmpeg instead of avconv if both are available, diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index f843036c7..7fe23bdea 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -377,6 +377,9 @@ def parseOpts(overrideArguments=None): verbosity.add_option('--get-format', action='store_true', dest='getformat', help='simulate, quiet but print output format', default=False) + verbosity.add_option('--get-filesize', + action='store_true', dest='get_filesize', + help='simulate, quiet but print video filesize', default=False) verbosity.add_option('-j', '--dump-json', action='store_true', dest='dumpjson', help='simulate, quiet but print JSON information', default=False) @@ -685,7 +688,7 @@ def _real_main(argv=None): 'username': opts.username, 'password': opts.password, 'videopassword': opts.videopassword, - 'quiet': (opts.quiet or any_printing), + 'quiet': (opts.quiet or any_printing or opts.get_filesize), 'forceurl': opts.geturl, 'forcetitle': opts.gettitle, 'forceid': opts.getid, @@ -740,6 +743,7 @@ def _real_main(argv=None): 'keepvideo': opts.keepvideo, 'min_filesize': opts.min_filesize, 'max_filesize': opts.max_filesize, + 'get_filesize': opts.get_filesize, 'min_views': opts.min_views, 'max_views': opts.max_views, 'daterange': date, diff --git a/youtube_dl/downloader/common.py b/youtube_dl/downloader/common.py index 5a068aa8b..5f9bd914e 100644 --- a/youtube_dl/downloader/common.py +++ b/youtube_dl/downloader/common.py @@ -37,6 +37,7 @@ class FileDownloader(object): test: Download only first bytes to test the downloader. min_filesize: Skip files smaller than this size max_filesize: Skip files larger than this size + get_filesize: Simulate quietly and print video filesize Subclasses of this one must re-define the real_download method. """ diff --git a/youtube_dl/downloader/http.py b/youtube_dl/downloader/http.py index 748f9f3ad..5027314ea 100644 --- a/youtube_dl/downloader/http.py +++ b/youtube_dl/downloader/http.py @@ -97,6 +97,9 @@ class HttpFD(FileDownloader): return False data_len = data.info().get('Content-length', None) + if self.params.get('get_filesize', False): + print data_len + return True if data_len is not None: data_len = int(data_len) + resume_len min_data_len = self.params.get("min_filesize", None)