popcorntimes.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import base64
  2. from .common import InfoExtractor
  3. from ..utils import int_or_none
  4. class PopcorntimesIE(InfoExtractor):
  5. _VALID_URL = r'https?://popcorntimes\.tv/[^/]+/m/(?P<id>[^/]+)/(?P<display_id>[^/?#&]+)'
  6. _TEST = {
  7. 'url': 'https://popcorntimes.tv/de/m/A1XCFvz/haensel-und-gretel-opera-fantasy',
  8. 'md5': '93f210991ad94ba8c3485950a2453257',
  9. 'info_dict': {
  10. 'id': 'A1XCFvz',
  11. 'display_id': 'haensel-und-gretel-opera-fantasy',
  12. 'ext': 'mp4',
  13. 'title': 'Hänsel und Gretel',
  14. 'description': 'md5:1b8146791726342e7b22ce8125cf6945',
  15. 'thumbnail': r're:^https?://.*\.jpg$',
  16. 'creator': 'John Paul',
  17. 'release_date': '19541009',
  18. 'duration': 4260,
  19. 'tbr': 5380,
  20. 'width': 720,
  21. 'height': 540,
  22. },
  23. }
  24. def _real_extract(self, url):
  25. mobj = self._match_valid_url(url)
  26. video_id, display_id = mobj.group('id', 'display_id')
  27. webpage = self._download_webpage(url, display_id)
  28. title = self._search_regex(
  29. r'<h1>([^<]+)', webpage, 'title',
  30. default=None) or self._html_search_meta(
  31. 'ya:ovs:original_name', webpage, 'title', fatal=True)
  32. loc = self._search_regex(
  33. r'PCTMLOC\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1', webpage, 'loc',
  34. group='value')
  35. loc_b64 = ''
  36. for c in loc:
  37. c_ord = ord(c)
  38. if ord('a') <= c_ord <= ord('z') or ord('A') <= c_ord <= ord('Z'):
  39. upper = ord('Z') if c_ord <= ord('Z') else ord('z')
  40. c_ord += 13
  41. if upper < c_ord:
  42. c_ord -= 26
  43. loc_b64 += chr(c_ord)
  44. video_url = base64.b64decode(loc_b64).decode('utf-8')
  45. description = self._html_search_regex(
  46. r'(?s)<div[^>]+class=["\']pt-movie-desc[^>]+>(.+?)</div>', webpage,
  47. 'description', fatal=False)
  48. thumbnail = self._search_regex(
  49. r'<img[^>]+class=["\']video-preview[^>]+\bsrc=(["\'])(?P<value>(?:(?!\1).)+)\1',
  50. webpage, 'thumbnail', default=None,
  51. group='value') or self._og_search_thumbnail(webpage)
  52. creator = self._html_search_meta(
  53. 'video:director', webpage, 'creator', default=None)
  54. release_date = self._html_search_meta(
  55. 'video:release_date', webpage, default=None)
  56. if release_date:
  57. release_date = release_date.replace('-', '')
  58. def int_meta(name):
  59. return int_or_none(self._html_search_meta(
  60. name, webpage, default=None))
  61. return {
  62. 'id': video_id,
  63. 'display_id': display_id,
  64. 'url': video_url,
  65. 'title': title,
  66. 'description': description,
  67. 'thumbnail': thumbnail,
  68. 'creator': creator,
  69. 'release_date': release_date,
  70. 'duration': int_meta('video:duration'),
  71. 'tbr': int_meta('ya:ovs:bitrate'),
  72. 'width': int_meta('og:video:width'),
  73. 'height': int_meta('og:video:height'),
  74. 'http_headers': {
  75. 'Referer': url,
  76. },
  77. }