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.

125 lines
4.1 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,
  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<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. def _real_extract(self, url):
  49. mobj = re.match(self._VALID_URL, url)
  50. display_id = mobj.group('slug')
  51. lang = mobj.group('lang')
  52. portal = mobj.group('portal')
  53. webpage = self._download_webpage(url, display_id)
  54. iframe_url = self._search_regex(
  55. r'<iframe[^>]*?id="videoplayer"[^>]*?src="([^"]+)"',
  56. webpage, 'iframe url')
  57. video_id = self._search_regex(
  58. r'videoid=(\d+)', iframe_url, 'video id')
  59. iframe = self._download_webpage(compat_urlparse.urljoin(
  60. url, iframe_url), display_id, 'Downloading iframe')
  61. partner_id = self._search_regex(
  62. r'partnerid\s*:\s*(["\'])(?P<partner_id>.+?)\1',
  63. iframe, 'partner id', group='partner_id')
  64. hd_doc = self._download_xml(
  65. 'http://www.laola1.tv/server/hd_video.php?%s'
  66. % compat_urllib_parse.urlencode({
  67. 'play': video_id,
  68. 'partner': partner_id,
  69. 'portal': portal,
  70. 'lang': lang,
  71. 'v5ident': '',
  72. }), display_id)
  73. _v = lambda x, **k: xpath_text(hd_doc, './/video/' + x, **k)
  74. title = _v('title', fatal=True)
  75. req = sanitized_Request(
  76. 'https://club.laola1.tv/sp/laola1/api/v3/user/session/premium/player/stream-access?%s' %
  77. compat_urllib_parse.urlencode({
  78. 'videoId': video_id,
  79. 'target': '2',
  80. 'label': 'laola1tv',
  81. 'area': _v('area'),
  82. }),
  83. urlencode_postdata(
  84. dict((i, v) for i, v in enumerate(_v('req_liga_abos').split(',')))))
  85. token_url = self._download_json(req, display_id)['data']['stream-access'][0]
  86. token_doc = self._download_xml(token_url, display_id, 'Downloading token')
  87. token_attrib = xpath_element(token_doc, './/token').attrib
  88. token_auth = token_attrib['auth']
  89. if token_auth in ('blocked', 'restricted', 'error'):
  90. raise ExtractorError(
  91. 'Token error: %s' % token_attrib['comment'], expected=True)
  92. formats = self._extract_f4m_formats(
  93. '%s?hdnea=%s&hdcore=3.2.0' % (token_attrib['url'], token_auth),
  94. video_id, f4m_id='hds')
  95. categories_str = _v('meta_sports')
  96. categories = categories_str.split(',') if categories_str else []
  97. return {
  98. 'id': video_id,
  99. 'display_id': display_id,
  100. 'title': title,
  101. 'upload_date': unified_strdate(_v('time_date')),
  102. 'uploader': _v('meta_organisation'),
  103. 'categories': categories,
  104. 'is_live': _v('islive') == 'true',
  105. 'formats': formats,
  106. }