logo

youtube-dl

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

tv2dk.py (6112B)


  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. 'add_ie': ['Kaltura'],
  41. }, {
  42. 'url': 'https://www.tv2lorry.dk/gadekamp/gadekamp-6-hoejhuse-i-koebenhavn',
  43. 'info_dict': {
  44. 'id': '1_7iwll9n0',
  45. 'ext': 'mp4',
  46. 'upload_date': '20211027',
  47. 'title': 'Gadekamp #6 - Højhuse i København',
  48. 'uploader_id': 'tv2lorry',
  49. 'timestamp': 1635345229,
  50. },
  51. 'add_ie': ['Kaltura'],
  52. }, {
  53. 'url': 'https://www.tv2ostjylland.dk/artikel/minister-gaar-ind-i-sag-om-diabetes-teknologi',
  54. 'only_matching': True,
  55. }, {
  56. 'url': 'https://www.tv2ostjylland.dk/nyheder/28-10-2019/22/2200-nyhederne-mandag-d-28-oktober-2019?autoplay=1#player',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'https://www.tvmidtvest.dk/nyheder/27-10-2019/1930/1930-27-okt-2019',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'https://www.tv2fyn.dk/artikel/fyn-kan-faa-landets-foerste-fabrik-til-groent-jetbraendstof',
  63. 'only_matching': True,
  64. }, {
  65. 'url': 'https://www.tv2east.dk/artikel/gods-faar-indleveret-tonsvis-af-aebler-100-kilo-aebler-gaar-til-en-aeblebrandy',
  66. 'only_matching': True,
  67. }, {
  68. 'url': 'https://www.tv2lorry.dk/koebenhavn/rasmus-paludan-evakueret-til-egen-demonstration#player',
  69. 'only_matching': True,
  70. }, {
  71. 'url': 'https://www.tv2nord.dk/artikel/dybt-uacceptabelt',
  72. 'only_matching': True,
  73. }]
  74. def _real_extract(self, url):
  75. video_id = self._match_id(url)
  76. webpage = self._download_webpage(url, video_id)
  77. entries = []
  78. def add_entry(partner_id, kaltura_id):
  79. entries.append(self.url_result(
  80. 'kaltura:%s:%s' % (partner_id, kaltura_id), 'Kaltura',
  81. video_id=kaltura_id))
  82. for video_el in re.findall(r'(?s)<[^>]+\bdata-entryid\s*=[^>]*>', webpage):
  83. video = extract_attributes(video_el)
  84. kaltura_id = video.get('data-entryid')
  85. if not kaltura_id:
  86. continue
  87. partner_id = video.get('data-partnerid')
  88. if not partner_id:
  89. continue
  90. add_entry(partner_id, kaltura_id)
  91. if not entries:
  92. kaltura_id = self._search_regex(
  93. (r'entry_id\s*:\s*["\']([0-9a-z_]+)',
  94. r'\\u002FentryId\\u002F(\w+)\\u002F'), webpage, 'kaltura id')
  95. partner_id = self._search_regex(
  96. (r'\\u002Fp\\u002F(\d+)\\u002F', r'/p/(\d+)/'), webpage,
  97. 'partner id')
  98. add_entry(partner_id, kaltura_id)
  99. if len(entries) == 1:
  100. return entries[0]
  101. return self.playlist_result(entries)
  102. class TV2DKBornholmPlayIE(InfoExtractor):
  103. _VALID_URL = r'https?://play\.tv2bornholm\.dk/\?.*?\bid=(?P<id>\d+)'
  104. _TEST = {
  105. 'url': 'http://play.tv2bornholm.dk/?area=specifikTV&id=781021',
  106. 'info_dict': {
  107. 'id': '781021',
  108. 'ext': 'mp4',
  109. 'title': '12Nyheder-27.11.19',
  110. },
  111. 'params': {
  112. 'skip_download': True,
  113. },
  114. }
  115. def _real_extract(self, url):
  116. video_id = self._match_id(url)
  117. video = self._download_json(
  118. 'https://play.tv2bornholm.dk/controls/AJAX.aspx/specifikVideo', video_id,
  119. data=json.dumps({
  120. 'playlist_id': video_id,
  121. 'serienavn': '',
  122. }).encode(), headers={
  123. 'X-Requested-With': 'XMLHttpRequest',
  124. 'Content-Type': 'application/json; charset=UTF-8',
  125. })['d']
  126. # TODO: generalize flowplayer
  127. title = self._search_regex(
  128. r'title\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1', video, 'title',
  129. group='value')
  130. sources = self._parse_json(self._search_regex(
  131. r'(?s)sources:\s*(\[.+?\]),', video, 'sources'),
  132. video_id, js_to_json)
  133. formats = []
  134. srcs = set()
  135. for source in sources:
  136. src = url_or_none(source.get('src'))
  137. if not src:
  138. continue
  139. if src in srcs:
  140. continue
  141. srcs.add(src)
  142. ext = determine_ext(src)
  143. src_type = source.get('type')
  144. if src_type == 'application/x-mpegurl' or ext == 'm3u8':
  145. formats.extend(self._extract_m3u8_formats(
  146. src, video_id, ext='mp4', entry_protocol='m3u8_native',
  147. m3u8_id='hls', fatal=False))
  148. elif src_type == 'application/dash+xml' or ext == 'mpd':
  149. formats.extend(self._extract_mpd_formats(
  150. src, video_id, mpd_id='dash', fatal=False))
  151. else:
  152. formats.append({
  153. 'url': src,
  154. })
  155. self._sort_formats(formats)
  156. return {
  157. 'id': video_id,
  158. 'title': title,
  159. 'formats': formats,
  160. }