X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2FInfoExtractors.py;h=94803aa95bc834c6454c32ad595f7ce256a7db93;hb=40b35b4aa6040ecc3ff7b3c9c8b908249633d86e;hp=44b2472c2677334b935f9e0723d53d43cd915a5e;hpb=717b1f72ed6070212a72ac823547cb3c776a6264;p=youtube-dl diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index 44b2472c2..94803aa95 100644 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -2,25 +2,15 @@ # -*- coding: utf-8 -*- import datetime -import HTMLParser -import httplib import netrc import os import re import socket import time -import urllib -import urllib2 import email.utils import xml.etree.ElementTree import random import math -from urlparse import parse_qs - -try: - import cStringIO as StringIO -except ImportError: - import StringIO from utils import * @@ -38,18 +28,24 @@ class InfoExtractor(object): The dictionaries must include the following fields: - id: Video identifier. - url: Final video URL. - uploader: Nickname of the video uploader. - title: Video title, unescaped. - ext: Video filename extension. - player_url: SWF Player URL (may be None). + id: Video identifier. + url: Final video URL. + uploader: Nickname of the video uploader, unescaped. + upload_date: Video upload date (YYYYMMDD). + title: Video title, unescaped. + ext: Video filename extension. The following fields are optional: - format: The video format, defaults to ext. Used by --get-format + format: The video format, defaults to ext (used for --get-format) thumbnail: Full URL to a video thumbnail image. - description One-line video description. + description: One-line video description. + 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 urllib.request.urlopen + + The fields should all be Unicode strings. Subclasses of this one should re-define the _real_initialize() and _real_extract() methods and define a _VALID_URL regexp. @@ -57,10 +53,14 @@ class InfoExtractor(object): _real_extract() must return a *list* of information dictionaries as described above. + + Finally, the _WORKING attribute should be set to False for broken IEs + in order to warn the users and skip the tests. """ _ready = False _downloader = None + _WORKING = True def __init__(self, downloader=None): """Constructor. Receives an optional downloader.""" @@ -71,6 +71,10 @@ class InfoExtractor(object): """Receives a URL and returns True if suitable for this IE.""" return re.match(self._VALID_URL, url) is not None + def working(self): + """Getter method for _WORKING.""" + return self._WORKING + def initialize(self): """Initializes an instance (authentication, etc).""" if not self._ready: @@ -238,16 +242,16 @@ class YoutubeIE(InfoExtractor): password = info[2] else: raise netrc.NetrcParseError('No authenticators for %s' % self._NETRC_MACHINE) - except (IOError, netrc.NetrcParseError), err: + except (IOError, netrc.NetrcParseError) as err: self._downloader.to_stderr(u'WARNING: parsing .netrc: %s' % compat_str(err)) 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), err: + compat_urllib_request.urlopen(request).read() + except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err: self._downloader.to_stderr(u'WARNING: unable to set language: %s' % compat_str(err)) return @@ -263,14 +267,14 @@ class YoutubeIE(InfoExtractor): '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)