Add support for goldenmoustache.com
[youtube-dl] / youtube_dl / extractor / goldenmoustache.py
1 from __future__ import unicode_literals
2
3 import re
4 from .common import InfoExtractor
5 from ..utils import (
6     parse_duration,
7     int_or_none,
8 )
9
10
11 class GoldenMoustacheIE(InfoExtractor):
12     _VALID_URL = r'https?://(?:www\.)?goldenmoustache\.com/(?P<display_id>[\w-]+)-(?P<id>\d+)'
13     _TEST = {
14         'url': 'http://www.goldenmoustache.com/suricate-le-poker-3700/',
15         'md5': '0f904432fa07da5054d6c8beb5efb51a',
16         'info_dict': {
17             'id': '3700',
18             'ext': 'mp4',
19             'title': 'Suricate - Le Poker',
20             'description': 'md5:3d1f242f44f8c8cb0a106f1fd08e5dc9',
21             'thumbnail': 'md5:fd41386bc1f932552622da4a7e9a7242',
22         }
23     }
24
25     def _real_extract(self, url):
26         mobj = re.match(self._VALID_URL, url)
27         video_id = mobj.group('id')
28
29         webpage = self._download_webpage(url, video_id)
30
31         video_url = self._html_search_regex(r'data-src-type="mp4" data-src="([^"]+)"', webpage, 'video URL')
32
33         title = self._html_search_regex(r'<title>(.*?) - Golden Moustache</title>', webpage, 'title')
34
35         thumbnail = self._html_search_meta('og:image', webpage, 'thumbnail')
36          
37         description = self._html_search_meta('og:description', webpage, 'description')
38
39         view_count = int_or_none(self._html_search_regex(
40             r'<strong>(\d+)</strong>\s*VUES</span>', webpage, 'view count', fatal=False))
41
42         return {
43             'id': video_id,
44             'url': video_url,
45             'ext': 'mp4',
46             'title': title,
47             'description': description,
48             'thumbnail': thumbnail,
49             'view_count': view_count,
50         }