<s> 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 . plugin . api . utils import parse_json , parse_query <EOL> from livestreamer . stream import RTMPStream , HTTPStream <EOL> SWF_LIVE_URL = "<STR_LIT>" <EOL> SWF_VIDEO_URL = "<STR_LIT>" <EOL> _url_re = re . compile ( "<STR_LIT>" ) <EOL> _live_export_re = re . compile ( <EOL> "<STR_LIT>" <EOL> ) <EOL> _live_json_re = re . compile ( "<STR_LIT>" ) <EOL> _replay_json_re = re . compile ( "<STR_LIT>" ) <EOL> _history_re = re . compile ( <EOL> "<STR_LIT>" <EOL> ) <EOL> _video_flashvars_re = re . compile ( <EOL> "<STR_LIT>" <EOL> ) <EOL> _live_schema = validate . Schema ( { <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:name>" : validate . text , <EOL> "<STR_LIT>" : validate . text , <EOL> "<STR_LIT:url>" : validate . url ( scheme = "<STR_LIT>" ) <EOL> } ] <EOL> } ) <EOL> _schema = validate . Schema ( <EOL> validate . union ( { <EOL> "<STR_LIT>" : validate . all ( <EOL> validate . transform ( _live_export_re . search ) , <EOL> validate . any ( <EOL> None , <EOL> validate . get ( <NUM_LIT:1> ) , <EOL> ) <EOL> ) , <EOL> "<STR_LIT>" : validate . all ( <EOL> validate . transform ( _video_flashvars_re . search ) , <EOL> validate . any ( <EOL> None , <EOL> validate . all ( <EOL> validate . get ( <NUM_LIT:1> ) , <EOL> validate . transform ( parse_query ) , <EOL> { <EOL> "<STR_LIT>" : validate . url ( scheme = "<STR_LIT>" ) , <EOL> "<STR_LIT>" : validate . text <EOL> } <EOL> ) <EOL> ) <EOL> ) , <EOL> "<STR_LIT>" : validate . all ( <EOL> validate . transform ( _history_re . search ) , <EOL> validate . any ( <EOL> None , <EOL> validate . all ( <EOL> validate . get ( <NUM_LIT:1> ) , <EOL> validate . url ( scheme = "<STR_LIT:http>" ) <EOL> ) <EOL> ) <EOL> ) , <EOL> "<STR_LIT>" : validate . all ( <EOL> validate . transform ( _replay_json_re . search ) , <EOL> validate . any ( <EOL> None , <EOL> validate . all ( <EOL> validate . get ( <NUM_LIT:1> ) , <EOL> validate . transform ( parse_json ) , <EOL> [ { <EOL> "<STR_LIT>" : validate . url ( scheme = "<STR_LIT:http>" ) <EOL> } ] <EOL> ) <EOL> ) <EOL> ) <EOL> } ) <EOL> ) <EOL> class Filmon_us ( Plugin ) : <EOL> @ classmethod <EOL> def can_handle_url ( self , url ) : <EOL> return _url_re . match ( url ) <EOL> def _get_live_stream ( self , export_url ) : <EOL> res = http . get ( export_url ) <EOL> match = _live_json_re . search ( res . text ) <EOL> if not match : <EOL> return <EOL> json = parse_json ( match . group ( <NUM_LIT:1> ) , schema = _live_schema ) <EOL> streams = { } <EOL> for stream in json [ "<STR_LIT>" ] : <EOL> stream_name = stream [ "<STR_LIT>" ] <EOL> parsed = urlparse ( stream [ "<STR_LIT:url>" ] ) <EOL> stream = RTMPStream ( self . session , { <EOL> "<STR_LIT>" : stream [ "<STR_LIT:url>" ] , <EOL> "<STR_LIT>" : "<STR_LIT>" . format ( parsed . path [ <NUM_LIT:1> : ] , parsed . query ) , <EOL> "<STR_LIT>" : stream [ "<STR_LIT:name>" ] , <EOL> "<STR_LIT>" : SWF_LIVE_URL , <EOL> "<STR_LIT>" : self . url , <EOL> "<STR_LIT>" : True <EOL> } ) <EOL> streams [ stream_name ] = stream <EOL> return streams <EOL> def _get_streams ( self ) : <EOL> res = http . get ( self . url , schema = _schema ) <EOL> if res [ "<STR_LIT>" ] : <EOL> return self . _get_live_stream ( res [ "<STR_LIT>" ] ) <EOL> elif res [ "<STR_LIT>" ] : <EOL> stream = RTMPStream ( self . session , { <EOL> "<STR_LIT>" : res [ "<STR_LIT>" ] [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : res [ "<STR_LIT>" ] [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : SWF_VIDEO_URL , <EOL> "<STR_LIT>" : self . url <EOL> } ) <EOL> return dict ( video = stream ) <EOL> elif res [ "<STR_LIT>" ] : <EOL> for stream in res [ "<STR_LIT>" ] : <EOL> stream = HTTPStream ( self . session , stream [ "<STR_LIT>" ] ) <EOL> return dict ( replay = stream ) <EOL> elif res [ "<STR_LIT>" ] : <EOL> stream = HTTPStream ( self . session , res [ "<STR_LIT>" ] ) <EOL> return dict ( history = stream ) <EOL> return <EOL> __plugin__ = Filmon_us </s>
