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.

116 lines
4.1 KiB

10 years ago
  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': 'flv',
  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': 'flv',
  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. video_id = self._match_id(url)
  66. data = self._download_json(
  67. 'http://svp.vg.no/svp/api/v1/vgtv/assets/%s?appName=vgtv-website' % video_id,
  68. video_id, 'Downloading media JSON')
  69. streams = data['streamUrls']
  70. formats = []
  71. hls_url = streams.get('hls')
  72. if hls_url:
  73. formats.extend(self._extract_m3u8_formats(hls_url, video_id, 'mp4'))
  74. hds_url = streams.get('hds')
  75. if hds_url:
  76. formats.extend(self._extract_f4m_formats(hds_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18', video_id))
  77. mp4_url = streams.get('mp4')
  78. if mp4_url:
  79. _url = hls_url or hds_url
  80. MP4_URL_TEMPLATE = '%s/%%s.%s' % (mp4_url.rpartition('/')[0], mp4_url.rpartition('.')[-1])
  81. for mp4_format in _url.split(','):
  82. m = re.search('(?P<width>\d+)_(?P<height>\d+)_(?P<vbr>\d+)', mp4_format)
  83. if not m:
  84. continue
  85. width = int(m.group('width'))
  86. height = int(m.group('height'))
  87. vbr = int(m.group('vbr'))
  88. formats.append({
  89. 'url': MP4_URL_TEMPLATE % mp4_format,
  90. 'format_id': 'mp4-%s' % vbr,
  91. 'width': width,
  92. 'height': height,
  93. 'vbr': vbr,
  94. 'preference': 1,
  95. })
  96. self._sort_formats(formats)
  97. return {
  98. 'id': video_id,
  99. 'title': data['title'],
  100. 'description': data['description'],
  101. 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
  102. 'timestamp': data['published'],
  103. 'duration': float_or_none(data['duration'], 1000),
  104. 'view_count': data['displays'],
  105. 'formats': formats,
  106. }