]>
Commit | Line | Data |
---|---|---|
66420a2d DF |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
b42a2a72 | 3 | |
5537dce8 DF |
4 | import re |
5 | ||
6 | from .common import InfoExtractor | |
b42a2a72 S |
7 | from ..utils import ( |
8 | ExtractorError, | |
9 | parse_duration, | |
10 | ) | |
11 | ||
5537dce8 DF |
12 | |
13 | class MojvideoIE(InfoExtractor): | |
b42a2a72 | 14 | _VALID_URL = r'https?://(?:www\.)?mojvideo\.com/video-(?P<display_id>[^/]+)/(?P<id>[a-f0-9]+)' |
5537dce8 DF |
15 | _TEST = { |
16 | 'url': 'http://www.mojvideo.com/video-v-avtu-pred-mano-rdecelaska-alfi-nipic/3d1ed4497707730b2906', | |
17 | 'md5': 'f7fd662cc8ce2be107b0d4f2c0483ae7', | |
18 | 'info_dict': { | |
19 | 'id': '3d1ed4497707730b2906', | |
b42a2a72 | 20 | 'display_id': 'v-avtu-pred-mano-rdecelaska-alfi-nipic', |
5537dce8 DF |
21 | 'ext': 'mp4', |
22 | 'title': 'V avtu pred mano rdečelaska - Alfi Nipič', | |
b42a2a72 S |
23 | 'thumbnail': 're:^http://.*\.jpg$', |
24 | 'duration': 242, | |
5537dce8 DF |
25 | } |
26 | } | |
27 | ||
28 | def _real_extract(self, url): | |
29 | mobj = re.match(self._VALID_URL, url) | |
30 | video_id = mobj.group('id') | |
b42a2a72 S |
31 | display_id = mobj.group('display_id') |
32 | ||
33 | # XML is malformed | |
34 | playerapi = self._download_webpage( | |
35 | 'http://www.mojvideo.com/playerapi.php?v=%s&t=1' % video_id, display_id) | |
5537dce8 | 36 | |
b42a2a72 S |
37 | if '<error>true</error>' in playerapi: |
38 | error_desc = self._html_search_regex( | |
39 | r'<errordesc>([^<]*)</errordesc>', playerapi, 'error description', fatal=False) | |
40 | raise ExtractorError('%s said: %s' % (self.IE_NAME, error_desc), expected=True) | |
41 | ||
42 | title = self._html_search_regex( | |
43 | r'<title>([^<]+)</title>', playerapi, 'title') | |
44 | video_url = self._html_search_regex( | |
45 | r'<file>([^<]+)</file>', playerapi, 'video URL') | |
46 | thumbnail = self._html_search_regex( | |
47 | r'<preview>([^<]+)</preview>', playerapi, 'thumbnail', fatal=False) | |
48 | duration = parse_duration(self._html_search_regex( | |
49 | r'<duration>([^<]+)</duration>', playerapi, 'duration', fatal=False)) | |
5537dce8 DF |
50 | |
51 | return { | |
52 | 'id': video_id, | |
b42a2a72 S |
53 | 'display_id': display_id, |
54 | 'url': video_url, | |
5537dce8 | 55 | 'title': title, |
b42a2a72 S |
56 | 'thumbnail': thumbnail, |
57 | 'duration': duration, | |
5f6a1245 | 58 | } |