]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mojvideo.py
Merge pull request #4 from debian-janitor/lintian-fixes
[youtubedl] / youtube_dl / extractor / mojvideo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 ExtractorError,
9 parse_duration,
10 )
11
12
13 class MojvideoIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?mojvideo\.com/video-(?P<display_id>[^/]+)/(?P<id>[a-f0-9]+)'
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',
20 'display_id': 'v-avtu-pred-mano-rdecelaska-alfi-nipic',
21 'ext': 'mp4',
22 'title': 'V avtu pred mano rdečelaska - Alfi Nipič',
23 'thumbnail': r're:^http://.*\.jpg$',
24 'duration': 242,
25 }
26 }
27
28 def _real_extract(self, url):
29 mobj = re.match(self._VALID_URL, url)
30 video_id = mobj.group('id')
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)
36
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))
50
51 return {
52 'id': video_id,
53 'display_id': display_id,
54 'url': video_url,
55 'title': title,
56 'thumbnail': thumbnail,
57 'duration': duration,
58 }