<s> import re <EOL> from livestreamer . plugin import Plugin <EOL> from livestreamer . plugin . api import http , validate <EOL> from livestreamer . stream import RTMPStream <EOL> _url_re = re . compile ( "<STR_LIT>" ) <EOL> CHANNEL_INFO = "<STR_LIT>" <EOL> CHANNEL_MANIFEST = "<STR_LIT>" <EOL> _assets_schema = validate . Schema ( <EOL> validate . union ( { <EOL> "<STR_LIT>" : validate . all ( <EOL> validate . xml_find ( "<STR_LIT>" ) , <EOL> validate . get ( "<STR_LIT>" ) , <EOL> validate . url ( scheme = "<STR_LIT>" ) <EOL> ) , <EOL> "<STR_LIT>" : validate . all ( <EOL> validate . xml_findall ( "<STR_LIT>" ) , <EOL> [ <EOL> validate . union ( { <EOL> "<STR_LIT:src>" : validate . all ( <EOL> validate . get ( "<STR_LIT:src>" ) , <EOL> validate . text <EOL> ) , <EOL> "<STR_LIT>" : validate . all ( <EOL> validate . get ( "<STR_LIT>" ) , <EOL> validate . text , <EOL> validate . transform ( int ) <EOL> ) <EOL> } ) <EOL> ] <EOL> ) <EOL> } ) <EOL> ) <EOL> class Beam ( Plugin ) : <EOL> @ classmethod <EOL> def can_handle_url ( self , url ) : <EOL> return _url_re . match ( url ) <EOL> def _get_streams ( self ) : <EOL> match = _url_re . match ( self . url ) <EOL> channel = match . group ( "<STR_LIT>" ) <EOL> res = http . get ( CHANNEL_INFO . format ( channel ) ) <EOL> channel_info = http . json ( res ) <EOL> if not channel_info [ "<STR_LIT>" ] : <EOL> return <EOL> res = http . get ( CHANNEL_MANIFEST . format ( channel_info [ "<STR_LIT:id>" ] ) ) <EOL> assets = http . xml ( res , schema = _assets_schema ) <EOL> streams = { } <EOL> for video in assets [ "<STR_LIT>" ] : <EOL> name = "<STR_LIT>" . format ( video [ "<STR_LIT>" ] ) <EOL> stream = RTMPStream ( self . session , { <EOL> "<STR_LIT>" : "<STR_LIT>" . format ( assets [ "<STR_LIT>" ] , video [ "<STR_LIT:src>" ] ) <EOL> } ) <EOL> streams [ name ] = stream <EOL> return streams <EOL> __plugin__ = Beam </s>
