Merge remote-tracking branch 'yasoob/master'
[youtube-dl] / youtube_dl / extractor / ehow.py
1 import re
2 from ..utils import compat_urllib_parse
3 from .common import InfoExtractor
4
5
6 class EhowIE(InfoExtractor):
7     _VALID_URL = r'(?:http://)?(?:www\.)?ehow\.com/([^/]+)'
8     _TEST = {
9         u'url': u'http://www.ehow.com/video_12245069_hardwood-flooring-basics.html',
10         u'file': u'12245069.flv',
11         u'md5': u'9809b4e3f115ae2088440bcb4efbf371',
12         u'info_dict': {
13             u"title": u"Hardwood Flooring Basics",
14             u"description": u"Hardwood flooring may be time consuming, but its ultimately a pretty straightforward concept. Learn about hardwood flooring basics with help from a hardware flooring business owner in this free video...",
15                         u"uploader": u"Erick Nathan"
16         }
17     }
18
19     def _real_extract(self, url):
20         mobj = re.match(self._VALID_URL, url)
21         video_id = mobj.group(1).split("_")[1]
22         webpage = self._download_webpage(url, video_id)
23         video_url = self._search_regex(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)',
24             webpage, u'video URL')
25         final_url = compat_urllib_parse.unquote(video_url)        
26         thumbnail_url = self._search_regex(r'<meta property="og:image" content="(.+?)" />',
27             webpage, u'thumbnail URL')
28         uploader = self._search_regex(r'<meta name="uploader" content="(.+?)" />',
29             webpage, u'uploader')
30         title = self._search_regex(r'<meta property="og:title" content="(.+?)" />',
31             webpage, u'Video title').replace(' | eHow','')
32         description = self._search_regex(r'<meta property="og:description" content="(.+?)" />',
33             webpage, u'video description')
34         ext = final_url.split('.')[-1]
35         return [{
36             'id':          video_id,
37             'url':         final_url,
38             'ext':         ext,
39             'title':       title,
40             'thumbnail':   thumbnail_url,
41             'description': description,
42             'uploader':    uploader,
43         }]
44