vgtv.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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'http://(?:www\.)?(?P<host>vgtv|bt)\.no/(?:(?:tv/)?#!/(?:video|live)/(?P<id>[0-9]+)|(?:[^/]+/)*(?P<path>[^/]+))'
  9. _TESTS = [
  10. {
  11. # streamType: vod
  12. 'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
  13. 'md5': 'b8be7a234cebb840c0d512c78013e02f',
  14. 'info_dict': {
  15. 'id': '84196',
  16. 'ext': 'mp4',
  17. 'title': 'Hevnen er søt: Episode 10 - Abu',
  18. 'description': 'md5:e25e4badb5f544b04341e14abdc72234',
  19. 'thumbnail': 're:^https?://.*\.jpg',
  20. 'duration': 648.000,
  21. 'timestamp': 1404626400,
  22. 'upload_date': '20140706',
  23. 'view_count': int,
  24. },
  25. },
  26. {
  27. # streamType: wasLive
  28. 'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
  29. 'info_dict': {
  30. 'id': '100764',
  31. 'ext': 'flv',
  32. 'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
  33. 'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
  34. 'thumbnail': 're:^https?://.*\.jpg',
  35. 'duration': 9103.0,
  36. 'timestamp': 1410113864,
  37. 'upload_date': '20140907',
  38. 'view_count': int,
  39. },
  40. 'params': {
  41. # m3u8 download
  42. 'skip_download': True,
  43. },
  44. },
  45. {
  46. # streamType: live
  47. 'url': 'http://www.vgtv.no/#!/live/100015/direkte-her-kan-du-se-laksen-live-fra-suldalslaagen',
  48. 'info_dict': {
  49. 'id': '100015',
  50. 'ext': 'flv',
  51. 'title': 'DIREKTE: Her kan du se laksen live fra Suldalslågen!',
  52. 'description': 'md5:9a60cc23fa349f761628924e56eeec2d',
  53. 'thumbnail': 're:^https?://.*\.jpg',
  54. 'duration': 0,
  55. 'timestamp': 1407423348,
  56. 'upload_date': '20140807',
  57. 'view_count': int,
  58. },
  59. 'params': {
  60. # m3u8 download
  61. 'skip_download': True,
  62. },
  63. },
  64. {
  65. 'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
  66. 'only_matching': True,
  67. },
  68. ]
  69. def _real_extract(self, url):
  70. mobj = re.match(self._VALID_URL, url)
  71. video_id = mobj.group('id')
  72. host = mobj.group('host')
  73. HOST_WEBSITES = {
  74. 'vgtv': 'vgtv',
  75. 'bt': 'bttv',
  76. }
  77. data = self._download_json(
  78. 'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
  79. % (host, video_id, HOST_WEBSITES[host]),
  80. video_id, 'Downloading media JSON')
  81. streams = data['streamUrls']
  82. formats = []
  83. hls_url = streams.get('hls')
  84. if hls_url:
  85. formats.extend(self._extract_m3u8_formats(hls_url, video_id, 'mp4'))
  86. hds_url = streams.get('hds')
  87. if hds_url:
  88. formats.extend(self._extract_f4m_formats(hds_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18', video_id))
  89. mp4_url = streams.get('mp4')
  90. if mp4_url:
  91. _url = hls_url or hds_url
  92. MP4_URL_TEMPLATE = '%s/%%s.%s' % (mp4_url.rpartition('/')[0], mp4_url.rpartition('.')[-1])
  93. for mp4_format in _url.split(','):
  94. m = re.search('(?P<width>\d+)_(?P<height>\d+)_(?P<vbr>\d+)', mp4_format)
  95. if not m:
  96. continue
  97. width = int(m.group('width'))
  98. height = int(m.group('height'))
  99. vbr = int(m.group('vbr'))
  100. formats.append({
  101. 'url': MP4_URL_TEMPLATE % mp4_format,
  102. 'format_id': 'mp4-%s' % vbr,
  103. 'width': width,
  104. 'height': height,
  105. 'vbr': vbr,
  106. 'preference': 1,
  107. })
  108. self._sort_formats(formats)
  109. return {
  110. 'id': video_id,
  111. 'title': data['title'],
  112. 'description': data['description'],
  113. 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
  114. 'timestamp': data['published'],
  115. 'duration': float_or_none(data['duration'], 1000),
  116. 'view_count': data['displays'],
  117. 'formats': formats,
  118. }