videomega.py 1.6 KB

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