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.

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