<s> import re <EOL> from livestreamer . plugin import Plugin <EOL> from livestreamer . plugin . api import http <EOL> from livestreamer . stream import HLSStream <EOL> from livestreamer . plugin . api import validate <EOL> STREAM_INFO_URL = "<STR_LIT>" <EOL> _url_re = re . compile ( r"<STR_LIT>" ) <EOL> _media_schema = validate . Schema ( { <EOL> "<STR_LIT>" : validate . text , <EOL> "<STR_LIT:url>" : validate . url ( scheme = validate . any ( "<STR_LIT:http>" ) ) <EOL> } ) <EOL> _channel_schema = validate . Schema ( { <EOL> "<STR_LIT>" : validate . any ( [ _media_schema ] , _media_schema ) <EOL> } ) <EOL> class TV3Cat ( Plugin ) : <EOL> @ classmethod <EOL> def can_handle_url ( self , url ) : <EOL> match = _url_re . match ( url ) <EOL> return match <EOL> def _get_streams ( self ) : <EOL> match = _url_re . match ( self . url ) <EOL> if match : <EOL> ident = match . group ( <NUM_LIT:1> ) <EOL> data_url = STREAM_INFO_URL . format ( ident = ident ) <EOL> res = http . get ( self . url ) <EOL> geo_data = re . search ( r'<STR_LIT>' , res . text ) <EOL> geo = geo_data and geo_data . group ( <NUM_LIT:1> ) or "<STR_LIT>" <EOL> stream_data = http . json ( http . get ( data_url ) , schema = _channel_schema ) <EOL> if isinstance ( stream_data [ '<STR_LIT>' ] , list ) : <EOL> stream_infos = stream_data [ '<STR_LIT>' ] <EOL> else : <EOL> stream_infos = [ stream_data [ '<STR_LIT>' ] ] <EOL> for stream in stream_infos : <EOL> if stream [ '<STR_LIT>' ] == geo : <EOL> return HLSStream . parse_variant_playlist ( self . session , stream [ '<STR_LIT:url>' ] ) <EOL> __plugin__ = TV3Cat </s>
