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.

66 lines
1.9 KiB

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