<s> from totalimpact . providers import provider <EOL> from totalimpact . providers . provider import Provider , ProviderContentMalformedError <EOL> import simplejson , os , re <EOL> import logging <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> class Vimeo ( Provider ) : <EOL> example_id = ( "<STR_LIT:url>" , "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> descr = "<STR_LIT>" <EOL> biblio_url_template = "<STR_LIT>" <EOL> aliases_url_template = "<STR_LIT>" <EOL> metrics_url_template = "<STR_LIT>" <EOL> provenance_url_template = "<STR_LIT>" <EOL> static_meta_dict = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> } <EOL> def __init__ ( self ) : <EOL> super ( Vimeo , self ) . __init__ ( ) <EOL> def is_relevant_alias ( self , alias ) : <EOL> ( namespace , nid ) = alias <EOL> if ( ( "<STR_LIT:url>" == namespace ) and ( "<STR_LIT>" in nid ) ) : <EOL> return True <EOL> else : <EOL> return False <EOL> def _get_video_id ( self , video_url ) : <EOL> try : <EOL> nid_as_vimeo_id = re . findall ( "<STR_LIT>" , video_url ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> raise ProviderContentMalformedError ( "<STR_LIT>" ) <EOL> return nid_as_vimeo_id <EOL> def _get_templated_url ( self , template , nid_as_video_url , method = None ) : <EOL> nid_as_video_id = self . _get_video_id ( nid_as_video_url ) <EOL> url = template % ( nid_as_video_id ) <EOL> return ( url ) <EOL> def _extract_biblio ( self , page , id = None ) : <EOL> json_response = provider . _load_json ( page ) <EOL> this_video_json = json_response [ <NUM_LIT:0> ] <EOL> dict_of_keylists = { <EOL> '<STR_LIT:title>' : [ '<STR_LIT:title>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT:url>' : [ '<STR_LIT:url>' ] <EOL> } <EOL> biblio_dict = provider . _extract_from_data_dict ( this_video_json , dict_of_keylists ) <EOL> try : <EOL> biblio_dict [ "<STR_LIT>" ] = biblio_dict [ "<STR_LIT>" ] [ <NUM_LIT:0> : <NUM_LIT:4> ] <EOL> except KeyError : <EOL> pass <EOL> biblio_dict [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> return biblio_dict <EOL> def _extract_metrics ( self , page , status_code = <NUM_LIT:200> , id = None ) : <EOL> if status_code != <NUM_LIT:200> : <EOL> if status_code == <NUM_LIT> : <EOL> return { } <EOL> else : <EOL> raise ( self . _get_error ( status_code ) ) <EOL> if not "<STR_LIT>" in page : <EOL> raise ProviderContentMalformedError <EOL> json_response = provider . _load_json ( page ) <EOL> this_video_json = json_response [ <NUM_LIT:0> ] <EOL> dict_of_keylists = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> metrics_dict = provider . _extract_from_data_dict ( this_video_json , dict_of_keylists ) <EOL> return metrics_dict </s>
