logo

youtube-dl

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

joj.py (3748B)


  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>[^/?#^]+)
  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': 'https://media.joj.sk/embed/9i1cxv',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'joj:a388ec4c-6019-4a4a-9312-b1bee194e932',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'joj:9i1cxv',
  36. 'only_matching': True,
  37. }]
  38. @staticmethod
  39. def _extract_urls(webpage):
  40. return [
  41. mobj.group('url')
  42. for mobj in re.finditer(
  43. r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//media\.joj\.sk/embed/(?:(?!\1).)+)\1',
  44. webpage)]
  45. def _real_extract(self, url):
  46. video_id = self._match_id(url)
  47. webpage = self._download_webpage(
  48. 'https://media.joj.sk/embed/%s' % video_id, video_id)
  49. title = self._search_regex(
  50. (r'videoTitle\s*:\s*(["\'])(?P<title>(?:(?!\1).)+)\1',
  51. r'<title>(?P<title>[^<]+)'), webpage, 'title',
  52. default=None, group='title') or self._og_search_title(webpage)
  53. bitrates = self._parse_json(
  54. self._search_regex(
  55. r'(?s)(?:src|bitrates)\s*=\s*({.+?});', webpage, 'bitrates',
  56. default='{}'),
  57. video_id, transform_source=js_to_json, fatal=False)
  58. formats = []
  59. for format_url in try_get(bitrates, lambda x: x['mp4'], list) or []:
  60. if isinstance(format_url, compat_str):
  61. height = self._search_regex(
  62. r'(\d+)[pP]\.', format_url, 'height', default=None)
  63. formats.append({
  64. 'url': format_url,
  65. 'format_id': '%sp' % height if height else None,
  66. 'height': int(height),
  67. })
  68. if not formats:
  69. playlist = self._download_xml(
  70. 'https://media.joj.sk/services/Video.php?clip=%s' % video_id,
  71. video_id)
  72. for file_el in playlist.findall('./files/file'):
  73. path = file_el.get('path')
  74. if not path:
  75. continue
  76. format_id = file_el.get('id') or file_el.get('label')
  77. formats.append({
  78. 'url': 'http://n16.joj.sk/storage/%s' % path.replace(
  79. 'dat/', '', 1),
  80. 'format_id': format_id,
  81. 'height': int_or_none(self._search_regex(
  82. r'(\d+)[pP]', format_id or path, 'height',
  83. default=None)),
  84. })
  85. self._sort_formats(formats)
  86. thumbnail = self._og_search_thumbnail(webpage)
  87. duration = int_or_none(self._search_regex(
  88. r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
  89. return {
  90. 'id': video_id,
  91. 'title': title,
  92. 'thumbnail': thumbnail,
  93. 'duration': duration,
  94. 'formats': formats,
  95. }