]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/empflix.py
[ign] Fix extraction of video in articles
[youtube-dl.git] / youtube_dl / extractor / empflix.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6
7
8 class EmpflixIE(InfoExtractor):
9     _VALID_URL = r'^https?://www\.empflix\.com/videos/.*?-(?P<id>[0-9]+)\.html'
10     _TEST = {
11         'url': 'http://www.empflix.com/videos/Amateur-Finger-Fuck-33051.html',
12         'md5': 'b1bc15b6412d33902d6e5952035fcabc',
13         'info_dict': {
14             'id': '33051',
15             'ext': 'mp4',
16             'title': 'Amateur Finger Fuck',
17             'description': 'Amateur solo finger fucking.',
18             'age_limit': 18,
19         }
20     }
21
22     def _real_extract(self, url):
23         mobj = re.match(self._VALID_URL, url)
24         video_id = mobj.group('id')
25
26         webpage = self._download_webpage(url, video_id)
27         age_limit = self._rta_search(webpage)
28
29         video_title = self._html_search_regex(
30             r'name="title" value="(?P<title>[^"]*)"', webpage, 'title')
31         video_description = self._html_search_regex(
32             r'name="description" value="([^"]*)"', webpage, 'description', fatal=False)
33
34         cfg_url = self._html_search_regex(
35             r'flashvars\.config = escape\("([^"]+)"',
36             webpage, 'flashvars.config')
37
38         # XML is malformed
39         cfg_xml = self._download_webpage(
40             cfg_url, video_id, note='Downloading metadata')
41
42         formats = [
43             {
44                 'url': item[1],
45                 'format_id': item[0],
46             } for item in re.findall(
47                 r'<item>\s*<res>([^>]+)</res>\s*<videoLink>([^<]+)</videoLink>\s*</item>', cfg_xml)
48         ]
49
50         thumbnail = self._html_search_regex(
51             r'<startThumb>([^<]+)</startThumb>', cfg_xml, 'thumbnail', fatal=False)
52
53         return {
54             'id': video_id,
55             'title': video_title,
56             'description': video_description,
57             'thumbnail': thumbnail,
58             'formats': formats,
59             'age_limit': age_limit,
60         }