<s> """<STR_LIT>""" <EOL> import re <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 HDSStream , RTMPStream <EOL> ASSET_URL = "<STR_LIT>" <EOL> SWF_URL = "<STR_LIT>" <EOL> _url_re = re . compile ( """<STR_LIT>""" , re . VERBOSE ) <EOL> _asset_schema = validate . Schema ( <EOL> validate . xml_findall ( "<STR_LIT>" ) , <EOL> [ <EOL> validate . all ( <EOL> validate . xml_findall ( "<STR_LIT:*>" ) , <EOL> validate . map ( lambda e : ( e . tag , e . text ) ) , <EOL> validate . transform ( dict ) , <EOL> { <EOL> "<STR_LIT>" : validate . text , <EOL> "<STR_LIT>" : validate . all ( <EOL> validate . text , validate . transform ( int ) <EOL> ) , <EOL> "<STR_LIT:url>" : validate . text <EOL> } <EOL> ) <EOL> ] <EOL> ) <EOL> class TV4Play ( Plugin ) : <EOL> @ classmethod <EOL> def can_handle_url ( cls , url ) : <EOL> return _url_re . match ( url ) <EOL> def _get_streams ( self ) : <EOL> match = _url_re . match ( self . url ) <EOL> video_id = match . group ( "<STR_LIT>" ) <EOL> res = http . get ( ASSET_URL . format ( video_id ) ) <EOL> assets = http . xml ( res , schema = _asset_schema ) <EOL> streams = { } <EOL> for asset in assets : <EOL> base = asset [ "<STR_LIT>" ] <EOL> url = asset [ "<STR_LIT:url>" ] <EOL> if urlparse ( url ) . path . endswith ( "<STR_LIT>" ) : <EOL> streams . update ( <EOL> HDSStream . parse_manifest ( self . session , url , pvswf = SWF_URL ) <EOL> ) <EOL> elif base . startswith ( "<STR_LIT>" ) : <EOL> name = "<STR_LIT>" . format ( asset [ "<STR_LIT>" ] ) <EOL> params = { <EOL> "<STR_LIT>" : asset [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : url , <EOL> "<STR_LIT>" : True <EOL> } <EOL> streams [ name ] = RTMPStream ( self . session , params ) <EOL> return streams <EOL> __plugin__ = TV4Play </s>
