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.6 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. 'duration': 2732,
  38. 'title': 'Li-Ning Badminton Weltmeisterschaft 2014 Kopenhagen: Herren Einzel, Wei Lee vs. Keun Lee',
  39. 'thumbnail': 're:^https?://.*\.jpg$',
  40. 'view_count': int,
  41. 'categories': ['Li-Ning Badminton WM 2014'],
  42. }
  43. }]
  44. def _real_extract(self, url):
  45. mobj = re.match(self._VALID_URL, url)
  46. video_id = mobj.group('id')
  47. sport_id = mobj.group('sport')
  48. api_url = 'http://proxy.vidibusdynamic.net/sportdeutschland.tv/api/permalinks/%s/%s?access_token=true' % (
  49. sport_id, video_id)
  50. req = compat_urllib_request.Request(api_url, headers={
  51. 'Accept': 'application/vnd.vidibus.v2.html+json',
  52. 'Referer': url,
  53. })
  54. data = self._download_json(req, video_id)
  55. asset = data['asset']
  56. categories = [data['section']['title']]
  57. formats = []
  58. smil_url = asset['video']
  59. if '.smil' in smil_url:
  60. m3u8_url = smil_url.replace('.smil', '.m3u8')
  61. formats.extend(
  62. self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4'))
  63. smil_doc = self._download_xml(
  64. smil_url, video_id, note='Downloading SMIL metadata')
  65. base_url = smil_doc.find('./head/meta').attrib['base']
  66. formats.extend([{
  67. 'format_id': 'rmtp',
  68. 'url': base_url,
  69. 'play_path': n.attrib['src'],
  70. 'ext': 'flv',
  71. 'preference': -100,
  72. 'format_note': 'Seems to fail at example stream',
  73. } for n in smil_doc.findall('./body/video')])
  74. else:
  75. formats.append({'url': smil_url})
  76. self._sort_formats(formats)
  77. return {
  78. 'id': video_id,
  79. 'formats': formats,
  80. 'title': asset['title'],
  81. 'thumbnail': asset.get('image'),
  82. 'description': asset.get('teaser'),
  83. 'duration': asset.get('duration'),
  84. 'categories': categories,
  85. 'view_count': asset.get('views'),
  86. 'rtmp_live': asset.get('live'),
  87. 'timestamp': parse_iso8601(asset.get('date')),
  88. }