diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py index 411d01a41..89beaf453 100644 --- a/youtube_dl/FileDownloader.py +++ b/youtube_dl/FileDownloader.py @@ -9,7 +9,6 @@ import subprocess import sys import time -import urllib2 if os.name == 'nt': import ctypes @@ -461,7 +460,7 @@ def process_info(self, info_dict): success = self._do_download(filename, info_dict) except (OSError, IOError) as err: raise UnavailableVideoError - except (urllib2.URLError, httplib.HTTPException, socket.error) as err: + except (compat_urllib_error.URLError, httplib.HTTPException, socket.error) as err: self.trouble(u'ERROR: unable to download video data: %s' % str(err)) return except (ContentTooShortError, ) as err: @@ -585,8 +584,8 @@ def _do_download(self, filename, info_dict): # Do not include the Accept-Encoding header headers = {'Youtubedl-no-compression': 'True'} - basic_request = urllib2.Request(url, None, headers) - request = urllib2.Request(url, None, headers) + basic_request = compat_urllib_request.Request(url, None, headers) + request = compat_urllib_request.Request(url, None, headers) # Establish possible resume length if os.path.isfile(encodeFilename(tmpfilename)): @@ -610,9 +609,9 @@ def _do_download(self, filename, info_dict): try: if count == 0 and 'urlhandle' in info_dict: data = info_dict['urlhandle'] - data = urllib2.urlopen(request) + data = compat_urllib_request.urlopen(request) break - except (urllib2.HTTPError, ) as err: + except (compat_urllib_error.HTTPError, ) as err: if (err.code < 500 or err.code >= 600) and err.code != 416: # Unexpected HTTP error raise @@ -620,9 +619,9 @@ def _do_download(self, filename, info_dict): # Unable to resume (requested range not satisfiable) try: # Open the connection again without the range header - data = urllib2.urlopen(basic_request) + data = compat_urllib_request.urlopen(basic_request) content_length = data.info()['Content-Length'] - except (urllib2.HTTPError, ) as err: + except (compat_urllib_error.HTTPError, ) as err: if err.code < 500 or err.code >= 600: raise else: diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index f07735360..28731b895 100644 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -9,8 +9,6 @@ import re import socket import time -import urllib -import urllib2 import email.utils import xml.etree.ElementTree import random @@ -53,7 +51,7 @@ class InfoExtractor(object): player_url: SWF Player URL (used for rtmpdump). subtitles: The .srt file contents. urlhandle: [internal] The urlHandle to be used to download the file, - like returned by urllib2.urlopen + like returned by urllib.request.urlopen The fields should all be Unicode strings. @@ -257,11 +255,11 @@ def _real_initialize(self): return # Set language - request = urllib2.Request(self._LANG_URL) + request = compat_urllib_request.Request(self._LANG_URL) try: self.report_lang() - urllib2.urlopen(request).read() - except (urllib2.URLError, httplib.HTTPException, socket.error) as err: + compat_urllib_request.urlopen(request).read() + except (compat_urllib_error.URLError, httplib.HTTPException, socket.error) as err: self._downloader.to_stderr(u'WARNING: unable to set language: %s' % compat_str(err)) return @@ -277,14 +275,14 @@ def _real_initialize(self): 'username': username, 'password': password, } - request = urllib2.Request(self._LOGIN_URL, urllib.urlencode(login_form)) + request = compat_urllib_request.Request(self._LOGIN_URL, compat_urllib_parse.urlencode(login_form)) try: self.report_login() - login_results = urllib2.urlopen(request).read() + login_results = compat_urllib_request.urlopen(request).read() if re.search(r'(?i)