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