megavideoz.py 1.6 KB

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