<s> from __future__ import unicode_literals <EOL> import re <EOL> import json <EOL> from . subtitles import SubtitlesInfoExtractor <EOL> from . . compat import ( <EOL> compat_str , <EOL> ) <EOL> from . . utils import ( <EOL> determine_ext , <EOL> ExtractorError , <EOL> xpath_with_ns , <EOL> ) <EOL> _x = lambda p : xpath_with_ns ( p , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> class ThePlatformIE ( SubtitlesInfoExtractor ) : <EOL> _VALID_URL = r'''<STR_LIT>''' <EOL> _TEST = { <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> } , <EOL> } <EOL> def _real_extract ( self , url ) : <EOL> mobj = re . match ( self . _VALID_URL , url ) <EOL> video_id = mobj . group ( '<STR_LIT:id>' ) <EOL> if mobj . group ( '<STR_LIT>' ) : <EOL> config_url = url + '<STR_LIT>' <EOL> config_url = config_url . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> config_url = config_url . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> config = self . _download_json ( config_url , video_id , '<STR_LIT>' ) <EOL> smil_url = config [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> else : <EOL> smil_url = ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( video_id ) ) <EOL> meta = self . _download_xml ( smil_url , video_id ) <EOL> try : <EOL> error_msg = next ( <EOL> n . attrib [ '<STR_LIT>' ] <EOL> for n in meta . findall ( _x ( '<STR_LIT>' ) ) <EOL> if n . attrib . get ( '<STR_LIT:title>' ) == '<STR_LIT>' ) <EOL> except StopIteration : <EOL> pass <EOL> else : <EOL> raise ExtractorError ( error_msg , expected = True ) <EOL> info_url = '<STR_LIT>' . format ( video_id ) <EOL> info_json = self . _download_webpage ( info_url , video_id ) <EOL> info = json . loads ( info_json ) <EOL> subtitles = { } <EOL> captions = info . get ( '<STR_LIT>' ) <EOL> if isinstance ( captions , list ) : <EOL> for caption in captions : <EOL> lang , src = caption . get ( '<STR_LIT>' ) , caption . get ( '<STR_LIT:src>' ) <EOL> if lang and src : <EOL> subtitles [ lang ] = src <EOL> if self . _downloader . params . get ( '<STR_LIT>' , False ) : <EOL> self . _list_available_subtitles ( video_id , subtitles ) <EOL> return <EOL> subtitles = self . extract_subtitles ( video_id , subtitles ) <EOL> head = meta . find ( _x ( '<STR_LIT>' ) ) <EOL> body = meta . find ( _x ( '<STR_LIT>' ) ) <EOL> f4m_node = body . find ( _x ( '<STR_LIT>' ) ) <EOL> if f4m_node is not None and '<STR_LIT>' in f4m_node . attrib [ '<STR_LIT:src>' ] : <EOL> f4m_url = f4m_node . attrib [ '<STR_LIT:src>' ] <EOL> if '<STR_LIT>' not in f4m_url : <EOL> f4m_url += '<STR_LIT:?>' <EOL> f4m_url += '<STR_LIT>' <EOL> formats = self . _extract_f4m_formats ( f4m_url , video_id ) <EOL> else : <EOL> formats = [ ] <EOL> switch = body . find ( _x ( '<STR_LIT>' ) ) <EOL> if switch is not None : <EOL> base_url = head . find ( _x ( '<STR_LIT>' ) ) . attrib [ '<STR_LIT>' ] <EOL> for f in switch . findall ( _x ( '<STR_LIT>' ) ) : <EOL> attr = f . attrib <EOL> width = int ( attr [ '<STR_LIT:width>' ] ) <EOL> height = int ( attr [ '<STR_LIT>' ] ) <EOL> vbr = int ( attr [ '<STR_LIT>' ] ) // <NUM_LIT:1000> <EOL> format_id = '<STR_LIT>' % ( width , height , vbr ) <EOL> formats . append ( { <EOL> '<STR_LIT>' : format_id , <EOL> '<STR_LIT:url>' : base_url , <EOL> '<STR_LIT>' : '<STR_LIT>' + attr [ '<STR_LIT:src>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:width>' : width , <EOL> '<STR_LIT>' : height , <EOL> '<STR_LIT>' : vbr , <EOL> } ) <EOL> else : <EOL> switch = body . find ( _x ( '<STR_LIT>' ) ) <EOL> for f in switch . findall ( _x ( '<STR_LIT>' ) ) : <EOL> attr = f . attrib <EOL> vbr = int ( attr [ '<STR_LIT>' ] ) // <NUM_LIT:1000> <EOL> ext = determine_ext ( attr [ '<STR_LIT:src>' ] ) <EOL> if ext == '<STR_LIT>' : <EOL> ext = '<STR_LIT>' <EOL> formats . append ( { <EOL> '<STR_LIT>' : compat_str ( vbr ) , <EOL> '<STR_LIT:url>' : attr [ '<STR_LIT:src>' ] , <EOL> '<STR_LIT>' : vbr , <EOL> '<STR_LIT>' : ext , <EOL> } ) <EOL> self . _sort_formats ( formats ) <EOL> return { <EOL> '<STR_LIT:id>' : video_id , <EOL> '<STR_LIT:title>' : info [ '<STR_LIT:title>' ] , <EOL> '<STR_LIT>' : subtitles , <EOL> '<STR_LIT>' : formats , <EOL> '<STR_LIT:description>' : info [ '<STR_LIT:description>' ] , <EOL> '<STR_LIT>' : info [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : info [ '<STR_LIT>' ] // <NUM_LIT:1000> , <EOL> } </s>
