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.

154 lines
5.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. determine_ext,
  8. extract_attributes,
  9. js_to_json,
  10. url_or_none,
  11. )
  12. class TV2DKIE(InfoExtractor):
  13. _VALID_URL = r'''(?x)
  14. https?://
  15. (?:www\.)?
  16. (?:
  17. tvsyd|
  18. tv2ostjylland|
  19. tvmidtvest|
  20. tv2fyn|
  21. tv2east|
  22. tv2lorry|
  23. tv2nord
  24. )\.dk/
  25. (:[^/]+/)*
  26. (?P<id>[^/?\#&]+)
  27. '''
  28. _TESTS = [{
  29. 'url': 'https://www.tvsyd.dk/nyheder/28-10-2019/1930/1930-28-okt-2019?autoplay=1#player',
  30. 'info_dict': {
  31. 'id': '0_52jmwa0p',
  32. 'ext': 'mp4',
  33. 'title': '19:30 - 28. okt. 2019',
  34. 'timestamp': 1572290248,
  35. 'upload_date': '20191028',
  36. 'uploader_id': 'tvsyd',
  37. 'duration': 1347,
  38. 'view_count': int,
  39. },
  40. 'params': {
  41. 'skip_download': True,
  42. },
  43. 'add_ie': ['Kaltura'],
  44. }, {
  45. 'url': 'https://www.tv2ostjylland.dk/artikel/minister-gaar-ind-i-sag-om-diabetes-teknologi',
  46. 'only_matching': True,
  47. }, {
  48. 'url': 'https://www.tv2ostjylland.dk/nyheder/28-10-2019/22/2200-nyhederne-mandag-d-28-oktober-2019?autoplay=1#player',
  49. 'only_matching': True,
  50. }, {
  51. 'url': 'https://www.tvmidtvest.dk/nyheder/27-10-2019/1930/1930-27-okt-2019',
  52. 'only_matching': True,
  53. }, {
  54. 'url': 'https://www.tv2fyn.dk/artikel/fyn-kan-faa-landets-foerste-fabrik-til-groent-jetbraendstof',
  55. 'only_matching': True,
  56. }, {
  57. 'url': 'https://www.tv2east.dk/artikel/gods-faar-indleveret-tonsvis-af-aebler-100-kilo-aebler-gaar-til-en-aeblebrandy',
  58. 'only_matching': True,
  59. }, {
  60. 'url': 'https://www.tv2lorry.dk/koebenhavn/rasmus-paludan-evakueret-til-egen-demonstration#player',
  61. 'only_matching': True,
  62. }, {
  63. 'url': 'https://www.tv2nord.dk/artikel/dybt-uacceptabelt',
  64. 'only_matching': True,
  65. }]
  66. def _real_extract(self, url):
  67. video_id = self._match_id(url)
  68. webpage = self._download_webpage(url, video_id)
  69. entries = []
  70. for video_el in re.findall(r'(?s)<[^>]+\bdata-entryid\s*=[^>]*>', webpage):
  71. video = extract_attributes(video_el)
  72. kaltura_id = video.get('data-entryid')
  73. if not kaltura_id:
  74. continue
  75. partner_id = video.get('data-partnerid')
  76. if not partner_id:
  77. continue
  78. entries.append(self.url_result(
  79. 'kaltura:%s:%s' % (partner_id, kaltura_id), 'Kaltura',
  80. video_id=kaltura_id))
  81. return self.playlist_result(entries)
  82. class TV2DKBornholmPlayIE(InfoExtractor):
  83. _VALID_URL = r'https?://play\.tv2bornholm\.dk/\?.*?\bid=(?P<id>\d+)'
  84. _TEST = {
  85. 'url': 'http://play.tv2bornholm.dk/?area=specifikTV&id=781021',
  86. 'info_dict': {
  87. 'id': '781021',
  88. 'ext': 'mp4',
  89. 'title': '12Nyheder-27.11.19',
  90. },
  91. 'params': {
  92. 'skip_download': True,
  93. },
  94. }
  95. def _real_extract(self, url):
  96. video_id = self._match_id(url)
  97. video = self._download_json(
  98. 'http://play.tv2bornholm.dk/controls/AJAX.aspx/specifikVideo', video_id,
  99. data=json.dumps({
  100. 'playlist_id': video_id,
  101. 'serienavn': '',
  102. }).encode(), headers={
  103. 'X-Requested-With': 'XMLHttpRequest',
  104. 'Content-Type': 'application/json; charset=UTF-8',
  105. })['d']
  106. # TODO: generalize flowplayer
  107. title = self._search_regex(
  108. r'title\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1', video, 'title',
  109. group='value')
  110. sources = self._parse_json(self._search_regex(
  111. r'(?s)sources:\s*(\[.+?\]),', video, 'sources'),
  112. video_id, js_to_json)
  113. formats = []
  114. srcs = set()
  115. for source in sources:
  116. src = url_or_none(source.get('src'))
  117. if not src:
  118. continue
  119. if src in srcs:
  120. continue
  121. srcs.add(src)
  122. ext = determine_ext(src)
  123. src_type = source.get('type')
  124. if src_type == 'application/x-mpegurl' or ext == 'm3u8':
  125. formats.extend(self._extract_m3u8_formats(
  126. src, video_id, ext='mp4', entry_protocol='m3u8_native',
  127. m3u8_id='hls', fatal=False))
  128. elif src_type == 'application/dash+xml' or ext == 'mpd':
  129. formats.extend(self._extract_mpd_formats(
  130. src, video_id, mpd_id='dash', fatal=False))
  131. else:
  132. formats.append({
  133. 'url': src,
  134. })
  135. self._sort_formats(formats)
  136. return {
  137. 'id': video_id,
  138. 'title': title,
  139. 'formats': formats,
  140. }