You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.8 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. float_or_none,
  8. xpath_text,
  9. )
  10. class MegaVideozIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?megavideoz\.eu/video/(?P<id>[^/]+)(?:/(?P<display_id>[^/]+))?'
  12. _TEST = {
  13. 'url': 'http://megavideoz.eu/video/WM6UB919XMXH/SMPTE-Universal-Film-Leader',
  14. 'info_dict': {
  15. 'id': '48723',
  16. 'display_id': 'SMPTE-Universal-Film-Leader',
  17. 'ext': 'mp4',
  18. 'title': 'SMPTE Universal Film Leader',
  19. 'thumbnail': 're:https?://.*?\.jpg',
  20. 'duration': 10.93,
  21. }
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. display_id = mobj.group('display_id') or video_id
  27. webpage = self._download_webpage(url, display_id)
  28. if any(p in webpage for p in ('>Video Not Found<', '>404 Error<')):
  29. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  30. config = self._download_xml(
  31. self._search_regex(
  32. r"var\s+cnf\s*=\s*'([^']+)'", webpage, 'cnf url'),
  33. display_id)
  34. video_url = xpath_text(config, './file', 'video url', fatal=True)
  35. title = xpath_text(config, './title', 'title', fatal=True)
  36. thumbnail = xpath_text(config, './image', 'thumbnail')
  37. duration = float_or_none(xpath_text(config, './duration', 'duration'))
  38. video_id = xpath_text(config, './mediaid', 'video id') or video_id
  39. return {
  40. 'id': video_id,
  41. 'display_id': display_id,
  42. 'url': video_url,
  43. 'title': title,
  44. 'thumbnail': thumbnail,
  45. 'duration': duration
  46. }