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.

100 lines
3.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. parse_iso8601,
  7. )
  8. class TV4IE(InfoExtractor):
  9. IE_DESC = 'tv4.se and tv4play.se'
  10. _VALID_URL = r'''(?x)https?://(?:www\.)?
  11. (?:
  12. tv4\.se/(?:[^/]+)/klipp/(?:.*)-|
  13. tv4play\.se/
  14. (?:
  15. (?:program|barn)/(?:[^\?]+)\?video_id=|
  16. iframe/video/|
  17. film/|
  18. sport/|
  19. )
  20. )(?P<id>[0-9]+)'''
  21. _TESTS = [
  22. {
  23. 'url': 'http://www.tv4.se/kalla-fakta/klipp/kalla-fakta-5-english-subtitles-2491650',
  24. 'md5': '909d6454b87b10a25aa04c4bdd416a9b',
  25. 'info_dict': {
  26. 'id': '2491650',
  27. 'ext': 'mp4',
  28. 'title': 'Kalla Fakta 5 (english subtitles)',
  29. 'thumbnail': 're:^https?://.*\.jpg$',
  30. 'timestamp': int,
  31. 'upload_date': '20131125',
  32. },
  33. },
  34. {
  35. 'url': 'http://www.tv4play.se/iframe/video/3054113',
  36. 'md5': '77f851c55139ffe0ebd41b6a5552489b',
  37. 'info_dict': {
  38. 'id': '3054113',
  39. 'ext': 'mp4',
  40. 'title': 'Så här jobbar ficktjuvarna - se avslöjande bilder',
  41. 'thumbnail': 're:^https?://.*\.jpg$',
  42. '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.',
  43. 'timestamp': int,
  44. 'upload_date': '20150130',
  45. },
  46. },
  47. {
  48. 'url': 'http://www.tv4play.se/sport/3060959',
  49. 'only_matching': True,
  50. },
  51. {
  52. 'url': 'http://www.tv4play.se/film/2378136',
  53. 'only_matching': True,
  54. },
  55. {
  56. 'url': 'http://www.tv4play.se/barn/looney-tunes?video_id=3062412',
  57. 'only_matching': True,
  58. },
  59. ]
  60. def _real_extract(self, url):
  61. video_id = self._match_id(url)
  62. info = self._download_json(
  63. 'http://www.tv4play.se/player/assets/%s.json' % video_id, video_id, 'Downloading video info JSON')
  64. # If is_geo_restricted is true, it doesn't neceserally mean we can't download it
  65. if info['is_geo_restricted']:
  66. self.report_warning('This content might not be available in your country due to licensing restrictions.')
  67. if info['requires_subscription']:
  68. raise ExtractorError('This content requires subscription.', expected=True)
  69. sources_data = self._download_json(
  70. 'https://prima.tv4play.se/api/web/asset/%s/play.json?protocol=http&videoFormat=MP4' % video_id, video_id, 'Downloading sources JSON')
  71. sources = sources_data['playback']
  72. formats = []
  73. for item in sources.get('items', {}).get('item', []):
  74. ext, bitrate = item['mediaFormat'], item['bitrate']
  75. formats.append({
  76. 'format_id': '%s_%s' % (ext, bitrate),
  77. 'tbr': bitrate,
  78. 'ext': ext,
  79. 'url': item['url'],
  80. })
  81. self._sort_formats(formats)
  82. return {
  83. 'id': video_id,
  84. 'title': info['title'],
  85. 'formats': formats,
  86. 'description': info.get('description'),
  87. 'timestamp': parse_iso8601(info.get('broadcast_date_time')),
  88. 'duration': info.get('duration'),
  89. 'thumbnail': info.get('image'),
  90. 'is_live': sources.get('live'),
  91. }