logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

popcorntimes.py (3362B)


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