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.

261 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. formats.extend(self._extract_m3u8_formats(
  140. hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  141. hds_url = streams.get('hds')
  142. if hds_url:
  143. hdcore_sign = 'hdcore=3.7.0'
  144. f4m_formats = self._extract_f4m_formats(
  145. hds_url + '?%s' % hdcore_sign, video_id, f4m_id='hds', fatal=False)
  146. if f4m_formats:
  147. for entry in f4m_formats:
  148. # URLs without the extra param induce an 404 error
  149. entry.update({'extra_param_to_segment_url': hdcore_sign})
  150. formats.append(entry)
  151. mp4_urls = streams.get('pseudostreaming') or []
  152. mp4_url = streams.get('mp4')
  153. if mp4_url:
  154. mp4_urls.append(mp4_url)
  155. for mp4_url in mp4_urls:
  156. format_info = {
  157. 'url': mp4_url,
  158. }
  159. mobj = re.search('(\d+)_(\d+)_(\d+)', mp4_url)
  160. if mobj:
  161. tbr = int(mobj.group(3))
  162. format_info.update({
  163. 'width': int(mobj.group(1)),
  164. 'height': int(mobj.group(2)),
  165. 'tbr': tbr,
  166. 'format_id': 'mp4-%s' % tbr,
  167. })
  168. formats.append(format_info)
  169. info['formats'].extend(formats)
  170. self._sort_formats(info['formats'])
  171. info.update({
  172. 'id': video_id,
  173. 'title': self._live_title(data['title']) if stream_type == 'live' else data['title'],
  174. 'description': data['description'],
  175. 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
  176. 'timestamp': data['published'],
  177. 'duration': float_or_none(data['duration'], 1000),
  178. 'view_count': data['displays'],
  179. 'is_live': True if stream_type == 'live' else False,
  180. })
  181. return info
  182. class BTArticleIE(InfoExtractor):
  183. IE_NAME = 'bt:article'
  184. IE_DESC = 'Bergens Tidende Articles'
  185. _VALID_URL = 'http://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
  186. _TEST = {
  187. 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
  188. 'md5': '2acbe8ad129b3469d5ae51b1158878df',
  189. 'info_dict': {
  190. 'id': '23199',
  191. 'ext': 'mp4',
  192. 'title': 'Alrekstad internat',
  193. 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
  194. 'thumbnail': 're:^https?://.*\.jpg',
  195. 'duration': 191,
  196. 'timestamp': 1289991323,
  197. 'upload_date': '20101117',
  198. 'view_count': int,
  199. },
  200. }
  201. def _real_extract(self, url):
  202. webpage = self._download_webpage(url, self._match_id(url))
  203. video_id = self._search_regex(
  204. r'<video[^>]+data-id="(\d+)"', webpage, 'video id')
  205. return self.url_result('bttv:%s' % video_id, 'VGTV')
  206. class BTVestlendingenIE(InfoExtractor):
  207. IE_NAME = 'bt:vestlendingen'
  208. IE_DESC = 'Bergens Tidende - Vestlendingen'
  209. _VALID_URL = 'http://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
  210. _TESTS = [{
  211. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
  212. 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
  213. 'info_dict': {
  214. 'id': '86588',
  215. 'ext': 'mov',
  216. 'title': 'Otto Wollertsen',
  217. 'description': 'Vestlendingen Otto Fredrik Wollertsen',
  218. 'timestamp': 1430473209,
  219. 'upload_date': '20150501',
  220. },
  221. 'skip': '404 Error',
  222. }, {
  223. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86255',
  224. 'md5': 'a2893f8632e96389f4bdf36aa9463ceb',
  225. 'info_dict': {
  226. 'id': '86255',
  227. 'ext': 'mov',
  228. 'title': 'Du må tåle å fryse og være sulten',
  229. 'description': 'md5:b8046f4d022d5830ddab04865791d063',
  230. 'upload_date': '20150321',
  231. 'timestamp': 1426942023,
  232. },
  233. }]
  234. def _real_extract(self, url):
  235. return self.url_result('bttv:%s' % self._match_id(url), 'VGTV')