1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-11-22 00:07:50 +08:00
youtube-dl/youtube_dl/extractor/megavideoz.py

57 lines
1.8 KiB
Python
Raw Normal View History

2015-01-16 10:28:57 +08:00
# encoding: utf-8
from __future__ import unicode_literals
2015-04-19 06:07:45 +08:00
import re
2015-01-16 10:28:57 +08:00
from .common import InfoExtractor
from ..utils import (
2015-04-19 06:09:01 +08:00
ExtractorError,
2015-04-19 06:07:45 +08:00
float_or_none,
xpath_text,
2015-01-16 10:28:57 +08:00
)
2015-04-19 06:08:29 +08:00
class MegaVideozIE(InfoExtractor):
2015-04-19 06:07:45 +08:00
_VALID_URL = r'https?://(?:www\.)?megavideoz\.eu/video/(?P<id>[^/]+)(?:/(?P<display_id>[^/]+))?'
_TEST = {
'url': 'http://megavideoz.eu/video/WM6UB919XMXH/SMPTE-Universal-Film-Leader',
'info_dict': {
'id': '48723',
'display_id': 'SMPTE-Universal-Film-Leader',
'ext': 'mp4',
'title': 'SMPTE Universal Film Leader',
'thumbnail': 're:https?://.*?\.jpg',
'duration': 10.93,
2015-04-17 23:25:01 +08:00
}
2015-04-19 06:07:45 +08:00
}
2015-01-16 10:28:57 +08:00
def _real_extract(self, url):
2015-04-19 06:07:45 +08:00
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
display_id = mobj.group('display_id') or video_id
2015-01-16 10:28:57 +08:00
2015-04-19 06:07:45 +08:00
webpage = self._download_webpage(url, display_id)
2015-01-16 10:28:57 +08:00
if any(p in webpage for p in ('>Video Not Found<', '>404 Error<')):
2015-04-19 06:09:01 +08:00
raise ExtractorError('Video %s does not exist' % video_id, expected=True)
2015-04-19 06:07:45 +08:00
config = self._download_xml(
self._search_regex(
r"var\s+cnf\s*=\s*'([^']+)'", webpage, 'cnf url'),
display_id)
2015-01-16 10:28:57 +08:00
2015-04-19 06:07:45 +08:00
video_url = xpath_text(config, './file', 'video url', fatal=True)
title = xpath_text(config, './title', 'title', fatal=True)
thumbnail = xpath_text(config, './image', 'thumbnail')
duration = float_or_none(xpath_text(config, './duration', 'duration'))
video_id = xpath_text(config, './mediaid', 'video id') or video_id
2015-01-16 10:28:57 +08:00
return {
'id': video_id,
2015-04-19 06:07:45 +08:00
'display_id': display_id,
2015-01-16 10:28:57 +08:00
'url': video_url,
'title': title,
2015-04-19 06:07:45 +08:00
'thumbnail': thumbnail,
2015-01-16 10:28:57 +08:00
'duration': duration
}