<s> """<STR_LIT>""" <EOL> import re <EOL> from itertools import chain <EOL> from livestreamer . compat import urlparse <EOL> from livestreamer . plugin import Plugin <EOL> from livestreamer . plugin . api import http , validate <EOL> from livestreamer . stream import HLSStream , HTTPStream , RTMPStream <EOL> SWF_URL = "<STR_LIT>" <EOL> _url_re = re . compile ( "<STR_LIT>" ) <EOL> _json_re = re . compile ( "<STR_LIT>" ) <EOL> _schema = validate . Schema ( <EOL> validate . transform ( _json_re . search ) , <EOL> validate . any ( <EOL> None , <EOL> validate . all ( <EOL> validate . get ( <NUM_LIT:2> ) , <EOL> validate . url ( scheme = "<STR_LIT:http>" ) <EOL> ) <EOL> ) <EOL> ) <EOL> _video_schema = validate . Schema ( { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : validate . any ( <EOL> [ ] , <EOL> { <EOL> validate . text : { <EOL> "<STR_LIT>" : int , <EOL> "<STR_LIT>" : validate . text , <EOL> "<STR_LIT:url>" : validate . text , <EOL> validate . optional ( "<STR_LIT>" ) : validate . text <EOL> } , <EOL> } , <EOL> ) , <EOL> "<STR_LIT>" : validate . text <EOL> } <EOL> } ) <EOL> class ArteTV ( Plugin ) : <EOL> @ classmethod <EOL> def can_handle_url ( self , url ) : <EOL> return _url_re . match ( url ) <EOL> def _create_stream ( self , stream , is_live ) : <EOL> stream_name = "<STR_LIT>" . format ( stream [ "<STR_LIT>" ] ) <EOL> stream_type = stream [ "<STR_LIT>" ] <EOL> stream_url = stream [ "<STR_LIT:url>" ] <EOL> if stream_type in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if urlparse ( stream_url ) . path . endswith ( "<STR_LIT>" ) : <EOL> try : <EOL> streams = HLSStream . parse_variant_playlist ( self . session , stream_url ) <EOL> for stream in streams . items ( ) : <EOL> yield stream <EOL> except IOError as err : <EOL> self . logger . error ( "<STR_LIT>" , err ) <EOL> else : <EOL> yield stream_name , HTTPStream ( self . session , stream_url ) <EOL> elif stream_type == "<STR_LIT>" : <EOL> params = { <EOL> "<STR_LIT>" : stream [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : stream [ "<STR_LIT:url>" ] , <EOL> "<STR_LIT>" : SWF_URL , <EOL> "<STR_LIT>" : self . url , <EOL> } <EOL> if is_live : <EOL> params [ "<STR_LIT>" ] = True <EOL> else : <EOL> params [ "<STR_LIT>" ] = "<STR_LIT>" . format ( params [ "<STR_LIT>" ] ) <EOL> stream = RTMPStream ( self . session , params ) <EOL> yield stream_name , stream <EOL> def _get_streams ( self ) : <EOL> json_url = http . get ( self . url , schema = _schema ) <EOL> if not json_url : <EOL> return <EOL> res = http . get ( json_url ) <EOL> video = http . json ( res , schema = _video_schema ) <EOL> if not video [ "<STR_LIT>" ] [ "<STR_LIT>" ] : <EOL> return <EOL> is_live = video [ "<STR_LIT>" ] [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> vsr = video [ "<STR_LIT>" ] [ "<STR_LIT>" ] . values ( ) <EOL> streams = ( self . _create_stream ( stream , is_live ) for stream in vsr ) <EOL> return chain . from_iterable ( streams ) <EOL> __plugin__ = ArteTV </s>
