From c6b2afd3a33d2a65d55ef6f22fd8826c6e6b12d5 Mon Sep 17 00:00:00 2001 From: Lord-Simon Date: Sun, 17 Aug 2014 04:48:16 +0200 Subject: [PATCH] Fix urlopen in Python3 --- youtube_dl/extractor/toukoucity.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/toukoucity.py b/youtube_dl/extractor/toukoucity.py index 96d8890b9..b591f20a0 100644 --- a/youtube_dl/extractor/toukoucity.py +++ b/youtube_dl/extractor/toukoucity.py @@ -2,7 +2,12 @@ from __future__ import unicode_literals import re -import urllib2 +try: + # Python 3 urllib + from urllib.request import urlopen +except ImportError: + # Fall back to Python 2's urllib2 + from urllib2 import urlopen from .common import InfoExtractor from ..utils import ( @@ -42,7 +47,7 @@ class ToukouCityIE(InfoExtractor): view_count = self._html_search_regex(r'(.+?)', webpage, u'view_count') player_url = self._search_regex(r'SWFObject\(\'(.+?)\'.+?\)', webpage, u'player_url') description = self._search_regex(r'

(.+?)

', webpage, u'description') - filesize = int(urllib2.urlopen(video_url).headers["Content-Length"]) + filesize = int(urlopen(video_url).headers["Content-Length"]) return { 'id': video_id,