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.

176 lines
6.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. unified_strdate,
  7. urlencode_postdata,
  8. xpath_element,
  9. xpath_text,
  10. urljoin,
  11. update_url_query,
  12. )
  13. class Laola1TvEmbedIE(InfoExtractor):
  14. IE_NAME = 'laola1tv:embed'
  15. _VALID_URL = r'https?://(?:www\.)?laola1\.tv/titanplayer\.php\?.*?\bvideoid=(?P<id>\d+)'
  16. _TEST = {
  17. # flashvars.premium = "false";
  18. 'url': 'https://www.laola1.tv/titanplayer.php?videoid=708065&type=V&lang=en&portal=int&customer=1024',
  19. 'info_dict': {
  20. 'id': '708065',
  21. 'ext': 'mp4',
  22. 'title': 'MA Long CHN - FAN Zhendong CHN',
  23. 'uploader': 'ITTF - International Table Tennis Federation',
  24. 'upload_date': '20161211',
  25. },
  26. }
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. webpage = self._download_webpage(url, video_id)
  30. flash_vars = self._search_regex(
  31. r'(?s)flashvars\s*=\s*({.+?});', webpage, 'flash vars')
  32. def get_flashvar(x, *args, **kwargs):
  33. flash_var = self._search_regex(
  34. r'%s\s*:\s*"([^"]+)"' % x,
  35. flash_vars, x, default=None)
  36. if not flash_var:
  37. flash_var = self._search_regex([
  38. r'flashvars\.%s\s*=\s*"([^"]+)"' % x,
  39. r'%s\s*=\s*"([^"]+)"' % x],
  40. webpage, x, *args, **kwargs)
  41. return flash_var
  42. hd_doc = self._download_xml(
  43. 'http://www.laola1.tv/server/hd_video.php', video_id, query={
  44. 'play': get_flashvar('streamid'),
  45. 'partner': get_flashvar('partnerid'),
  46. 'portal': get_flashvar('portalid'),
  47. 'lang': get_flashvar('sprache'),
  48. 'v5ident': '',
  49. })
  50. _v = lambda x, **k: xpath_text(hd_doc, './/video/' + x, **k)
  51. title = _v('title', fatal=True)
  52. token_url = None
  53. premium = get_flashvar('premium', default=None)
  54. if premium:
  55. token_url = update_url_query(
  56. _v('url', fatal=True), {
  57. 'timestamp': get_flashvar('timestamp'),
  58. 'auth': get_flashvar('auth'),
  59. })
  60. else:
  61. data_abo = urlencode_postdata(
  62. dict((i, v) for i, v in enumerate(_v('req_liga_abos').split(','))))
  63. token_url = self._download_json(
  64. 'https://club.laola1.tv/sp/laola1/api/v3/user/session/premium/player/stream-access',
  65. video_id, query={
  66. 'videoId': _v('id'),
  67. 'target': self._search_regex(r'vs_target = (\d+);', webpage, 'vs target'),
  68. 'label': _v('label'),
  69. 'area': _v('area'),
  70. }, data=data_abo)['data']['stream-access'][0]
  71. token_doc = self._download_xml(
  72. token_url, video_id, 'Downloading token',
  73. headers=self.geo_verification_headers())
  74. token_attrib = xpath_element(token_doc, './/token').attrib
  75. if token_attrib['status'] != '0':
  76. raise ExtractorError(
  77. 'Token error: %s' % token_attrib['comment'], expected=True)
  78. formats = self._extract_akamai_formats(
  79. '%s?hdnea=%s' % (token_attrib['url'], token_attrib['auth']),
  80. video_id)
  81. self._sort_formats(formats)
  82. categories_str = _v('meta_sports')
  83. categories = categories_str.split(',') if categories_str else []
  84. is_live = _v('islive') == 'true'
  85. return {
  86. 'id': video_id,
  87. 'title': self._live_title(title) if is_live else title,
  88. 'upload_date': unified_strdate(_v('time_date')),
  89. 'uploader': _v('meta_organisation'),
  90. 'categories': categories,
  91. 'is_live': is_live,
  92. 'formats': formats,
  93. }
  94. class Laola1TvIE(InfoExtractor):
  95. IE_NAME = 'laola1tv'
  96. _VALID_URL = r'https?://(?:www\.)?laola1\.tv/[a-z]+-[a-z]+/[^/]+/(?P<id>[^/?#&]+)'
  97. _TESTS = [{
  98. 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie/227883.html',
  99. 'info_dict': {
  100. 'id': '227883',
  101. 'display_id': 'straubing-tigers-koelner-haie',
  102. 'ext': 'flv',
  103. 'title': 'Straubing Tigers - Kölner Haie',
  104. 'upload_date': '20140912',
  105. 'is_live': False,
  106. 'categories': ['Eishockey'],
  107. },
  108. 'params': {
  109. 'skip_download': True,
  110. },
  111. }, {
  112. 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie',
  113. 'info_dict': {
  114. 'id': '464602',
  115. 'display_id': 'straubing-tigers-koelner-haie',
  116. 'ext': 'flv',
  117. 'title': 'Straubing Tigers - Kölner Haie',
  118. 'upload_date': '20160129',
  119. 'is_live': False,
  120. 'categories': ['Eishockey'],
  121. },
  122. 'params': {
  123. 'skip_download': True,
  124. },
  125. }, {
  126. 'url': 'http://www.laola1.tv/de-de/livestream/2016-03-22-belogorie-belgorod-trentino-diatec-lde',
  127. 'info_dict': {
  128. 'id': '487850',
  129. 'display_id': '2016-03-22-belogorie-belgorod-trentino-diatec-lde',
  130. 'ext': 'flv',
  131. 'title': 'Belogorie BELGOROD - TRENTINO Diatec',
  132. 'upload_date': '20160322',
  133. 'uploader': 'CEV - Europäischer Volleyball Verband',
  134. 'is_live': True,
  135. 'categories': ['Volleyball'],
  136. },
  137. 'params': {
  138. 'skip_download': True,
  139. },
  140. 'skip': 'This live stream has already finished.',
  141. }]
  142. def _real_extract(self, url):
  143. display_id = self._match_id(url)
  144. webpage = self._download_webpage(url, display_id)
  145. if 'Dieser Livestream ist bereits beendet.' in webpage:
  146. raise ExtractorError('This live stream has already finished.', expected=True)
  147. iframe_url = urljoin(url, self._search_regex(
  148. r'<iframe[^>]*?id="videoplayer"[^>]*?src="([^"]+)"',
  149. webpage, 'iframe url'))
  150. return {
  151. '_type': 'url',
  152. 'display_id': display_id,
  153. 'url': iframe_url,
  154. 'ie_key': 'Laola1TvEmbed',
  155. }