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.

217 lines
7.7 KiB

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