]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/laola1tv.py
c7f813370162bb8582db8abd9a3f49e3e4bb1bc1
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
  18 class Laola1TvEmbedIE(InfoExtractor
): 
  19     IE_NAME 
= 'laola1tv:embed' 
  20     _VALID_URL 
= r
'https?://(?:www\.)?laola1\.tv/titanplayer\.php\?.*?\bvideoid=(?P<id>\d+)' 
  22         # flashvars.premium = "false"; 
  23         'url': 'https://www.laola1.tv/titanplayer.php?videoid=708065&type=V&lang=en&portal=int&customer=1024', 
  27             'title': 'MA Long CHN - FAN Zhendong CHN', 
  28             'uploader': 'ITTF - International Table Tennis Federation', 
  29             'upload_date': '20161211', 
  33     def _extract_token_url(self
, stream_access_url
, video_id
, data
): 
  34         return self
._download
_json
( 
  35             stream_access_url
, video_id
, headers
={ 
  36                 'Content-Type': 'application/json', 
  37             }, data
=json
.dumps(data
).encode())['data']['stream-access'][0] 
  39     def _extract_formats(self
, token_url
, video_id
): 
  40         token_doc 
= self
._download
_xml
( 
  41             token_url
, video_id
, 'Downloading token', 
  42             headers
=self
.geo_verification_headers()) 
  44         token_attrib 
= xpath_element(token_doc
, './/token').attrib
 
  46         if token_attrib
['status'] != '0': 
  48                 'Token error: %s' % token_attrib
['comment'], expected
=True) 
  50         formats 
= self
._extract
_akamai
_formats
( 
  51             '%s?hdnea=%s' % (token_attrib
['url'], token_attrib
['auth']), 
  53         self
._sort
_formats
(formats
) 
  56     def _real_extract(self
, url
): 
  57         video_id 
= self
._match
_id
(url
) 
  58         webpage 
= self
._download
_webpage
(url
, video_id
) 
  59         flash_vars 
= self
._search
_regex
( 
  60             r
'(?s)flashvars\s*=\s*({.+?});', webpage
, 'flash vars') 
  62         def get_flashvar(x
, *args
, **kwargs
): 
  63             flash_var 
= self
._search
_regex
( 
  64                 r
'%s\s*:\s*"([^"]+)"' % x
, 
  65                 flash_vars
, x
, default
=None) 
  67                 flash_var 
= self
._search
_regex
([ 
  68                     r
'flashvars\.%s\s*=\s*"([^"]+)"' % x
, 
  69                     r
'%s\s*=\s*"([^"]+)"' % x
], 
  70                     webpage
, x
, *args
, **kwargs
) 
  73         hd_doc 
= self
._download
_xml
( 
  74             'http://www.laola1.tv/server/hd_video.php', video_id
, query
={ 
  75                 'play': get_flashvar('streamid'), 
  76                 'partner': get_flashvar('partnerid'), 
  77                 'portal': get_flashvar('portalid'), 
  78                 'lang': get_flashvar('sprache'), 
  82         _v 
= lambda x
, **k
: xpath_text(hd_doc
, './/video/' + x
, **k
) 
  83         title 
= _v('title', fatal
=True) 
  86         premium 
= get_flashvar('premium', default
=None) 
  88             token_url 
= update_url_query( 
  89                 _v('url', fatal
=True), { 
  90                     'timestamp': get_flashvar('timestamp'), 
  91                     'auth': get_flashvar('auth'), 
  94             data_abo 
= urlencode_postdata( 
  95                 dict((i
, v
) for i
, v 
in enumerate(_v('req_liga_abos').split(',')))) 
  96             stream_access_url 
= update_url_query( 
  97                 'https://club.laola1.tv/sp/laola1/api/v3/user/session/premium/player/stream-access', { 
  99                     'target': self
._search
_regex
(r
'vs_target = (\d+);', webpage
, 'vs target'), 
 100                     'label': _v('label'), 
 103             token_url 
= self
._extract
_token
_url
(stream_access_url
, video_id
, data_abo
) 
 105         formats 
= self
._extract
_formats
(token_url
, video_id
) 
 107         categories_str 
= _v('meta_sports') 
 108         categories 
= categories_str
.split(',') if categories_str 
else [] 
 109         is_live 
= _v('islive') == 'true' 
 113             'title': self
._live
_title
(title
) if is_live 
else title
, 
 114             'upload_date': unified_strdate(_v('time_date')), 
 115             'uploader': _v('meta_organisation'), 
 116             'categories': categories
, 
 122 class Laola1TvIE(Laola1TvEmbedIE
): 
 124     _VALID_URL 
= r
'https?://(?:www\.)?laola1\.tv/[a-z]+-[a-z]+/[^/]+/(?P<id>[^/?#&]+)' 
 126         'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie/227883.html', 
 129             'display_id': 'straubing-tigers-koelner-haie', 
 131             'title': 'Straubing Tigers - Kölner Haie', 
 132             'upload_date': '20140912', 
 134             'categories': ['Eishockey'], 
 137             'skip_download': True, 
 140         'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie', 
 143             'display_id': 'straubing-tigers-koelner-haie', 
 145             'title': 'Straubing Tigers - Kölner Haie', 
 146             'upload_date': '20160129', 
 148             'categories': ['Eishockey'], 
 151             'skip_download': True, 
 154         'url': 'http://www.laola1.tv/de-de/livestream/2016-03-22-belogorie-belgorod-trentino-diatec-lde', 
 157             'display_id': '2016-03-22-belogorie-belgorod-trentino-diatec-lde', 
 159             'title': 'Belogorie BELGOROD - TRENTINO Diatec', 
 160             'upload_date': '20160322', 
 161             'uploader': 'CEV - Europäischer Volleyball Verband', 
 163             'categories': ['Volleyball'], 
 166             'skip_download': True, 
 168         'skip': 'This live stream has already finished.', 
 171     def _real_extract(self
, url
): 
 172         display_id 
= self
._match
_id
(url
) 
 174         webpage 
= self
._download
_webpage
(url
, display_id
) 
 176         if 'Dieser Livestream ist bereits beendet.' in webpage
: 
 177             raise ExtractorError('This live stream has already finished.', expected
=True) 
 179         conf 
= self
._parse
_json
(self
._search
_regex
( 
 180             r
'(?s)conf\s*=\s*({.+?});', webpage
, 'conf'), 
 181             display_id
, js_to_json
) 
 183         video_id 
= conf
['videoid'] 
 185         config 
= self
._download
_json
(conf
['configUrl'], video_id
, query
={ 
 187             'partnerid': conf
['partnerid'], 
 188             'language': conf
.get('language', ''), 
 189             'portal': conf
.get('portalid', ''), 
 191         error 
= config
.get('error') 
 193             raise ExtractorError('%s said: %s' % (self
.IE_NAME
, error
), expected
=True) 
 195         video_data 
= config
['video'] 
 196         title 
= video_data
['title'] 
 197         is_live 
= video_data
.get('isLivestream') and video_data
.get('isLive') 
 198         meta 
= video_data
.get('metaInformation') 
 199         sports 
= meta
.get('sports') 
 200         categories 
= sports
.split(',') if sports 
else [] 
 202         token_url 
= self
._extract
_token
_url
( 
 203             video_data
['streamAccess'], video_id
, 
 204             video_data
['abo']['required']) 
 206         formats 
= self
._extract
_formats
(token_url
, video_id
) 
 210             'display_id': display_id
, 
 211             'title': self
._live
_title
(title
) if is_live 
else title
, 
 212             'description': video_data
.get('description'), 
 213             'thumbnail': video_data
.get('image'), 
 214             'categories': categories
, 
 220 class ITTFIE(InfoExtractor
): 
 221     _VALID_URL 
= r
'https?://tv\.ittf\.com/video/[^/]+/(?P<id>\d+)' 
 223         'url': 'https://tv.ittf.com/video/peng-wang-wei-matsudaira-kenta/951802', 
 224         'only_matching': True, 
 227     def _real_extract(self
, url
): 
 228         return self
.url_result( 
 229             update_url_query('https://www.laola1.tv/titanplayer.php', { 
 230                 'videoid': self
._match
_id
(url
), 
 235             }), Laola1TvEmbedIE
.ie_key())