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.

104 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 (
  6. determine_ext,
  7. parse_iso8601,
  8. xpath_text,
  9. )
  10. class SrfIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.srf\.ch/play(?:er)?/tv/[^/]+/video/(?P<display_id>[^?]+)\?id=|tp\.srgssr\.ch/p/flash\?urn=urn:srf:ais:video:)(?P<id>[0-9a-f\-]{36})'
  12. _TESTS = [{
  13. 'url': 'http://www.srf.ch/play/tv/10vor10/video/snowden-beantragt-asyl-in-russland?id=28e1a57d-5b76-4399-8ab3-9097f071e6c5',
  14. 'md5': '4cd93523723beff51bb4bee974ee238d',
  15. 'info_dict': {
  16. 'id': '28e1a57d-5b76-4399-8ab3-9097f071e6c5',
  17. 'display_id': 'snowden-beantragt-asyl-in-russland',
  18. 'ext': 'm4v',
  19. 'upload_date': '20130701',
  20. 'title': 'Snowden beantragt Asyl in Russland',
  21. 'timestamp': 1372713995,
  22. }
  23. }, {
  24. # No Speichern (Save) button
  25. 'url': 'http://www.srf.ch/play/tv/top-gear/video/jaguar-xk120-shadow-und-tornado-dampflokomotive?id=677f5829-e473-4823-ac83-a1087fe97faa',
  26. 'md5': 'd97e236e80d1d24729e5d0953d276a4f',
  27. 'info_dict': {
  28. 'id': '677f5829-e473-4823-ac83-a1087fe97faa',
  29. 'display_id': 'jaguar-xk120-shadow-und-tornado-dampflokomotive',
  30. 'ext': 'flv',
  31. 'upload_date': '20130710',
  32. 'title': 'Jaguar XK120, Shadow und Tornado-Dampflokomotive',
  33. 'timestamp': 1373493600,
  34. },
  35. }, {
  36. 'url': 'http://www.srf.ch/player/tv/10vor10/video/snowden-beantragt-asyl-in-russland?id=28e1a57d-5b76-4399-8ab3-9097f071e6c5',
  37. 'only_matching': True,
  38. }, {
  39. 'url': 'https://tp.srgssr.ch/p/flash?urn=urn:srf:ais:video:28e1a57d-5b76-4399-8ab3-9097f071e6c5',
  40. 'only_matching': True,
  41. }]
  42. def _real_extract(self, url):
  43. video_id = self._match_id(url)
  44. display_id = re.match(self._VALID_URL, url).group('display_id') or video_id
  45. video_data = self._download_xml(
  46. 'http://il.srgssr.ch/integrationlayer/1.0/ue/srf/video/play/%s.xml' % video_id,
  47. display_id)
  48. title = xpath_text(
  49. video_data, './AssetMetadatas/AssetMetadata/title', fatal=True)
  50. thumbnails = [{
  51. 'url': s.text
  52. } for s in video_data.findall('.//ImageRepresentation/url')]
  53. timestamp = parse_iso8601(xpath_text(video_data, './createdDate'))
  54. # The <duration> field in XML is different from the exact duration, skipping
  55. formats = []
  56. for item in video_data.findall('./Playlists/Playlist') + video_data.findall('./Downloads/Download'):
  57. for url_node in item.findall('url'):
  58. quality = url_node.attrib['quality']
  59. full_url = url_node.text
  60. original_ext = determine_ext(full_url)
  61. format_id = '%s-%s' % (quality, item.attrib['protocol'])
  62. if original_ext == 'f4m':
  63. formats.extend(self._extract_f4m_formats(
  64. full_url + '?hdcore=3.4.0', display_id, f4m_id=format_id))
  65. elif original_ext == 'm3u8':
  66. formats.extend(self._extract_m3u8_formats(
  67. full_url, display_id, 'mp4', m3u8_id=format_id))
  68. else:
  69. formats.append({
  70. 'url': full_url,
  71. 'ext': original_ext,
  72. 'format_id': format_id,
  73. 'quality': 0 if 'HD' in quality else -1,
  74. 'preference': 1,
  75. })
  76. self._sort_formats(formats)
  77. subtitles = {}
  78. subtitles_data = video_data.find('Subtitles')
  79. if subtitles_data is not None:
  80. subtitles_list = [{
  81. 'url': sub.text,
  82. 'ext': determine_ext(sub.text),
  83. } for sub in subtitles_data]
  84. if subtitles_list:
  85. subtitles['de'] = subtitles_list
  86. return {
  87. 'id': video_id,
  88. 'display_id': display_id,
  89. 'formats': formats,
  90. 'title': title,
  91. 'thumbnails': thumbnails,
  92. 'timestamp': timestamp,
  93. 'subtitles': subtitles,
  94. }