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.

263 lines
8.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from .xstream import XstreamIE
  6. from ..utils import (
  7. ExtractorError,
  8. float_or_none,
  9. )
  10. class VGTVIE(XstreamIE):
  11. IE_DESC = 'VGTV, BTTV, FTV, Aftenposten and Aftonbladet'
  12. _HOST_TO_APPNAME = {
  13. 'vgtv.no': 'vgtv',
  14. 'bt.no/tv': 'bttv',
  15. 'aftenbladet.no/tv': 'satv',
  16. 'fvn.no/fvntv': 'fvntv',
  17. 'aftenposten.no/webtv': 'aptv',
  18. }
  19. _APP_NAME_TO_VENDOR = {
  20. 'vgtv': 'vgtv',
  21. 'bttv': 'bt',
  22. 'satv': 'sa',
  23. 'fvntv': 'fvn',
  24. 'aptv': 'ap',
  25. }
  26. _VALID_URL = r'''(?x)
  27. (?:https?://(?:www\.)?
  28. (?P<host>
  29. %s
  30. )
  31. /
  32. (?:
  33. \#!/(?:video|live)/|
  34. embed?.*id=
  35. )|
  36. (?P<appname>
  37. %s
  38. ):)
  39. (?P<id>\d+)
  40. ''' % ('|'.join(_HOST_TO_APPNAME.keys()), '|'.join(_APP_NAME_TO_VENDOR.keys()))
  41. _TESTS = [
  42. {
  43. # streamType: vod
  44. 'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
  45. 'md5': 'b8be7a234cebb840c0d512c78013e02f',
  46. 'info_dict': {
  47. 'id': '84196',
  48. 'ext': 'mp4',
  49. 'title': 'Hevnen er søt: Episode 10 - Abu',
  50. 'description': 'md5:e25e4badb5f544b04341e14abdc72234',
  51. 'thumbnail': 're:^https?://.*\.jpg',
  52. 'duration': 648.000,
  53. 'timestamp': 1404626400,
  54. 'upload_date': '20140706',
  55. 'view_count': int,
  56. },
  57. },
  58. {
  59. # streamType: wasLive
  60. 'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
  61. 'info_dict': {
  62. 'id': '100764',
  63. 'ext': 'flv',
  64. 'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
  65. 'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
  66. 'thumbnail': 're:^https?://.*\.jpg',
  67. 'duration': 9103.0,
  68. 'timestamp': 1410113864,
  69. 'upload_date': '20140907',
  70. 'view_count': int,
  71. },
  72. 'params': {
  73. # m3u8 download
  74. 'skip_download': True,
  75. },
  76. 'skip': 'Video is no longer available',
  77. },
  78. {
  79. # streamType: wasLive
  80. 'url': 'http://www.vgtv.no/#!/live/113063/direkte-v75-fra-solvalla',
  81. 'md5': '458f4841239dab414343b50e5af8869c',
  82. 'info_dict': {
  83. 'id': '113063',
  84. 'ext': 'flv',
  85. 'title': 'V75 fra Solvalla 30.05.15',
  86. 'description': 'md5:b3743425765355855f88e096acc93231',
  87. 'thumbnail': 're:^https?://.*\.jpg',
  88. 'duration': 25966,
  89. 'timestamp': 1432975582,
  90. 'upload_date': '20150530',
  91. 'view_count': int,
  92. },
  93. },
  94. {
  95. 'url': 'http://www.aftenposten.no/webtv/#!/video/21039/trailer-sweatshop-i-can-t-take-any-more',
  96. 'md5': 'fd828cd29774a729bf4d4425fe192972',
  97. 'info_dict': {
  98. 'id': '21039',
  99. 'ext': 'mov',
  100. 'title': 'TRAILER: «SWEATSHOP» - I can´t take any more',
  101. 'description': 'md5:21891f2b0dd7ec2f78d84a50e54f8238',
  102. 'duration': 66,
  103. 'timestamp': 1417002452,
  104. 'upload_date': '20141126',
  105. 'view_count': int,
  106. }
  107. },
  108. {
  109. 'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
  110. 'only_matching': True,
  111. },
  112. ]
  113. def _real_extract(self, url):
  114. mobj = re.match(self._VALID_URL, url)
  115. video_id = mobj.group('id')
  116. host = mobj.group('host')
  117. appname = self._HOST_TO_APPNAME[host] if host else mobj.group('appname')
  118. vendor = self._APP_NAME_TO_VENDOR[appname]
  119. data = self._download_json(
  120. 'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
  121. % (vendor, video_id, appname),
  122. video_id, 'Downloading media JSON')
  123. if data.get('status') == 'inactive':
  124. raise ExtractorError(
  125. 'Video %s is no longer available' % video_id, expected=True)
  126. info = {
  127. 'formats': [],
  128. }
  129. if len(video_id) == 5:
  130. if appname == 'bttv':
  131. info = self._extract_video_info('btno', video_id)
  132. elif appname == 'aptv':
  133. info = self._extract_video_info('ap', video_id)
  134. streams = data['streamUrls']
  135. stream_type = data.get('streamType')
  136. formats = []
  137. hls_url = streams.get('hls')
  138. if hls_url:
  139. m3u8_formats = self._extract_m3u8_formats(
  140. hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
  141. if m3u8_formats:
  142. formats.extend(m3u8_formats)
  143. hds_url = streams.get('hds')
  144. if hds_url:
  145. hdcore_sign = 'hdcore=3.7.0'
  146. f4m_formats = self._extract_f4m_formats(
  147. hds_url + '?%s' % hdcore_sign, video_id, f4m_id='hds', fatal=False)
  148. if f4m_formats:
  149. for entry in f4m_formats:
  150. # URLs without the extra param induce an 404 error
  151. entry.update({'extra_param_to_segment_url': hdcore_sign})
  152. formats.append(entry)
  153. mp4_urls = streams.get('pseudostreaming') or []
  154. mp4_url = streams.get('mp4')
  155. if mp4_url:
  156. mp4_urls.append(mp4_url)
  157. for mp4_url in mp4_urls:
  158. format_info = {
  159. 'url': mp4_url,
  160. }
  161. mobj = re.search('(\d+)_(\d+)_(\d+)', mp4_url)
  162. if mobj:
  163. tbr = int(mobj.group(3))
  164. format_info.update({
  165. 'width': int(mobj.group(1)),
  166. 'height': int(mobj.group(2)),
  167. 'tbr': tbr,
  168. 'format_id': 'mp4-%s' % tbr,
  169. })
  170. formats.append(format_info)
  171. info['formats'].extend(formats)
  172. self._sort_formats(info['formats'])
  173. info.update({
  174. 'id': video_id,
  175. 'title': self._live_title(data['title']) if stream_type == 'live' else data['title'],
  176. 'description': data['description'],
  177. 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
  178. 'timestamp': data['published'],
  179. 'duration': float_or_none(data['duration'], 1000),
  180. 'view_count': data['displays'],
  181. 'is_live': True if stream_type == 'live' else False,
  182. })
  183. return info
  184. class BTArticleIE(InfoExtractor):
  185. IE_NAME = 'bt:article'
  186. IE_DESC = 'Bergens Tidende Articles'
  187. _VALID_URL = 'http://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
  188. _TEST = {
  189. 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
  190. 'md5': '2acbe8ad129b3469d5ae51b1158878df',
  191. 'info_dict': {
  192. 'id': '23199',
  193. 'ext': 'mp4',
  194. 'title': 'Alrekstad internat',
  195. 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
  196. 'thumbnail': 're:^https?://.*\.jpg',
  197. 'duration': 191,
  198. 'timestamp': 1289991323,
  199. 'upload_date': '20101117',
  200. 'view_count': int,
  201. },
  202. }
  203. def _real_extract(self, url):
  204. webpage = self._download_webpage(url, self._match_id(url))
  205. video_id = self._search_regex(
  206. r'<video[^>]+data-id="(\d+)"', webpage, 'video id')
  207. return self.url_result('bttv:%s' % video_id, 'VGTV')
  208. class BTVestlendingenIE(InfoExtractor):
  209. IE_NAME = 'bt:vestlendingen'
  210. IE_DESC = 'Bergens Tidende - Vestlendingen'
  211. _VALID_URL = 'http://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
  212. _TESTS = [{
  213. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
  214. 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
  215. 'info_dict': {
  216. 'id': '86588',
  217. 'ext': 'mov',
  218. 'title': 'Otto Wollertsen',
  219. 'description': 'Vestlendingen Otto Fredrik Wollertsen',
  220. 'timestamp': 1430473209,
  221. 'upload_date': '20150501',
  222. },
  223. 'skip': '404 Error',
  224. }, {
  225. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86255',
  226. 'md5': 'a2893f8632e96389f4bdf36aa9463ceb',
  227. 'info_dict': {
  228. 'id': '86255',
  229. 'ext': 'mov',
  230. 'title': 'Du må tåle å fryse og være sulten',
  231. 'description': 'md5:b8046f4d022d5830ddab04865791d063',
  232. 'upload_date': '20150321',
  233. 'timestamp': 1426942023,
  234. },
  235. }]
  236. def _real_extract(self, url):
  237. return self.url_result('bttv:%s' % self._match_id(url), 'VGTV')