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.

203 lines
6.9 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. float_or_none,
  8. )
  9. class VGTVIE(InfoExtractor):
  10. IE_DESC = 'VGTV and BTTV'
  11. _VALID_URL = r'''(?x)
  12. (?:
  13. vgtv:|
  14. http://(?:www\.)?
  15. )
  16. (?P<host>vgtv|bt)
  17. (?:
  18. :|
  19. \.no/(?:tv/)?\#!/(?:video|live)/
  20. )
  21. (?P<id>[0-9]+)
  22. '''
  23. _TESTS = [
  24. {
  25. # streamType: vod
  26. 'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
  27. 'md5': 'b8be7a234cebb840c0d512c78013e02f',
  28. 'info_dict': {
  29. 'id': '84196',
  30. 'ext': 'mp4',
  31. 'title': 'Hevnen er søt: Episode 10 - Abu',
  32. 'description': 'md5:e25e4badb5f544b04341e14abdc72234',
  33. 'thumbnail': 're:^https?://.*\.jpg',
  34. 'duration': 648.000,
  35. 'timestamp': 1404626400,
  36. 'upload_date': '20140706',
  37. 'view_count': int,
  38. },
  39. },
  40. {
  41. # streamType: wasLive
  42. 'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
  43. 'info_dict': {
  44. 'id': '100764',
  45. 'ext': 'flv',
  46. 'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
  47. 'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
  48. 'thumbnail': 're:^https?://.*\.jpg',
  49. 'duration': 9103.0,
  50. 'timestamp': 1410113864,
  51. 'upload_date': '20140907',
  52. 'view_count': int,
  53. },
  54. 'params': {
  55. # m3u8 download
  56. 'skip_download': True,
  57. },
  58. },
  59. {
  60. # streamType: live
  61. 'url': 'http://www.vgtv.no/#!/live/113063/direkte-v75-fra-solvalla',
  62. 'info_dict': {
  63. 'id': '113063',
  64. 'ext': 'flv',
  65. 'title': 're:^DIREKTE: V75 fra Solvalla [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  66. 'description': 'md5:b3743425765355855f88e096acc93231',
  67. 'thumbnail': 're:^https?://.*\.jpg',
  68. 'duration': 0,
  69. 'timestamp': 1432975582,
  70. 'upload_date': '20150530',
  71. 'view_count': int,
  72. },
  73. 'params': {
  74. # m3u8 download
  75. 'skip_download': True,
  76. },
  77. },
  78. {
  79. 'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
  80. 'only_matching': True,
  81. },
  82. ]
  83. def _real_extract(self, url):
  84. mobj = re.match(self._VALID_URL, url)
  85. video_id = mobj.group('id')
  86. host = mobj.group('host')
  87. HOST_WEBSITES = {
  88. 'vgtv': 'vgtv',
  89. 'bt': 'bttv',
  90. }
  91. data = self._download_json(
  92. 'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
  93. % (host, video_id, HOST_WEBSITES[host]),
  94. video_id, 'Downloading media JSON')
  95. if data.get('status') == 'inactive':
  96. raise ExtractorError(
  97. 'Video %s is no longer available' % video_id, expected=True)
  98. streams = data['streamUrls']
  99. stream_type = data.get('streamType')
  100. formats = []
  101. hls_url = streams.get('hls')
  102. if hls_url:
  103. formats.extend(self._extract_m3u8_formats(
  104. hls_url, video_id, 'mp4', m3u8_id='hls'))
  105. hds_url = streams.get('hds')
  106. # wasLive hds are always 404
  107. if hds_url and stream_type != 'wasLive':
  108. formats.extend(self._extract_f4m_formats(
  109. hds_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
  110. video_id, f4m_id='hds'))
  111. mp4_url = streams.get('mp4')
  112. if mp4_url:
  113. _url = hls_url or hds_url
  114. MP4_URL_TEMPLATE = '%s/%%s.%s' % (mp4_url.rpartition('/')[0], mp4_url.rpartition('.')[-1])
  115. for mp4_format in _url.split(','):
  116. m = re.search('(?P<width>\d+)_(?P<height>\d+)_(?P<vbr>\d+)', mp4_format)
  117. if not m:
  118. continue
  119. width = int(m.group('width'))
  120. height = int(m.group('height'))
  121. vbr = int(m.group('vbr'))
  122. formats.append({
  123. 'url': MP4_URL_TEMPLATE % mp4_format,
  124. 'format_id': 'mp4-%s' % vbr,
  125. 'width': width,
  126. 'height': height,
  127. 'vbr': vbr,
  128. 'preference': 1,
  129. })
  130. self._sort_formats(formats)
  131. return {
  132. 'id': video_id,
  133. 'title': self._live_title(data['title']),
  134. 'description': data['description'],
  135. 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
  136. 'timestamp': data['published'],
  137. 'duration': float_or_none(data['duration'], 1000),
  138. 'view_count': data['displays'],
  139. 'formats': formats,
  140. 'is_live': True if stream_type == 'live' else False,
  141. }
  142. class BTArticleIE(InfoExtractor):
  143. IE_NAME = 'bt:article'
  144. IE_DESC = 'Bergens Tidende Articles'
  145. _VALID_URL = 'http://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
  146. _TEST = {
  147. 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
  148. 'md5': 'd055e8ee918ef2844745fcfd1a4175fb',
  149. 'info_dict': {
  150. 'id': '23199',
  151. 'ext': 'mp4',
  152. 'title': 'Alrekstad internat',
  153. 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
  154. 'thumbnail': 're:^https?://.*\.jpg',
  155. 'duration': 191,
  156. 'timestamp': 1289991323,
  157. 'upload_date': '20101117',
  158. 'view_count': int,
  159. },
  160. }
  161. def _real_extract(self, url):
  162. webpage = self._download_webpage(url, self._match_id(url))
  163. video_id = self._search_regex(
  164. r'SVP\.Player\.load\(\s*(\d+)', webpage, 'video id')
  165. return self.url_result('vgtv:bt:%s' % video_id, 'VGTV')
  166. class BTVestlendingenIE(InfoExtractor):
  167. IE_NAME = 'bt:vestlendingen'
  168. IE_DESC = 'Bergens Tidende - Vestlendingen'
  169. _VALID_URL = 'http://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
  170. _TEST = {
  171. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
  172. 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
  173. 'info_dict': {
  174. 'id': '86588',
  175. 'ext': 'mov',
  176. 'title': 'Otto Wollertsen',
  177. 'description': 'Vestlendingen Otto Fredrik Wollertsen',
  178. 'timestamp': 1430473209,
  179. 'upload_date': '20150501',
  180. },
  181. }
  182. def _real_extract(self, url):
  183. return self.url_result('xstream:btno:%s' % self._match_id(url), 'Xstream')