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.

60 lines
1.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse,
  6. compat_urllib_request,
  7. )
  8. from ..utils import (
  9. remove_start,
  10. )
  11. class VideoMegaIE(InfoExtractor):
  12. _VALID_URL = r'''(?x)https?://
  13. (?:www\.)?videomega\.tv/
  14. (?:iframe\.php)?\?ref=(?P<id>[A-Za-z0-9]+)
  15. '''
  16. _TEST = {
  17. 'url': 'http://videomega.tv/?ref=QR0HCUHI1661IHUCH0RQ',
  18. 'md5': 'bf5c2f95c4c917536e80936af7bc51e1',
  19. 'info_dict': {
  20. 'id': 'QR0HCUHI1661IHUCH0RQ',
  21. 'ext': 'mp4',
  22. 'title': 'Big Buck Bunny',
  23. 'thumbnail': 're:^https?://.*\.jpg$',
  24. }
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. iframe_url = 'http://videomega.tv/iframe.php?ref={0:}'.format(video_id)
  29. req = compat_urllib_request.Request(iframe_url)
  30. req.add_header('Referer', url)
  31. webpage = self._download_webpage(req, video_id)
  32. escaped_data = self._search_regex(
  33. r'unescape\("([^"]+)"\)', webpage, 'escaped data')
  34. playlist = compat_urllib_parse.unquote(escaped_data)
  35. thumbnail = self._search_regex(
  36. r'image:\s*"([^"]+)"', playlist, 'thumbnail', fatal=False)
  37. video_url = self._search_regex(r'file:\s*"([^"]+)"', playlist, 'URL')
  38. title = remove_start(self._html_search_regex(
  39. r'<title>(.*?)</title>', webpage, 'title'), 'VideoMega.tv - ')
  40. formats = [{
  41. 'format_id': 'sd',
  42. 'url': video_url,
  43. }]
  44. self._sort_formats(formats)
  45. return {
  46. 'id': video_id,
  47. 'title': title,
  48. 'formats': formats,
  49. 'thumbnail': thumbnail,
  50. 'http_referer': iframe_url,
  51. }