1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-11-24 19:22:52 +08:00
youtube-dl/youtube_dl/extractor/howcast.py

42 lines
1.4 KiB
Python
Raw Normal View History

2014-02-11 03:45:17 +08:00
from __future__ import unicode_literals
2013-06-24 04:30:16 +08:00
import re
from .common import InfoExtractor
class HowcastIE(InfoExtractor):
2014-02-11 03:45:17 +08:00
_VALID_URL = r'https?://(?:www\.)?howcast\.com/videos/(?P<id>\d+)'
2013-06-28 02:46:46 +08:00
_TEST = {
2014-02-11 03:45:17 +08:00
'url': 'http://www.howcast.com/videos/390161-How-to-Tie-a-Square-Knot-Properly',
'md5': '8b743df908c42f60cf6496586c7f12c3',
'info_dict': {
'id': '390161',
'ext': 'mp4',
'description': 'The square knot, also known as the reef knot, is one of the oldest, most basic knots to tie, and can be used in many different ways. Here\'s the proper way to tie a square knot.',
'title': 'How to Tie a Square Knot Properly',
2013-06-28 02:46:46 +08:00
}
}
2013-06-24 04:30:16 +08:00
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
webpage = self._download_webpage(url, video_id)
2013-06-24 04:30:16 +08:00
self.report_extraction(video_id)
video_url = self._search_regex(r'\'?file\'?: "(http://mobile-media\.howcast\.com/[0-9]+\.mp4)',
2014-02-11 03:45:17 +08:00
webpage, 'video URL')
2013-06-24 04:30:16 +08:00
video_description = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') name=\'description\'',
2014-02-11 03:45:17 +08:00
webpage, 'description', fatal=False)
2013-06-24 04:30:16 +08:00
2014-02-11 03:45:17 +08:00
return {
'id': video_id,
'url': video_url,
'title': self._og_search_title(webpage),
2013-06-24 04:30:16 +08:00
'description': video_description,
2014-02-11 03:45:17 +08:00
'thumbnail': self._og_search_thumbnail(webpage),
}