]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/mojvideo.py
[cleanup] Use `_html_extract_title`
[yt-dlp.git] / yt_dlp / extractor / mojvideo.py
CommitLineData
66420a2d
DF
1# coding: utf-8
2from __future__ import unicode_literals
b42a2a72 3
5537dce8
DF
4
5from .common import InfoExtractor
b42a2a72
S
6from ..utils import (
7 ExtractorError,
8 parse_duration,
9)
10
5537dce8
DF
11
12class 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
04f3fd2c 41 title = self._html_extract_title(playerapi)
b42a2a72
S
42 video_url = self._html_search_regex(
43 r'<file>([^<]+)</file>', playerapi, 'video URL')
44 thumbnail = self._html_search_regex(
45 r'<preview>([^<]+)</preview>', playerapi, 'thumbnail', fatal=False)
46 duration = parse_duration(self._html_search_regex(
47 r'<duration>([^<]+)</duration>', playerapi, 'duration', fatal=False))
5537dce8
DF
48
49 return {
50 'id': video_id,
b42a2a72
S
51 'display_id': display_id,
52 'url': video_url,
5537dce8 53 'title': title,
b42a2a72
S
54 'thumbnail': thumbnail,
55 'duration': duration,
5f6a1245 56 }