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.

115 lines
3.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_iso8601,
  8. )
  9. class TV4IE(InfoExtractor):
  10. IE_DESC = 'tv4.se and tv4play.se'
  11. _VALID_URL = r'''(?x)https?://(?:www\.)?
  12. (?:
  13. tv4\.se/(?:[^/]+)/klipp/(?:.*)-|
  14. tv4play\.se/
  15. (?:
  16. (?:program|barn)/(?:[^/]+/|(?:[^\?]+)\?video_id=)|
  17. iframe/video/|
  18. film/|
  19. sport/|
  20. )
  21. )(?P<id>[0-9]+)'''
  22. _GEO_COUNTRIES = ['SE']
  23. _TESTS = [
  24. {
  25. 'url': 'http://www.tv4.se/kalla-fakta/klipp/kalla-fakta-5-english-subtitles-2491650',
  26. 'md5': 'cb837212f342d77cec06e6dad190e96d',
  27. 'info_dict': {
  28. 'id': '2491650',
  29. 'ext': 'mp4',
  30. 'title': 'Kalla Fakta 5 (english subtitles)',
  31. 'thumbnail': r're:^https?://.*\.jpg$',
  32. 'timestamp': int,
  33. 'upload_date': '20131125',
  34. },
  35. },
  36. {
  37. 'url': 'http://www.tv4play.se/iframe/video/3054113',
  38. 'md5': 'cb837212f342d77cec06e6dad190e96d',
  39. 'info_dict': {
  40. 'id': '3054113',
  41. 'ext': 'mp4',
  42. 'title': 'Så här jobbar ficktjuvarna - se avslöjande bilder',
  43. 'thumbnail': r're:^https?://.*\.jpg$',
  44. 'description': 'Unika bilder avslöjar hur turisternas fickor vittjas mitt på Stockholms central. Två experter på ficktjuvarna avslöjar knepen du ska se upp för.',
  45. 'timestamp': int,
  46. 'upload_date': '20150130',
  47. },
  48. },
  49. {
  50. 'url': 'http://www.tv4play.se/sport/3060959',
  51. 'only_matching': True,
  52. },
  53. {
  54. 'url': 'http://www.tv4play.se/film/2378136',
  55. 'only_matching': True,
  56. },
  57. {
  58. 'url': 'http://www.tv4play.se/barn/looney-tunes?video_id=3062412',
  59. 'only_matching': True,
  60. },
  61. {
  62. 'url': 'http://www.tv4play.se/program/farang/3922081',
  63. 'only_matching': True,
  64. }
  65. ]
  66. def _real_extract(self, url):
  67. video_id = self._match_id(url)
  68. info = self._download_json(
  69. 'http://www.tv4play.se/player/assets/%s.json' % video_id,
  70. video_id, 'Downloading video info JSON')
  71. title = info['title']
  72. manifest_url = self._download_json(
  73. 'https://playback-api.b17g.net/media/' + video_id,
  74. video_id, query={
  75. 'service': 'tv4',
  76. 'device': 'browser',
  77. 'protocol': 'hls',
  78. })['playbackItem']['manifestUrl']
  79. formats = self._extract_m3u8_formats(
  80. manifest_url, video_id, 'mp4',
  81. 'm3u8_native', m3u8_id='hls', fatal=False)
  82. formats.extend(self._extract_mpd_formats(
  83. manifest_url.replace('.m3u8', '.mpd'),
  84. video_id, mpd_id='dash', fatal=False))
  85. formats.extend(self._extract_f4m_formats(
  86. manifest_url.replace('.m3u8', '.f4m'),
  87. video_id, f4m_id='hds', fatal=False))
  88. formats.extend(self._extract_ism_formats(
  89. re.sub(r'\.ism/.+?\.m3u8', r'.ism/Manifest', manifest_url),
  90. video_id, ism_id='mss', fatal=False))
  91. if not formats and info.get('is_geo_restricted'):
  92. self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
  93. self._sort_formats(formats)
  94. return {
  95. 'id': video_id,
  96. 'title': title,
  97. 'formats': formats,
  98. # 'subtitles': subtitles,
  99. 'description': info.get('description'),
  100. 'timestamp': parse_iso8601(info.get('broadcast_date_time')),
  101. 'duration': int_or_none(info.get('duration')),
  102. 'thumbnail': info.get('image'),
  103. 'is_live': info.get('is_live') is True,
  104. }