vgtv.py 4.0 KB

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