<s> """<STR_LIT>""" <EOL> import mimetypes <EOL> import os <EOL> class Base ( object ) : <EOL> """<STR_LIT>""" <EOL> __name__ = '<STR_LIT>' <EOL> extensions = ( ) <EOL> def __init__ ( self , source = None ) : <EOL> self . source = source <EOL> self . reset_cache ( ) <EOL> def format_metadata ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def get_album ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def get_file_path ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . source <EOL> def get_coordinate ( self , type ) : <EOL> return None <EOL> def get_extension ( self ) : <EOL> """<STR_LIT>""" <EOL> if ( not self . is_valid ( ) ) : <EOL> return None <EOL> source = self . source <EOL> return os . path . splitext ( source ) [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] . lower ( ) <EOL> def get_metadata ( self , update_cache = False ) : <EOL> """<STR_LIT>""" <EOL> if ( not self . is_valid ( ) ) : <EOL> return None <EOL> if ( isinstance ( self . metadata , dict ) and update_cache is False ) : <EOL> return self . metadata <EOL> source = self . source <EOL> self . metadata = { <EOL> '<STR_LIT>' : self . get_date_taken ( ) , <EOL> '<STR_LIT>' : self . get_coordinate ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . get_coordinate ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . get_album ( ) , <EOL> '<STR_LIT:title>' : self . get_title ( ) , <EOL> '<STR_LIT>' : self . get_mimetype ( ) , <EOL> '<STR_LIT>' : os . path . splitext ( os . path . basename ( source ) ) [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : self . get_extension ( ) , <EOL> '<STR_LIT>' : os . path . dirname ( source ) <EOL> } <EOL> return self . metadata <EOL> def get_mimetype ( self ) : <EOL> """<STR_LIT>""" <EOL> if ( not self . is_valid ( ) ) : <EOL> return None <EOL> source = self . source <EOL> mimetype = mimetypes . guess_type ( source ) <EOL> if ( mimetype is None ) : <EOL> return None <EOL> return mimetype [ <NUM_LIT:0> ] <EOL> def get_title ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def is_valid ( self ) : <EOL> """<STR_LIT>""" <EOL> source = self . source <EOL> return os . path . splitext ( source ) [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] . lower ( ) in self . extensions <EOL> def reset_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> self . metadata = None <EOL> def set_album ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def set_album_from_folder ( self ) : <EOL> """<STR_LIT>""" <EOL> metadata = self . get_metadata ( ) <EOL> if ( not isinstance ( metadata , dict ) or metadata [ '<STR_LIT>' ] is not None ) : <EOL> return False <EOL> folder = os . path . basename ( metadata [ '<STR_LIT>' ] ) <EOL> if ( len ( folder ) == <NUM_LIT:0> ) : <EOL> return False <EOL> self . set_album ( folder ) <EOL> return True <EOL> def set_metadata_basename ( self , new_basename ) : <EOL> """<STR_LIT>""" <EOL> self . get_metadata ( ) <EOL> self . metadata [ '<STR_LIT>' ] = new_basename <EOL> def set_metadata ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> metadata = self . get_metadata ( ) <EOL> for key in kwargs : <EOL> if ( key in metadata ) : <EOL> self . metadata [ key ] = kwargs [ key ] <EOL> @ classmethod <EOL> def get_class_by_file ( cls , _file , classes ) : <EOL> if not isinstance ( _file , basestring ) or not os . path . isfile ( _file ) : <EOL> return None <EOL> extension = os . path . splitext ( _file ) [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] . lower ( ) <EOL> if len ( extension ) > <NUM_LIT:0> : <EOL> for i in classes : <EOL> if ( extension in i . extensions ) : <EOL> return i ( _file ) <EOL> return None <EOL> @ classmethod <EOL> def get_valid_extensions ( cls ) : <EOL> """<STR_LIT>""" <EOL> return cls . extensions </s>
