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.

96 lines
3.5 KiB

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