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.

55 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 compat_urllib_request
  6. class VideoMegaIE(InfoExtractor):
  7. _VALID_URL = r'(?:videomega:|https?://(?:www\.)?videomega\.tv/(?:(?:view|iframe|cdn)\.php)?\?ref=)(?P<id>[A-Za-z0-9]+)'
  8. _TESTS = [{
  9. 'url': 'http://videomega.tv/cdn.php?ref=AOSQBJYKIDDIKYJBQSOA',
  10. 'md5': 'cc1920a58add3f05c6a93285b84fb3aa',
  11. 'info_dict': {
  12. 'id': 'AOSQBJYKIDDIKYJBQSOA',
  13. 'ext': 'mp4',
  14. 'title': '1254207',
  15. 'thumbnail': 're:^https?://.*\.jpg$',
  16. }
  17. }, {
  18. 'url': 'http://videomega.tv/cdn.php?ref=AOSQBJYKIDDIKYJBQSOA&width=1070&height=600',
  19. 'only_matching': True,
  20. }, {
  21. 'url': 'http://videomega.tv/view.php?ref=090051111052065112106089103052052103089106112065052111051090',
  22. 'only_matching': True,
  23. }]
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. iframe_url = 'http://videomega.tv/cdn.php?ref=%s' % video_id
  27. req = compat_urllib_request.Request(iframe_url)
  28. req.add_header('Referer', url)
  29. req.add_header('Cookie', 'noadvtday=0')
  30. webpage = self._download_webpage(req, video_id)
  31. title = self._html_search_regex(
  32. r'<title>(.+?)</title>', webpage, 'title')
  33. title = re.sub(
  34. r'(?:^[Vv]ideo[Mm]ega\.tv\s-\s*|\s*-\svideomega\.tv$)', '', title)
  35. thumbnail = self._search_regex(
  36. r'<video[^>]+?poster="([^"]+)"', webpage, 'thumbnail', fatal=False)
  37. video_url = self._search_regex(
  38. r'<source[^>]+?src="([^"]+)"', webpage, 'video URL')
  39. return {
  40. 'id': video_id,
  41. 'title': title,
  42. 'url': video_url,
  43. 'thumbnail': thumbnail,
  44. 'http_headers': {
  45. 'Referer': iframe_url,
  46. },
  47. }