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.

120 lines
4.8 KiB

10 years ago
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 (
  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|radio)/[^/]+/(?P<media_type>video|audio)/(?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/play/radio/hoerspielarchiv-srf-musikwelle/audio/saegel-ohni-wind-von-jakob-stebler?id=415bf3d3-6429-4de7-968d-95866e37cfbc',
  37. 'md5': '',
  38. 'info_dict': {
  39. 'id': '415bf3d3-6429-4de7-968d-95866e37cfbc',
  40. 'display_id': 'saegel-ohni-wind-von-jakob-stebler',
  41. 'ext': 'mp3',
  42. 'upload_date': '20080518',
  43. 'title': '«Sägel ohni Wind» von Jakob Stebler',
  44. 'timestamp': 1211112000,
  45. },
  46. 'params': {
  47. 'skip_download': True, # requires rtmpdump
  48. },
  49. }, {
  50. 'url': 'http://www.srf.ch/player/tv/10vor10/video/snowden-beantragt-asyl-in-russland?id=28e1a57d-5b76-4399-8ab3-9097f071e6c5',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'https://tp.srgssr.ch/p/flash?urn=urn:srf:ais:video:28e1a57d-5b76-4399-8ab3-9097f071e6c5',
  54. 'only_matching': True,
  55. }]
  56. def _real_extract(self, url):
  57. mobj = re.match(self._VALID_URL, url)
  58. video_id = mobj.group('id')
  59. media_type = mobj.group('media_type')
  60. display_id = mobj.group('display_id') or video_id
  61. video_data = self._download_xml(
  62. 'http://il.srgssr.ch/integrationlayer/1.0/ue/srf/%s/play/%s.xml' % (media_type, video_id),
  63. display_id)
  64. title = xpath_text(
  65. video_data, './AssetMetadatas/AssetMetadata/title', fatal=True)
  66. thumbnails = [{
  67. 'url': s.text
  68. } for s in video_data.findall('.//ImageRepresentation/url')]
  69. timestamp = parse_iso8601(xpath_text(video_data, './createdDate'))
  70. # The <duration> field in XML is different from the exact duration, skipping
  71. formats = []
  72. for item in video_data.findall('./Playlists/Playlist') + video_data.findall('./Downloads/Download'):
  73. for url_node in item.findall('url'):
  74. quality = url_node.attrib['quality']
  75. full_url = url_node.text
  76. original_ext = determine_ext(full_url).lower()
  77. format_id = '%s-%s' % (quality, item.attrib['protocol'])
  78. if original_ext == 'f4m':
  79. formats.extend(self._extract_f4m_formats(
  80. full_url + '?hdcore=3.4.0', display_id, f4m_id=format_id))
  81. elif original_ext == 'm3u8':
  82. formats.extend(self._extract_m3u8_formats(
  83. full_url, display_id, 'mp4', m3u8_id=format_id))
  84. else:
  85. formats.append({
  86. 'url': full_url,
  87. 'ext': original_ext,
  88. 'format_id': format_id,
  89. 'quality': 0 if 'HD' in quality else -1,
  90. 'preference': 1,
  91. })
  92. self._sort_formats(formats)
  93. subtitles = {}
  94. subtitles_data = video_data.find('Subtitles')
  95. if subtitles_data is not None:
  96. subtitles_list = [{
  97. 'url': sub.text,
  98. 'ext': determine_ext(sub.text),
  99. } for sub in subtitles_data]
  100. if subtitles_list:
  101. subtitles['de'] = subtitles_list
  102. return {
  103. 'id': video_id,
  104. 'display_id': display_id,
  105. 'formats': formats,
  106. 'title': title,
  107. 'thumbnails': thumbnails,
  108. 'timestamp': timestamp,
  109. 'subtitles': subtitles,
  110. }