logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

mojvideo.py (2094B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. parse_duration,
  8. )
  9. class MojvideoIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?mojvideo\.com/video-(?P<display_id>[^/]+)/(?P<id>[a-f0-9]+)'
  11. _TEST = {
  12. 'url': 'http://www.mojvideo.com/video-v-avtu-pred-mano-rdecelaska-alfi-nipic/3d1ed4497707730b2906',
  13. 'md5': 'f7fd662cc8ce2be107b0d4f2c0483ae7',
  14. 'info_dict': {
  15. 'id': '3d1ed4497707730b2906',
  16. 'display_id': 'v-avtu-pred-mano-rdecelaska-alfi-nipic',
  17. 'ext': 'mp4',
  18. 'title': 'V avtu pred mano rdečelaska - Alfi Nipič',
  19. 'thumbnail': r're:^http://.*\.jpg$',
  20. 'duration': 242,
  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')
  27. # XML is malformed
  28. playerapi = self._download_webpage(
  29. 'http://www.mojvideo.com/playerapi.php?v=%s&t=1' % video_id, display_id)
  30. if '<error>true</error>' in playerapi:
  31. error_desc = self._html_search_regex(
  32. r'<errordesc>([^<]*)</errordesc>', playerapi, 'error description', fatal=False)
  33. raise ExtractorError('%s said: %s' % (self.IE_NAME, error_desc), expected=True)
  34. title = self._html_search_regex(
  35. r'<title>([^<]+)</title>', playerapi, 'title')
  36. video_url = self._html_search_regex(
  37. r'<file>([^<]+)</file>', playerapi, 'video URL')
  38. thumbnail = self._html_search_regex(
  39. r'<preview>([^<]+)</preview>', playerapi, 'thumbnail', fatal=False)
  40. duration = parse_duration(self._html_search_regex(
  41. r'<duration>([^<]+)</duration>', playerapi, 'duration', fatal=False))
  42. return {
  43. 'id': video_id,
  44. 'display_id': display_id,
  45. 'url': video_url,
  46. 'title': title,
  47. 'thumbnail': thumbnail,
  48. 'duration': duration,
  49. }