joj.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. format_field,
  4. int_or_none,
  5. js_to_json,
  6. try_get,
  7. )
  8. class JojIE(InfoExtractor):
  9. _VALID_URL = r'''(?x)
  10. (?:
  11. joj:|
  12. https?://media\.joj\.sk/embed/
  13. )
  14. (?P<id>[^/?#^]+)
  15. '''
  16. _EMBED_REGEX = [r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//media\.joj\.sk/embed/(?:(?!\1).)+)\1']
  17. _TESTS = [{
  18. 'url': 'https://media.joj.sk/embed/a388ec4c-6019-4a4a-9312-b1bee194e932',
  19. 'info_dict': {
  20. 'id': 'a388ec4c-6019-4a4a-9312-b1bee194e932',
  21. 'ext': 'mp4',
  22. 'title': 'NOVÉ BÝVANIE',
  23. 'thumbnail': r're:^https?://.*?$',
  24. 'duration': 3118,
  25. },
  26. }, {
  27. 'url': 'https://media.joj.sk/embed/CSM0Na0l0p1',
  28. 'info_dict': {
  29. 'id': 'CSM0Na0l0p1',
  30. 'ext': 'mp4',
  31. 'height': 576,
  32. 'title': 'Extrémne rodiny 2 - POKRAČOVANIE (2012/04/09 21:30:00)',
  33. 'duration': 3937,
  34. 'thumbnail': r're:^https?://.*?$',
  35. },
  36. }, {
  37. 'url': 'https://media.joj.sk/embed/9i1cxv',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'joj:a388ec4c-6019-4a4a-9312-b1bee194e932',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'joj:9i1cxv',
  44. 'only_matching': True,
  45. }]
  46. def _real_extract(self, url):
  47. video_id = self._match_id(url)
  48. webpage = self._download_webpage(
  49. f'https://media.joj.sk/embed/{video_id}', video_id)
  50. title = (self._search_json(r'videoTitle\s*:', webpage, 'title', video_id,
  51. contains_pattern=r'["\'].+["\']', default=None)
  52. or self._html_extract_title(webpage, default=None)
  53. or self._og_search_title(webpage))
  54. bitrates = self._parse_json(
  55. self._search_regex(
  56. r'(?s)(?:src|bitrates)\s*=\s*({.+?});', webpage, 'bitrates',
  57. default='{}'),
  58. video_id, transform_source=js_to_json, fatal=False)
  59. formats = []
  60. for format_url in try_get(bitrates, lambda x: x['mp4'], list) or []:
  61. if isinstance(format_url, str):
  62. height = self._search_regex(
  63. r'(\d+)[pP]|(pal)\.', format_url, 'height', default=None)
  64. if height == 'pal':
  65. height = 576
  66. formats.append({
  67. 'url': format_url,
  68. 'format_id': format_field(height, None, '%sp'),
  69. 'height': int_or_none(height),
  70. })
  71. if not formats:
  72. playlist = self._download_xml(
  73. f'https://media.joj.sk/services/Video.php?clip={video_id}',
  74. video_id)
  75. for file_el in playlist.findall('./files/file'):
  76. path = file_el.get('path')
  77. if not path:
  78. continue
  79. format_id = file_el.get('id') or file_el.get('label')
  80. formats.append({
  81. 'url': 'http://n16.joj.sk/storage/{}'.format(path.replace(
  82. 'dat/', '', 1)),
  83. 'format_id': format_id,
  84. 'height': int_or_none(self._search_regex(
  85. r'(\d+)[pP]', format_id or path, 'height',
  86. default=None)),
  87. })
  88. thumbnail = self._og_search_thumbnail(webpage)
  89. duration = int_or_none(self._search_regex(
  90. r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
  91. return {
  92. 'id': video_id,
  93. 'title': title,
  94. 'thumbnail': thumbnail,
  95. 'duration': duration,
  96. 'formats': formats,
  97. }