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.

97 lines
3.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_request,
  7. )
  8. from ..utils import (
  9. parse_iso8601,
  10. )
  11. class SportDeutschlandIE(InfoExtractor):
  12. _VALID_URL = r'https?://sportdeutschland\.tv/(?P<sport>[^/?#]+)/(?P<id>[^?#/]+)(?:$|[?#])'
  13. _TESTS = [{
  14. 'url': 'http://sportdeutschland.tv/badminton/live-li-ning-badminton-weltmeisterschaft-2014-kopenhagen',
  15. 'info_dict': {
  16. 'id': 'live-li-ning-badminton-weltmeisterschaft-2014-kopenhagen',
  17. 'ext': 'mp4',
  18. 'title': 're:Li-Ning Badminton Weltmeisterschaft 2014 Kopenhagen',
  19. 'categories': ['Badminton'],
  20. 'view_count': int,
  21. 'thumbnail': 're:^https?://.*\.jpg$',
  22. 'description': 're:Die Badminton-WM 2014 aus Kopenhagen bei Sportdeutschland\.TV',
  23. 'timestamp': int,
  24. 'upload_date': 're:^201408[23][0-9]$',
  25. },
  26. 'params': {
  27. 'skip_download': 'Live stream',
  28. },
  29. }, {
  30. 'url': 'http://sportdeutschland.tv/li-ning-badminton-wm-2014/lee-li-ning-badminton-weltmeisterschaft-2014-kopenhagen-herren-einzel-wei-vs',
  31. 'info_dict': {
  32. 'id': 'lee-li-ning-badminton-weltmeisterschaft-2014-kopenhagen-herren-einzel-wei-vs',
  33. 'ext': 'mp4',
  34. 'upload_date': '20140825',
  35. 'description': 'md5:60a20536b57cee7d9a4ec005e8687504',
  36. 'timestamp': 1408976060,
  37. 'title': 'Li-Ning Badminton Weltmeisterschaft 2014 Kopenhagen: Herren Einzel, Wei Lee vs. Keun Lee',
  38. 'thumbnail': 're:^https?://.*\.jpg$',
  39. 'view_count': int,
  40. 'categories': ['Li-Ning Badminton WM 2014'],
  41. }
  42. }]
  43. def _real_extract(self, url):
  44. mobj = re.match(self._VALID_URL, url)
  45. video_id = mobj.group('id')
  46. sport_id = mobj.group('sport')
  47. api_url = 'http://splink.tv/api/permalinks/%s/%s' % (
  48. sport_id, video_id)
  49. req = compat_urllib_request.Request(api_url, headers={
  50. 'Accept': 'application/vnd.vidibus.v2.html+json',
  51. 'Referer': url,
  52. })
  53. data = self._download_json(req, video_id)
  54. categories = list(data.get('section', {}).get('tags', {}).values())
  55. asset = data['asset']
  56. formats = []
  57. smil_url = asset['video']
  58. if '.smil' in smil_url:
  59. m3u8_url = smil_url.replace('.smil', '.m3u8')
  60. formats.extend(
  61. self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4'))
  62. smil_doc = self._download_xml(
  63. smil_url, video_id, note='Downloading SMIL metadata')
  64. base_url = smil_doc.find('./head/meta').attrib['base']
  65. formats.extend([{
  66. 'format_id': 'rmtp',
  67. 'url': base_url,
  68. 'play_path': n.attrib['src'],
  69. 'ext': 'flv',
  70. 'preference': -100,
  71. 'format_note': 'Seems to fail at example stream',
  72. } for n in smil_doc.findall('./body/video')])
  73. else:
  74. formats.append({'url': smil_url})
  75. self._sort_formats(formats)
  76. return {
  77. 'id': video_id,
  78. 'formats': formats,
  79. 'title': asset['title'],
  80. 'thumbnail': asset.get('image'),
  81. 'description': asset.get('teaser'),
  82. 'categories': categories,
  83. 'view_count': asset.get('views'),
  84. 'rtmp_live': asset.get('live'),
  85. 'timestamp': parse_iso8601(asset.get('date')),
  86. }