logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

laola1tv.py (9454B)


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