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.

113 lines
3.8 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_urlparse,
  7. ExtractorError,
  8. sanitized_Request,
  9. xpath_element,
  10. xpath_text,
  11. unified_strdate,
  12. urlencode_postdata,
  13. )
  14. class Laola1TvIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:www\.)?laola1\.tv/(?P<lang>[a-z]+)-(?P<portal>[a-z]+)/.*?/(?P<slug>[\w-]+)'
  16. _TESTS = [{
  17. 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie/227883.html',
  18. 'info_dict': {
  19. 'categories': ['Eishockey'],
  20. 'ext': 'flv',
  21. 'id': '227883',
  22. 'is_live': False,
  23. 'title': 'Straubing Tigers - Kölner Haie',
  24. 'upload_date': '20140912',
  25. },
  26. 'params': {
  27. 'skip_download': True,
  28. }
  29. }, {
  30. 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie',
  31. 'info_dict': {
  32. 'categories': ['Eishockey'],
  33. 'ext': 'flv',
  34. 'id': '464602',
  35. 'is_live': False,
  36. 'title': 'Straubing Tigers - Kölner Haie',
  37. 'upload_date': '20160129',
  38. },
  39. 'params': {
  40. 'skip_download': True,
  41. }
  42. }]
  43. def _real_extract(self, url):
  44. mobj = re.match(self._VALID_URL, url)
  45. lang = mobj.group('lang')
  46. portal = mobj.group('portal')
  47. webpage = self._download_webpage(url, mobj.group('slug'))
  48. iframe_url = self._search_regex(
  49. r'<iframe[^>]*?id="videoplayer"[^>]*?src="([^"]+)"',
  50. webpage, 'iframe URL')
  51. video_id = self._search_regex(
  52. r'videoid=(\d+)', iframe_url, 'video ID')
  53. iframe = self._download_webpage(compat_urlparse.urljoin(
  54. url, iframe_url), video_id, note='Downloading iframe')
  55. partner_id = self._search_regex(
  56. r'partnerid\s*:\s*"([^"]+)"', iframe, 'partner ID')
  57. xml_url = ('http://www.laola1.tv/server/hd_video.php?' +
  58. 'play=%s&partner=%s&portal=%s&v5ident=&lang=%s' % (
  59. video_id, partner_id, portal, lang))
  60. hd_doc = self._download_xml(xml_url, video_id)
  61. _v = lambda x, **k: xpath_text(hd_doc, './/video/' + x, **k)
  62. title = _v('title', fatal=True)
  63. categories = _v('meta_sports')
  64. if categories:
  65. categories = categories.split(',')
  66. time_date = _v('time_date')
  67. time_start = _v('time_start')
  68. upload_date = None
  69. if time_date and time_start:
  70. upload_date = unified_strdate(time_date + ' ' + time_start)
  71. json_url = ('https://club.laola1.tv/sp/laola1/api/v3/user/session' +
  72. '/premium/player/stream-access?videoId=%s&target=2' +
  73. '&label=laola1tv&area=%s') % (video_id, _v('area'))
  74. req = sanitized_Request(json_url, urlencode_postdata(
  75. dict((i, v) for i, v in enumerate(_v('req_liga_abos').split(',')))))
  76. token_url = self._download_json(req, video_id)['data']['stream-access'][0]
  77. token_doc = self._download_xml(
  78. token_url, video_id, note='Downloading token')
  79. token_attrib = xpath_element(token_doc, './/token').attrib
  80. token_auth = token_attrib['auth']
  81. if token_auth in ('blocked', 'restricted'):
  82. raise ExtractorError(
  83. 'Token error: %s' % token_attrib['comment'], expected=True)
  84. video_url = '%s?hdnea=%s&hdcore=3.2.0' % (token_attrib['url'], token_auth)
  85. return {
  86. 'categories': categories,
  87. 'formats': self._extract_f4m_formats(
  88. video_url, video_id, f4m_id='hds'),
  89. 'id': video_id,
  90. 'is_live': _v('islive') == 'true',
  91. 'title': title,
  92. 'upload_date': upload_date,
  93. 'uploader': _v('meta_organisation'),
  94. }