'Ori Avtalion',
'shizeeg',
'Filippo Valsorda',
+ 'Christian Albrecht',
)
__license__ = 'Public Domain'
-__version__ = '2012.11.17'
+__version__ = '2012.11.29'
UPDATE_URL = 'https://raw.github.com/rg3/youtube-dl/master/youtube-dl'
UPDATE_URL_VERSION = 'https://raw.github.com/rg3/youtube-dl/master/LATEST_VERSION'
UPDATE_URL_EXE = 'https://raw.github.com/rg3/youtube-dl/master/youtube-dl.exe'
-import cookielib
import getpass
import optparse
import os
import socket
import subprocess
import sys
-import urllib2
import warnings
from utils import *
downloader.to_screen(u'Updating to latest version...')
- urlv = urllib2.urlopen(UPDATE_URL_VERSION)
+ urlv = compat_urllib_request.urlopen(UPDATE_URL_VERSION)
newversion = urlv.read().strip()
if newversion == __version__:
downloader.to_screen(u'youtube-dl is up-to-date (' + __version__ + ')')
sys.exit('ERROR: no write permissions on %s' % directory)
try:
- urlh = urllib2.urlopen(UPDATE_URL_EXE)
+ urlh = compat_urllib_request.urlopen(UPDATE_URL_EXE)
newcontent = urlh.read()
urlh.close()
with open(exe + '.new', 'wb') as outf:
outf.write(newcontent)
- except (IOError, OSError), err:
+ except (IOError, OSError) as err:
sys.exit('ERROR: unable to download latest version')
try:
b.close()
os.startfile(bat)
- except (IOError, OSError), err:
+ except (IOError, OSError) as err:
sys.exit('ERROR: unable to overwrite current version')
else:
try:
- urlh = urllib2.urlopen(UPDATE_URL)
+ urlh = compat_urllib_request.urlopen(UPDATE_URL)
newcontent = urlh.read()
urlh.close()
- except (IOError, OSError), err:
+ except (IOError, OSError) as err:
sys.exit('ERROR: unable to download latest version')
try:
with open(filename, 'wb') as outf:
outf.write(newcontent)
- except (IOError, OSError), err:
+ except (IOError, OSError) as err:
sys.exit('ERROR: unable to overwrite current version')
downloader.to_screen(u'Updated youtube-dl. Restart youtube-dl to use the new version.')
opts = []
- if option._short_opts: opts.append(option._short_opts[0])
- if option._long_opts: opts.append(option._long_opts[0])
- if len(opts) > 1: opts.insert(1, ', ')
+ if option._short_opts:
+ opts.append(option._short_opts[0])
+ if option._long_opts:
+ opts.append(option._long_opts[0])
+ if len(opts) > 1:
+ opts.insert(1, ', ')
if option.takes_value(): opts.append(' %s' % option.metavar)
dest='ratelimit', metavar='LIMIT', help='download rate limit (e.g. 50k or 44.6m)')
general.add_option('-R', '--retries',
dest='retries', metavar='RETRIES', help='number of retries (default is %default)', default=10)
+ general.add_option('--buffer-size',
+ dest='buffersize', metavar='SIZE', help='size of download buffer (e.g. 1024 or 16k) (default is %default)', default="1024")
+ general.add_option('--no-resize-buffer',
+ action='store_true', dest='noresizebuffer',
+ help='do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.', default=False)
general.add_option('--dump-user-agent',
action='store_true', dest='dump_user_agent',
help='display the current browser identification', default=False)
dest='outtmpl', metavar='TEMPLATE', help='output filename template. Use %(title)s to get the title, %(uploader)s for the uploader name, %(autonumber)s to get an automatically incremented number, %(ext)s for the filename extension, %(upload_date)s for the upload date (YYYYMMDD), %(extractor)s for the provider (youtube, metacafe, etc), %(id)s for the video id and %% for a literal percent. Use - to output to stdout.')
filesystem.add_option('--restrict-filenames',
action='store_true', dest='restrictfilenames',
- help='Avoid some characters such as "&" and spaces in filenames', default=False)
+ help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames', default=False)
filesystem.add_option('-a', '--batch-file',
dest='batchfile', metavar='FILE', help='file containing URLs to download (\'-\' for stdin)')
filesystem.add_option('-w', '--no-overwrites',
YoukuIE(),
XNXXIE(),
GooglePlusIE(),
-
+ ArteTvIE(),
GenericIE()
]
# Open appropriate CookieJar
if opts.cookiefile is None:
- jar = cookielib.CookieJar()
+ jar = compat_cookiejar.CookieJar()
else:
try:
- jar = cookielib.MozillaCookieJar(opts.cookiefile)
+ jar = compat_cookiejar.MozillaCookieJar(opts.cookiefile)
if os.path.isfile(opts.cookiefile) and os.access(opts.cookiefile, os.R_OK):
jar.load()
- except (IOError, OSError), err:
+ except (IOError, OSError) as err:
sys.exit(u'ERROR: unable to open cookie file')
# Set user agent
if opts.user_agent is not None:
# Dump user agent
if opts.dump_user_agent:
- print std_headers['User-Agent']
+ print(std_headers['User-Agent'])
sys.exit(0)
# Batch file verification
except IOError:
sys.exit(u'ERROR: batch file could not be read')
all_urls = batchurls + args
- all_urls = map(lambda url: url.strip(), all_urls)
+ all_urls = [url.strip() for url in all_urls]
# General configuration
- cookie_processor = urllib2.HTTPCookieProcessor(jar)
- proxy_handler = urllib2.ProxyHandler()
- opener = urllib2.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
- urllib2.install_opener(opener)
+ cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
+ proxy_handler = compat_urllib_request.ProxyHandler()
+ opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
+ compat_urllib_request.install_opener(opener)
socket.setdefaulttimeout(300) # 5 minutes should be enough (famous last words)
extractors = gen_extractors()
opts.ratelimit = numeric_limit
if opts.retries is not None:
try:
- opts.retries = long(opts.retries)
- except (TypeError, ValueError), err:
+ opts.retries = int(opts.retries)
+ except (TypeError, ValueError) as err:
parser.error(u'invalid retry count specified')
+ if opts.buffersize is not None:
+ numeric_buffersize = FileDownloader.parse_bytes(opts.buffersize)
+ if numeric_buffersize is None:
+ parser.error(u'invalid buffer size specified')
+ opts.buffersize = numeric_buffersize
try:
opts.playliststart = int(opts.playliststart)
if opts.playliststart <= 0:
raise ValueError(u'Playlist start must be positive')
- except (TypeError, ValueError), err:
+ except (TypeError, ValueError) as err:
parser.error(u'invalid playlist start number specified')
try:
opts.playlistend = int(opts.playlistend)
if opts.playlistend != -1 and (opts.playlistend <= 0 or opts.playlistend < opts.playliststart):
raise ValueError(u'Playlist end must be greater than playlist start')
- except (TypeError, ValueError), err:
+ except (TypeError, ValueError) as err:
parser.error(u'invalid playlist end number specified')
if opts.extractaudio:
if opts.audioformat not in ['best', 'aac', 'mp3', 'vorbis', 'm4a', 'wav']:
'ratelimit': opts.ratelimit,
'nooverwrites': opts.nooverwrites,
'retries': opts.retries,
+ 'buffersize': opts.buffersize,
+ 'noresizebuffer': opts.noresizebuffer,
'continuedl': opts.continue_dl,
'noprogress': opts.noprogress,
'playliststart': opts.playliststart,
parser.error(u'you must provide at least one URL')
else:
sys.exit()
-
+
try:
retcode = fd.download(all_urls)
except MaxDownloadsReached:
if opts.cookiefile is not None:
try:
jar.save()
- except (IOError, OSError), err:
+ except (IOError, OSError) as err:
sys.exit(u'ERROR: unable to save cookie jar')
sys.exit(retcode)