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.

118 lines
4.2 KiB

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