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.

264 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. 'info_dict': {
  82. 'id': '113063',
  83. 'ext': 'mp4',
  84. 'title': 'V75 fra Solvalla 30.05.15',
  85. 'description': 'md5:b3743425765355855f88e096acc93231',
  86. 'thumbnail': 're:^https?://.*\.jpg',
  87. 'duration': 25966,
  88. 'timestamp': 1432975582,
  89. 'upload_date': '20150530',
  90. 'view_count': int,
  91. },
  92. 'params': {
  93. # m3u8 download
  94. 'skip_download': True,
  95. },
  96. },
  97. {
  98. 'url': 'http://www.aftenposten.no/webtv/#!/video/21039/trailer-sweatshop-i-can-t-take-any-more',
  99. 'md5': 'fd828cd29774a729bf4d4425fe192972',
  100. 'info_dict': {
  101. 'id': '21039',
  102. 'ext': 'mov',
  103. 'title': 'TRAILER: «SWEATSHOP» - I can´t take any more',
  104. 'description': 'md5:21891f2b0dd7ec2f78d84a50e54f8238',
  105. 'duration': 66,
  106. 'timestamp': 1417002452,
  107. 'upload_date': '20141126',
  108. 'view_count': int,
  109. }
  110. },
  111. {
  112. 'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
  113. 'only_matching': True,
  114. },
  115. ]
  116. def _real_extract(self, url):
  117. mobj = re.match(self._VALID_URL, url)
  118. video_id = mobj.group('id')
  119. host = mobj.group('host')
  120. appname = self._HOST_TO_APPNAME[host] if host else mobj.group('appname')
  121. vendor = self._APP_NAME_TO_VENDOR[appname]
  122. data = self._download_json(
  123. 'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
  124. % (vendor, video_id, appname),
  125. video_id, 'Downloading media JSON')
  126. if data.get('status') == 'inactive':
  127. raise ExtractorError(
  128. 'Video %s is no longer available' % video_id, expected=True)
  129. info = {
  130. 'formats': [],
  131. }
  132. if len(video_id) == 5:
  133. if appname == 'bttv':
  134. info = self._extract_video_info('btno', video_id)
  135. elif appname == 'aptv':
  136. info = self._extract_video_info('ap', video_id)
  137. streams = data['streamUrls']
  138. stream_type = data.get('streamType')
  139. formats = []
  140. hls_url = streams.get('hls')
  141. if hls_url:
  142. formats.extend(self._extract_m3u8_formats(
  143. hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  144. hds_url = streams.get('hds')
  145. if hds_url:
  146. hdcore_sign = 'hdcore=3.7.0'
  147. f4m_formats = self._extract_f4m_formats(
  148. hds_url + '?%s' % hdcore_sign, video_id, f4m_id='hds', fatal=False)
  149. if f4m_formats:
  150. for entry in f4m_formats:
  151. # URLs without the extra param induce an 404 error
  152. entry.update({'extra_param_to_segment_url': hdcore_sign})
  153. formats.append(entry)
  154. mp4_urls = streams.get('pseudostreaming') or []
  155. mp4_url = streams.get('mp4')
  156. if mp4_url:
  157. mp4_urls.append(mp4_url)
  158. for mp4_url in mp4_urls:
  159. format_info = {
  160. 'url': mp4_url,
  161. }
  162. mobj = re.search('(\d+)_(\d+)_(\d+)', mp4_url)
  163. if mobj:
  164. tbr = int(mobj.group(3))
  165. format_info.update({
  166. 'width': int(mobj.group(1)),
  167. 'height': int(mobj.group(2)),
  168. 'tbr': tbr,
  169. 'format_id': 'mp4-%s' % tbr,
  170. })
  171. formats.append(format_info)
  172. info['formats'].extend(formats)
  173. self._sort_formats(info['formats'])
  174. info.update({
  175. 'id': video_id,
  176. 'title': self._live_title(data['title']) if stream_type == 'live' else data['title'],
  177. 'description': data['description'],
  178. 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
  179. 'timestamp': data['published'],
  180. 'duration': float_or_none(data['duration'], 1000),
  181. 'view_count': data['displays'],
  182. 'is_live': True if stream_type == 'live' else False,
  183. })
  184. return info
  185. class BTArticleIE(InfoExtractor):
  186. IE_NAME = 'bt:article'
  187. IE_DESC = 'Bergens Tidende Articles'
  188. _VALID_URL = 'http://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
  189. _TEST = {
  190. 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
  191. 'md5': '2acbe8ad129b3469d5ae51b1158878df',
  192. 'info_dict': {
  193. 'id': '23199',
  194. 'ext': 'mp4',
  195. 'title': 'Alrekstad internat',
  196. 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
  197. 'thumbnail': 're:^https?://.*\.jpg',
  198. 'duration': 191,
  199. 'timestamp': 1289991323,
  200. 'upload_date': '20101117',
  201. 'view_count': int,
  202. },
  203. }
  204. def _real_extract(self, url):
  205. webpage = self._download_webpage(url, self._match_id(url))
  206. video_id = self._search_regex(
  207. r'<video[^>]+data-id="(\d+)"', webpage, 'video id')
  208. return self.url_result('bttv:%s' % video_id, 'VGTV')
  209. class BTVestlendingenIE(InfoExtractor):
  210. IE_NAME = 'bt:vestlendingen'
  211. IE_DESC = 'Bergens Tidende - Vestlendingen'
  212. _VALID_URL = 'http://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
  213. _TESTS = [{
  214. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
  215. 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
  216. 'info_dict': {
  217. 'id': '86588',
  218. 'ext': 'mov',
  219. 'title': 'Otto Wollertsen',
  220. 'description': 'Vestlendingen Otto Fredrik Wollertsen',
  221. 'timestamp': 1430473209,
  222. 'upload_date': '20150501',
  223. },
  224. 'skip': '404 Error',
  225. }, {
  226. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86255',
  227. 'md5': 'a2893f8632e96389f4bdf36aa9463ceb',
  228. 'info_dict': {
  229. 'id': '86255',
  230. 'ext': 'mov',
  231. 'title': 'Du må tåle å fryse og være sulten',
  232. 'description': 'md5:b8046f4d022d5830ddab04865791d063',
  233. 'upload_date': '20150321',
  234. 'timestamp': 1426942023,
  235. },
  236. }]
  237. def _real_extract(self, url):
  238. return self.url_result('bttv:%s' % self._match_id(url), 'VGTV')