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.

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