You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. int_or_none,
  8. js_to_json,
  9. try_get,
  10. )
  11. class JojIE(InfoExtractor):
  12. _VALID_URL = r'''(?x)
  13. (?:
  14. joj:|
  15. https?://media\.joj\.sk/embed/
  16. )
  17. (?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})
  18. '''
  19. _TESTS = [{
  20. 'url': 'https://media.joj.sk/embed/a388ec4c-6019-4a4a-9312-b1bee194e932',
  21. 'info_dict': {
  22. 'id': 'a388ec4c-6019-4a4a-9312-b1bee194e932',
  23. 'ext': 'mp4',
  24. 'title': 'NOVÉ BÝVANIE',
  25. 'thumbnail': r're:^https?://.*\.jpg$',
  26. 'duration': 3118,
  27. }
  28. }, {
  29. 'url': 'joj:a388ec4c-6019-4a4a-9312-b1bee194e932',
  30. 'only_matching': True,
  31. }]
  32. @staticmethod
  33. def _extract_urls(webpage):
  34. return re.findall(
  35. r'<iframe\b[^>]+\bsrc=["\'](?P<url>(?:https?:)?//media\.joj\.sk/embed/[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
  36. webpage)
  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)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': '%sp' % height if height else None,
  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. self._sort_formats(formats)
  78. thumbnail = self._og_search_thumbnail(webpage)
  79. duration = int_or_none(self._search_regex(
  80. r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
  81. return {
  82. 'id': video_id,
  83. 'title': title,
  84. 'thumbnail': thumbnail,
  85. 'duration': duration,
  86. 'formats': formats,
  87. }