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.

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