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.

147 lines
4.9 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_parse_urlencode,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. sanitized_Request,
  12. unified_strdate,
  13. urlencode_postdata,
  14. xpath_element,
  15. xpath_text,
  16. )
  17. class Laola1TvIE(InfoExtractor):
  18. _VALID_URL = r'https?://(?:www\.)?laola1\.tv/(?P<lang>[a-z]+)-(?P<portal>[a-z]+)/(?P<kind>[^/]+)/(?P<slug>[^/?#&]+)'
  19. _TESTS = [{
  20. 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie/227883.html',
  21. 'info_dict': {
  22. 'id': '227883',
  23. 'display_id': 'straubing-tigers-koelner-haie',
  24. 'ext': 'flv',
  25. 'title': 'Straubing Tigers - Kölner Haie',
  26. 'upload_date': '20140912',
  27. 'is_live': False,
  28. 'categories': ['Eishockey'],
  29. },
  30. 'params': {
  31. 'skip_download': True,
  32. },
  33. }, {
  34. 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie',
  35. 'info_dict': {
  36. 'id': '464602',
  37. 'display_id': 'straubing-tigers-koelner-haie',
  38. 'ext': 'flv',
  39. 'title': 'Straubing Tigers - Kölner Haie',
  40. 'upload_date': '20160129',
  41. 'is_live': False,
  42. 'categories': ['Eishockey'],
  43. },
  44. 'params': {
  45. 'skip_download': True,
  46. },
  47. }, {
  48. 'url': 'http://www.laola1.tv/de-de/livestream/2016-03-22-belogorie-belgorod-trentino-diatec-lde',
  49. 'info_dict': {
  50. 'id': '487850',
  51. 'display_id': '2016-03-22-belogorie-belgorod-trentino-diatec-lde',
  52. 'ext': 'flv',
  53. 'title': 'Belogorie BELGOROD - TRENTINO Diatec',
  54. 'upload_date': '20160322',
  55. 'uploader': 'CEV - Europäischer Volleyball Verband',
  56. 'is_live': True,
  57. 'categories': ['Volleyball'],
  58. },
  59. 'params': {
  60. 'skip_download': True,
  61. },
  62. }]
  63. def _real_extract(self, url):
  64. mobj = re.match(self._VALID_URL, url)
  65. display_id = mobj.group('slug')
  66. kind = mobj.group('kind')
  67. lang = mobj.group('lang')
  68. portal = mobj.group('portal')
  69. webpage = self._download_webpage(url, display_id)
  70. iframe_url = self._search_regex(
  71. r'<iframe[^>]*?id="videoplayer"[^>]*?src="([^"]+)"',
  72. webpage, 'iframe url')
  73. video_id = self._search_regex(
  74. r'videoid=(\d+)', iframe_url, 'video id')
  75. iframe = self._download_webpage(compat_urlparse.urljoin(
  76. url, iframe_url), display_id, 'Downloading iframe')
  77. partner_id = self._search_regex(
  78. r'partnerid\s*:\s*(["\'])(?P<partner_id>.+?)\1',
  79. iframe, 'partner id', group='partner_id')
  80. hd_doc = self._download_xml(
  81. 'http://www.laola1.tv/server/hd_video.php?%s'
  82. % compat_urllib_parse_urlencode({
  83. 'play': video_id,
  84. 'partner': partner_id,
  85. 'portal': portal,
  86. 'lang': lang,
  87. 'v5ident': '',
  88. }), display_id)
  89. _v = lambda x, **k: xpath_text(hd_doc, './/video/' + x, **k)
  90. title = _v('title', fatal=True)
  91. VS_TARGETS = {
  92. 'video': '2',
  93. 'livestream': '17',
  94. }
  95. req = sanitized_Request(
  96. 'https://club.laola1.tv/sp/laola1/api/v3/user/session/premium/player/stream-access?%s' %
  97. compat_urllib_parse_urlencode({
  98. 'videoId': video_id,
  99. 'target': VS_TARGETS.get(kind, '2'),
  100. 'label': _v('label'),
  101. 'area': _v('area'),
  102. }),
  103. urlencode_postdata(
  104. dict((i, v) for i, v in enumerate(_v('req_liga_abos').split(',')))))
  105. token_url = self._download_json(req, display_id)['data']['stream-access'][0]
  106. token_doc = self._download_xml(token_url, display_id, 'Downloading token')
  107. token_attrib = xpath_element(token_doc, './/token').attrib
  108. token_auth = token_attrib['auth']
  109. if token_auth in ('blocked', 'restricted', 'error'):
  110. raise ExtractorError(
  111. 'Token error: %s' % token_attrib['comment'], expected=True)
  112. formats = self._extract_f4m_formats(
  113. '%s?hdnea=%s&hdcore=3.2.0' % (token_attrib['url'], token_auth),
  114. video_id, f4m_id='hds')
  115. self._sort_formats(formats)
  116. categories_str = _v('meta_sports')
  117. categories = categories_str.split(',') if categories_str else []
  118. return {
  119. 'id': video_id,
  120. 'display_id': display_id,
  121. 'title': title,
  122. 'upload_date': unified_strdate(_v('time_date')),
  123. 'uploader': _v('meta_organisation'),
  124. 'categories': categories,
  125. 'is_live': _v('islive') == 'true',
  126. 'formats': formats,
  127. }