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.

201 lines
6.8 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/100015/direkte-her-kan-du-se-laksen-live-fra-suldalslaagen',
  62. 'info_dict': {
  63. 'id': '100015',
  64. 'ext': 'flv',
  65. 'title': 'DIREKTE: Her kan du se laksen live fra Suldalslågen!',
  66. 'description': 'md5:9a60cc23fa349f761628924e56eeec2d',
  67. 'thumbnail': 're:^https?://.*\.jpg',
  68. 'duration': 0,
  69. 'timestamp': 1407423348,
  70. 'upload_date': '20140807',
  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. formats = []
  100. hls_url = streams.get('hls')
  101. if hls_url:
  102. formats.extend(self._extract_m3u8_formats(
  103. hls_url, video_id, 'mp4', m3u8_id='hls'))
  104. hds_url = streams.get('hds')
  105. # wasLive hds are always 404
  106. if hds_url and data.get('streamType') != 'wasLive':
  107. formats.extend(self._extract_f4m_formats(
  108. hds_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
  109. video_id, f4m_id='hds'))
  110. mp4_url = streams.get('mp4')
  111. if mp4_url:
  112. _url = hls_url or hds_url
  113. MP4_URL_TEMPLATE = '%s/%%s.%s' % (mp4_url.rpartition('/')[0], mp4_url.rpartition('.')[-1])
  114. for mp4_format in _url.split(','):
  115. m = re.search('(?P<width>\d+)_(?P<height>\d+)_(?P<vbr>\d+)', mp4_format)
  116. if not m:
  117. continue
  118. width = int(m.group('width'))
  119. height = int(m.group('height'))
  120. vbr = int(m.group('vbr'))
  121. formats.append({
  122. 'url': MP4_URL_TEMPLATE % mp4_format,
  123. 'format_id': 'mp4-%s' % vbr,
  124. 'width': width,
  125. 'height': height,
  126. 'vbr': vbr,
  127. 'preference': 1,
  128. })
  129. self._sort_formats(formats)
  130. return {
  131. 'id': video_id,
  132. 'title': data['title'],
  133. 'description': data['description'],
  134. 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
  135. 'timestamp': data['published'],
  136. 'duration': float_or_none(data['duration'], 1000),
  137. 'view_count': data['displays'],
  138. 'formats': formats,
  139. }
  140. class BTArticleIE(InfoExtractor):
  141. IE_NAME = 'bt:article'
  142. IE_DESC = 'Bergens Tidende Articles'
  143. _VALID_URL = 'http://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
  144. _TEST = {
  145. 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
  146. 'md5': 'd055e8ee918ef2844745fcfd1a4175fb',
  147. 'info_dict': {
  148. 'id': '23199',
  149. 'ext': 'mp4',
  150. 'title': 'Alrekstad internat',
  151. 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
  152. 'thumbnail': 're:^https?://.*\.jpg',
  153. 'duration': 191,
  154. 'timestamp': 1289991323,
  155. 'upload_date': '20101117',
  156. 'view_count': int,
  157. },
  158. }
  159. def _real_extract(self, url):
  160. webpage = self._download_webpage(url, self._match_id(url))
  161. video_id = self._search_regex(
  162. r'SVP\.Player\.load\(\s*(\d+)', webpage, 'video id')
  163. return self.url_result('vgtv:bt:%s' % video_id, 'VGTV')
  164. class BTVestlendingenIE(InfoExtractor):
  165. IE_NAME = 'bt:vestlendingen'
  166. IE_DESC = 'Bergens Tidende - Vestlendingen'
  167. _VALID_URL = 'http://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
  168. _TEST = {
  169. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
  170. 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
  171. 'info_dict': {
  172. 'id': '86588',
  173. 'ext': 'mov',
  174. 'title': 'Otto Wollertsen',
  175. 'description': 'Vestlendingen Otto Fredrik Wollertsen',
  176. 'timestamp': 1430473209,
  177. 'upload_date': '20150501',
  178. },
  179. }
  180. def _real_extract(self, url):
  181. return self.url_result('xstream:btno:%s' % self._match_id(url), 'Xstream')