joj.py 3.3 KB

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