<s> import logging <EOL> from babelfish import Language <EOL> from requests import Session <EOL> from . import Provider , get_version <EOL> from . . import __version__ <EOL> from . . subtitle import Subtitle <EOL> logger = logging . getLogger ( __name__ ) <EOL> def get_subhash ( hash ) : <EOL> """<STR_LIT>""" <EOL> idx = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> mul = [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:4> , <NUM_LIT:3> ] <EOL> add = [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> b = [ ] <EOL> for i in range ( len ( idx ) ) : <EOL> a = add [ i ] <EOL> m = mul [ i ] <EOL> i = idx [ i ] <EOL> t = a + int ( hash [ i ] , <NUM_LIT:16> ) <EOL> v = int ( hash [ t : t + <NUM_LIT:2> ] , <NUM_LIT:16> ) <EOL> b . append ( ( '<STR_LIT>' % ( v * m ) ) [ - <NUM_LIT:1> ] ) <EOL> return '<STR_LIT>' . join ( b ) <EOL> class NapiProjektSubtitle ( Subtitle ) : <EOL> provider_name = '<STR_LIT>' <EOL> def __init__ ( self , language , hash ) : <EOL> super ( NapiProjektSubtitle , self ) . __init__ ( language ) <EOL> self . hash = hash <EOL> @ property <EOL> def id ( self ) : <EOL> return self . hash <EOL> def get_matches ( self , video , hearing_impaired = False ) : <EOL> matches = super ( NapiProjektSubtitle , self ) . get_matches ( video , hearing_impaired = hearing_impaired ) <EOL> if '<STR_LIT>' in video . hashes and video . hashes [ '<STR_LIT>' ] == self . hash : <EOL> matches . add ( '<STR_LIT>' ) <EOL> return matches <EOL> class NapiProjektProvider ( Provider ) : <EOL> languages = { Language . fromalpha2 ( l ) for l in [ '<STR_LIT>' ] } <EOL> required_hash = '<STR_LIT>' <EOL> server_url = '<STR_LIT>' <EOL> def initialize ( self ) : <EOL> self . session = Session ( ) <EOL> self . session . headers = { '<STR_LIT>' : '<STR_LIT>' % get_version ( __version__ ) } <EOL> def terminate ( self ) : <EOL> self . session . close ( ) <EOL> def query ( self , language , hash ) : <EOL> params = { <EOL> '<STR_LIT:v>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:false>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:l>' : language . alpha2 . upper ( ) , <EOL> '<STR_LIT:f>' : hash , <EOL> '<STR_LIT:t>' : get_subhash ( hash ) } <EOL> logger . info ( '<STR_LIT>' , params ) <EOL> response = self . session . get ( self . server_url , params = params , timeout = <NUM_LIT:10> ) <EOL> response . raise_for_status ( ) <EOL> if response . content [ : <NUM_LIT:4> ] == b'<STR_LIT>' : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> return None <EOL> subtitle = NapiProjektSubtitle ( language , hash ) <EOL> subtitle . content = response . content <EOL> logger . debug ( '<STR_LIT>' , subtitle ) <EOL> return subtitle <EOL> def list_subtitles ( self , video , languages ) : <EOL> return [ s for s in [ self . query ( l , video . hashes [ '<STR_LIT>' ] ) for l in languages ] if s is not None ] <EOL> def download_subtitle ( self , subtitle ) : <EOL> pass </s>
