youtube-dl/youtube_dl/InfoExtractors.py

361 lines
12 KiB
Python
Raw Normal View History

2013-01-02 05:07:37 +09:00
import base64
import datetime
2013-01-27 11:01:23 +09:00
import itertools
import netrc
import os
import re
import socket
import time
import email.utils
import xml.etree.ElementTree
2012-08-09 03:04:02 +09:00
import random
import math
import operator
2013-05-16 06:38:44 +09:00
import hashlib
import binascii
import urllib
2012-11-28 11:34:40 +09:00
from .utils import *
2013-06-24 02:57:38 +09:00
from .extractor.common import InfoExtractor, SearchInfoExtractor
from .extractor.ard import ARDIE
from .extractor.arte import ArteTvIE
2013-06-24 05:24:58 +09:00
from .extractor.bandcamp import BandcampIE
from .extractor.bliptv import BlipTVIE, BlipTVUserIE
2013-06-24 03:50:22 +09:00
from .extractor.comedycentral import ComedyCentralIE
2013-06-24 04:10:21 +09:00
from .extractor.collegehumor import CollegeHumorIE
2013-06-24 03:09:47 +09:00
from .extractor.dailymotion import DailymotionIE
2013-06-24 04:06:20 +09:00
from .extractor.depositfiles import DepositFilesIE
2013-06-24 05:15:50 +09:00
from .extractor.eighttracks import EightTracksIE
2013-06-24 04:08:17 +09:00
from .extractor.escapist import EscapistIE
2013-06-24 04:00:34 +09:00
from .extractor.facebook import FacebookIE
2013-06-24 05:05:23 +09:00
from .extractor.funnyordie import FunnyOrDieIE
2013-06-24 03:29:46 +09:00
from .extractor.gametrailers import GametrailersIE
2013-06-24 03:31:45 +09:00
from .extractor.generic import GenericIE
from .extractor.googleplus import GooglePlusIE
from .extractor.googlesearch import GoogleSearchIE
2013-06-24 05:29:27 +09:00
from .extractor.hypem import HypemIE
2013-06-24 05:28:19 +09:00
from .extractor.ina import InaIE
2013-06-24 04:14:19 +09:00
from .extractor.infoq import InfoQIE
2013-06-24 05:07:27 +09:00
from .extractor.justintv import JustinTVIE
2013-06-24 05:16:41 +09:00
from .extractor.keek import KeekIE
2013-06-24 05:23:19 +09:00
from .extractor.liveleak import LiveLeakIE
from .extractor.metacafe import MetacafeIE
2013-06-24 04:59:15 +09:00
from .extractor.mixcloud import MixcloudIE
2013-06-24 04:27:38 +09:00
from .extractor.mtv import MTVIE
from .extractor.myspass import MySpassIE
2013-06-24 03:48:32 +09:00
from .extractor.myvideo import MyVideoIE
2013-06-24 04:18:00 +09:00
from .extractor.nba import NBAIE
from .extractor.statigram import StatigramIE
2013-06-24 03:12:18 +09:00
from .extractor.photobucket import PhotobucketIE
2013-06-24 05:13:32 +09:00
from .extractor.pornotube import PornotubeIE
2013-06-24 05:09:32 +09:00
from .extractor.rbmaradio import RBMARadioIE
2013-06-24 05:27:16 +09:00
from .extractor.redtube import RedTubeIE
2013-06-24 03:57:44 +09:00
from .extractor.soundcloud import SoundcloudIE, SoundcloudSetIE
2013-06-24 05:22:08 +09:00
from .extractor.spiegel import SpiegelIE
2013-06-24 04:16:32 +09:00
from .extractor.stanfordoc import StanfordOpenClassroomIE
2013-06-24 05:02:56 +09:00
from .extractor.steam import SteamIE
2013-06-24 04:55:53 +09:00
from .extractor.ted import TEDIE
2013-06-24 05:24:07 +09:00
from .extractor.tumblr import TumblrIE
2013-06-24 05:08:28 +09:00
from .extractor.ustream import UstreamIE
2013-06-24 05:25:46 +09:00
from .extractor.vbox7 import Vbox7IE
2013-06-24 03:18:21 +09:00
from .extractor.vimeo import VimeoIE
2013-06-24 05:26:30 +09:00
from .extractor.vine import VineIE
2013-06-24 05:04:08 +09:00
from .extractor.worldstarhiphop import WorldStarHipHopIE
2013-06-24 05:02:56 +09:00
from .extractor.xnxx import XNXXIE
from .extractor.xvideos import XVideosIE
from .extractor.yahoo import YahooIE, YahooSearchIE
2013-06-24 05:14:22 +09:00
from .extractor.youjizz import YouJizzIE
2013-06-24 05:01:02 +09:00
from .extractor.youku import YoukuIE
2013-06-24 05:12:14 +09:00
from .extractor.youporn import YouPornIE
from .extractor.youtube import YoutubeIE, YoutubePlaylistIE, YoutubeSearchIE, YoutubeUserIE, YoutubeChannelIE
from .extractor.zdf import ZDFIE
2013-01-02 04:43:43 +09:00
2012-08-16 08:54:03 +09:00
2012-08-09 03:04:02 +09:00
2012-12-14 05:27:57 +09:00
2012-12-21 05:28:27 +09:00
2012-12-27 09:38:41 +09:00
2013-01-12 21:49:14 +09:00
2013-01-02 03:37:07 +09:00
2013-03-07 14:09:55 +09:00
2013-01-02 03:37:07 +09:00
2013-01-06 05:42:35 +09:00
2013-01-06 05:42:35 +09:00
2013-02-08 16:25:55 +09:00
2013-02-16 21:46:13 +09:00
2013-03-12 09:08:54 +09:00
2013-03-27 05:37:08 +09:00
2013-05-01 22:55:46 +09:00
2013-03-12 09:08:54 +09:00
class HowcastIE(InfoExtractor):
2013-05-20 07:25:26 +09:00
"""Information Extractor for Howcast.com"""
_VALID_URL = r'(?:https?://)?(?:www\.)?howcast\.com/videos/(?P<id>\d+)'
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
webpage_url = 'http://www.howcast.com/videos/' + video_id
webpage = self._download_webpage(webpage_url, video_id)
2013-05-20 15:39:41 +09:00
self.report_extraction(video_id)
2013-06-06 20:27:27 +09:00
video_url = self._search_regex(r'\'?file\'?: "(http://mobile-media\.howcast\.com/[0-9]+\.mp4)',
webpage, u'video URL')
video_title = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') property=\'og:title\'',
2013-06-06 20:27:27 +09:00
webpage, u'title')
video_description = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') name=\'description\'',
2013-06-06 20:27:27 +09:00
webpage, u'description', fatal=False)
thumbnail = self._html_search_regex(r'<meta content=\'(.+?)\' property=\'og:image\'',
2013-06-06 20:27:27 +09:00
webpage, u'thumbnail', fatal=False)
2013-05-20 15:39:41 +09:00
return [{
'id': video_id,
'url': video_url,
'ext': 'mp4',
'title': video_title,
'description': video_description,
2013-05-20 15:39:41 +09:00
'thumbnail': thumbnail,
}]
2013-05-20 07:25:26 +09:00
class FlickrIE(InfoExtractor):
"""Information Extractor for Flickr videos"""
2013-05-21 23:07:27 +09:00
_VALID_URL = r'(?:https?://)?(?:www\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*'
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
video_uploader_id = mobj.group('uploader_id')
webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
webpage = self._download_webpage(webpage_url, video_id)
2013-06-06 20:27:27 +09:00
secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, u'secret')
first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
2013-05-21 23:07:27 +09:00
first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
2013-06-06 20:27:27 +09:00
first_xml, u'node_id')
second_url = 'https://secure.flickr.com/video_playlist.gne?node_id=' + node_id + '&tech=flash&mode=playlist&bitrate=700&secret=' + secret + '&rd=video.yahoo.com&noad=1'
2013-05-21 23:07:27 +09:00
second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
self.report_extraction(video_id)
mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
if mobj is None:
raise ExtractorError(u'Unable to extract video url')
video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
video_title = self._html_search_regex(r'<meta property="og:title" content=(?:"([^"]+)"|\'([^\']+)\')',
2013-06-06 20:27:27 +09:00
webpage, u'video title')
video_description = self._html_search_regex(r'<meta property="og:description" content=(?:"([^"]+)"|\'([^\']+)\')',
2013-06-06 20:27:27 +09:00
webpage, u'description', fatal=False)
thumbnail = self._html_search_regex(r'<meta property="og:image" content=(?:"([^"]+)"|\'([^\']+)\')',
2013-06-06 20:27:27 +09:00
webpage, u'thumbnail', fatal=False)
return [{
2013-05-21 23:07:27 +09:00
'id': video_id,
'url': video_url,
'ext': 'mp4',
'title': video_title,
'description': video_description,
2013-05-21 23:07:27 +09:00
'thumbnail': thumbnail,
'uploader_id': video_uploader_id,
}]
2013-05-21 21:37:32 +09:00
class TeamcocoIE(InfoExtractor):
_VALID_URL = r'http://teamcoco\.com/video/(?P<url_title>.*)'
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
if mobj is None:
raise ExtractorError(u'Invalid URL: %s' % url)
url_title = mobj.group('url_title')
webpage = self._download_webpage(url, url_title)
video_id = self._html_search_regex(r'<article class="video" data-id="(\d+?)"',
2013-06-06 20:27:27 +09:00
webpage, u'video id')
2013-05-21 21:37:32 +09:00
self.report_extraction(video_id)
video_title = self._html_search_regex(r'<meta property="og:title" content="(.+?)"',
2013-06-06 20:27:27 +09:00
webpage, u'title')
2013-05-21 21:37:32 +09:00
thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)"',
2013-06-06 20:27:27 +09:00
webpage, u'thumbnail', fatal=False)
2013-05-21 21:37:32 +09:00
video_description = self._html_search_regex(r'<meta property="og:description" content="(.*?)"',
2013-06-06 20:27:27 +09:00
webpage, u'description', fatal=False)
2013-05-21 21:37:32 +09:00
data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
data = self._download_webpage(data_url, video_id, 'Downloading data webpage')
2013-06-06 20:27:27 +09:00
video_url = self._html_search_regex(r'<file type="high".*?>(.*?)</file>',
2013-06-06 20:27:27 +09:00
data, u'video URL')
2013-05-21 21:37:32 +09:00
return [{
'id': video_id,
'url': video_url,
'ext': 'mp4',
'title': video_title,
'thumbnail': thumbnail,
2013-06-06 20:27:27 +09:00
'description': video_description,
2013-05-21 21:37:32 +09:00
}]
2013-06-07 18:46:03 +09:00
class XHamsterIE(InfoExtractor):
"""Information Extractor for xHamster"""
_VALID_URL = r'(?:http://)?(?:www.)?xhamster\.com/movies/(?P<id>[0-9]+)/.*\.html'
def _real_extract(self,url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
2013-06-07 18:46:03 +09:00
mrss_url = 'http://xhamster.com/movies/%s/.html' % video_id
webpage = self._download_webpage(mrss_url, video_id)
2013-06-07 18:46:03 +09:00
mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
if mobj is None:
raise ExtractorError(u'Unable to extract media URL')
if len(mobj.group('server')) == 0:
video_url = compat_urllib_parse.unquote(mobj.group('file'))
else:
video_url = mobj.group('server')+'/key='+mobj.group('file')
video_extension = video_url.split('.')[-1]
video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
2013-06-07 18:46:03 +09:00
webpage, u'title')
# Can't see the description anywhere in the UI
# video_description = self._html_search_regex(r'<span>Description: </span>(?P<description>[^<]+)',
# webpage, u'description', fatal=False)
# if video_description: video_description = unescapeHTML(video_description)
mobj = re.search(r'hint=\'(?P<upload_date_Y>[0-9]{4})-(?P<upload_date_m>[0-9]{2})-(?P<upload_date_d>[0-9]{2}) [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z]{3,4}\'', webpage)
2013-06-07 18:46:03 +09:00
if mobj:
video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
else:
2013-06-07 18:46:03 +09:00
video_upload_date = None
self._downloader.report_warning(u'Unable to extract upload date')
video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
2013-06-07 18:46:03 +09:00
webpage, u'uploader id', default=u'anonymous')
video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
webpage, u'thumbnail', fatal=False)
return [{
'id': video_id,
'url': video_url,
'ext': video_extension,
'title': video_title,
# 'description': video_description,
'upload_date': video_upload_date,
'uploader_id': video_uploader_id,
'thumbnail': video_thumbnail
}]
2013-06-05 23:16:53 +09:00
2013-06-17 03:34:45 +09:00
2013-01-02 03:37:07 +09:00
def gen_extractors():
""" Return a list of an instance of every supported extractor.
The order does matter; the first extractor matched is the one handling the URL.
"""
return [
YoutubePlaylistIE(),
YoutubeChannelIE(),
YoutubeUserIE(),
YoutubeSearchIE(),
YoutubeIE(),
MetacafeIE(),
DailymotionIE(),
GoogleSearchIE(),
PhotobucketIE(),
YahooIE(),
YahooSearchIE(),
DepositFilesIE(),
FacebookIE(),
BlipTVIE(),
BlipTVUserIE(),
2013-01-02 03:37:07 +09:00
VimeoIE(),
MyVideoIE(),
ComedyCentralIE(),
EscapistIE(),
CollegeHumorIE(),
XVideosIE(),
SoundcloudSetIE(),
2013-01-02 03:37:07 +09:00
SoundcloudIE(),
InfoQIE(),
MixcloudIE(),
StanfordOpenClassroomIE(),
MTVIE(),
YoukuIE(),
XNXXIE(),
2013-01-07 05:52:33 +09:00
YouJizzIE(),
PornotubeIE(),
YouPornIE(),
2013-01-02 03:37:07 +09:00
GooglePlusIE(),
ArteTvIE(),
NBAIE(),
2013-03-07 14:09:55 +09:00
WorldStarHipHopIE(),
2013-01-02 03:37:07 +09:00
JustinTVIE(),
FunnyOrDieIE(),
SteamIE(),
UstreamIE(),
2013-01-13 01:58:39 +09:00
RBMARadioIE(),
2013-01-27 11:01:23 +09:00
EightTracksIE(),
2013-02-08 16:25:55 +09:00
KeekIE(),
2013-02-18 01:13:06 +09:00
TEDIE(),
2013-02-19 02:45:09 +09:00
MySpassIE(),
2013-03-12 09:08:54 +09:00
SpiegelIE(),
LiveLeakIE(),
ARDIE(),
ZDFIE(),
TumblrIE(),
2013-05-01 22:55:46 +09:00
BandcampIE(),
2013-05-04 03:07:35 +09:00
RedTubeIE(),
2013-05-06 03:57:19 +09:00
InaIE(),
HowcastIE(),
2013-05-20 07:25:26 +09:00
VineIE(),
FlickrIE(),
2013-05-21 21:37:32 +09:00
TeamcocoIE(),
XHamsterIE(),
2013-06-05 23:16:53 +09:00
HypemIE(),
2013-06-08 16:44:38 +09:00
Vbox7IE(),
2013-06-17 03:34:45 +09:00
GametrailersIE(),
2013-06-24 01:58:53 +09:00
StatigramIE(),
2013-01-02 03:37:07 +09:00
GenericIE()
]
def get_info_extractor(ie_name):
"""Returns the info extractor class with the given ie_name"""
return globals()[ie_name+'IE']