videomega.py 1.9 KB

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