X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=inline;f=youtube_dl%2F__init__.py;h=23e3c2ac29128de874c064e85523ed75c79f29a7;hb=2e5d60b7db7020b726cd54ee4cad8f2afbd1479d;hp=ae12128b96fdba83cedc78857ccf246700681057;hpb=60179645808cbc3cff3ba062312bfa360de48965;p=youtube-dl diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index ae12128b9..23e3c2ac2 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -22,6 +22,8 @@ __authors__ = ( 'Christian Albrecht', 'Dave Vasilevsky', 'Jaime Marquínez Ferrándiz', + 'Jeff Crouse', + 'Osama Khalid', ) __license__ = 'Public Domain' @@ -149,6 +151,9 @@ def parseOpts(): selection.add_option('--match-title', dest='matchtitle', metavar='REGEX',help='download only matching titles (regex or caseless sub-string)') selection.add_option('--reject-title', dest='rejecttitle', metavar='REGEX',help='skip download for matching titles (regex or caseless sub-string)') selection.add_option('--max-downloads', metavar='NUMBER', dest='max_downloads', help='Abort after downloading NUMBER files', default=None) + selection.add_option('--min-filesize', metavar='SIZE', dest='min_filesize', help="Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)", default=None) + selection.add_option('--max-filesize', metavar='SIZE', dest='max_filesize', help="Do not download any videos larger than SIZE (e.g. 50k or 44.6m)", default=None) + authentication.add_option('-u', '--username', dest='username', metavar='USERNAME', help='account username') @@ -197,6 +202,8 @@ def parseOpts(): verbosity.add_option('--get-format', action='store_true', dest='getformat', help='simulate, quiet but print output format', default=False) + verbosity.add_option('--newline', + action='store_true', dest='progress_with_newline', help='output progress bar as new lines', default=False) verbosity.add_option('--no-progress', action='store_true', dest='noprogress', help='do not print progress bar', default=False) verbosity.add_option('--console-title', @@ -205,7 +212,6 @@ def parseOpts(): verbosity.add_option('-v', '--verbose', action='store_true', dest='verbose', help='print various debugging information', default=False) - filesystem.add_option('-t', '--title', action='store_true', dest='usetitle', help='use title in file name', default=False) filesystem.add_option('--id', @@ -279,20 +285,19 @@ def parseOpts(): def _real_main(): parser, opts, args = parseOpts() - # Update version - if opts.update_self: - update_self(fd.to_screen, opts.verbose, sys.argv[0]) - # Open appropriate CookieJar if opts.cookiefile is None: jar = compat_cookiejar.CookieJar() else: try: jar = compat_cookiejar.MozillaCookieJar(opts.cookiefile) - if os.path.isfile(opts.cookiefile) and os.access(opts.cookiefile, os.R_OK): + if os.access(opts.cookiefile, os.R_OK): jar.load() except (IOError, OSError) as err: - sys.exit(u'ERROR: unable to open cookie file') + if opts.verbose: + traceback.print_exc() + sys.stderr.write(u'ERROR: unable to open cookie file\n') + sys.exit(101) # Set user agent if opts.user_agent is not None: std_headers['User-Agent'] = opts.user_agent @@ -352,6 +357,16 @@ def _real_main(): if numeric_limit is None: parser.error(u'invalid rate limit specified') opts.ratelimit = numeric_limit + if opts.min_filesize is not None: + numeric_limit = FileDownloader.parse_bytes(opts.min_filesize) + if numeric_limit is None: + parser.error(u'invalid min_filesize specified') + opts.min_filesize = numeric_limit + if opts.max_filesize is not None: + numeric_limit = FileDownloader.parse_bytes(opts.max_filesize) + if numeric_limit is None: + parser.error(u'invalid max_filesize specified') + opts.max_filesize = numeric_limit if opts.retries is not None: try: opts.retries = int(opts.retries) @@ -397,6 +412,7 @@ def _real_main(): or (opts.useid and u'%(id)s.%(ext)s') or (opts.autonumber and u'%(autonumber)s-%(id)s.%(ext)s') or u'%(id)s.%(ext)s') + # File downloader fd = FileDownloader({ 'usenetrc': opts.usenetrc, @@ -424,6 +440,7 @@ def _real_main(): 'noresizebuffer': opts.noresizebuffer, 'continuedl': opts.continue_dl, 'noprogress': opts.noprogress, + 'progress_with_newline': opts.progress_with_newline, 'playliststart': opts.playliststart, 'playlistend': opts.playlistend, 'logtostderr': opts.outtmpl == '-', @@ -434,13 +451,15 @@ def _real_main(): 'writeinfojson': opts.writeinfojson, 'writesubtitles': opts.writesubtitles, 'subtitleslang': opts.subtitleslang, - 'matchtitle': opts.matchtitle, - 'rejecttitle': opts.rejecttitle, + 'matchtitle': decodeOption(opts.matchtitle), + 'rejecttitle': decodeOption(opts.rejecttitle), 'max_downloads': opts.max_downloads, 'prefer_free_formats': opts.prefer_free_formats, 'verbose': opts.verbose, 'test': opts.test, 'keepvideo': opts.keepvideo, + 'min_filesize': opts.min_filesize, + 'max_filesize': opts.max_filesize }) if opts.verbose: @@ -466,6 +485,10 @@ def _real_main(): if opts.recodevideo: fd.add_post_processor(FFmpegVideoConvertor(preferedformat=opts.recodevideo)) + # Update version + if opts.update_self: + update_self(fd.to_screen, opts.verbose, sys.argv[0]) + # Maybe do nothing if len(all_urls) < 1: if not opts.update_self: