<s> """<STR_LIT>""" <EOL> from __future__ import division , absolute_import , print_function <EOL> import subprocess <EOL> from beets import ui <EOL> from beets import util <EOL> from beets . plugins import BeetsPlugin <EOL> class KeyFinderPlugin ( BeetsPlugin ) : <EOL> def __init__ ( self ) : <EOL> super ( KeyFinderPlugin , self ) . __init__ ( ) <EOL> self . config . add ( { <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : True , <EOL> u'<STR_LIT>' : False , <EOL> } ) <EOL> if self . config [ '<STR_LIT>' ] . get ( bool ) : <EOL> self . import_stages = [ self . imported ] <EOL> def commands ( self ) : <EOL> cmd = ui . Subcommand ( '<STR_LIT>' , <EOL> help = u'<STR_LIT>' ) <EOL> cmd . func = self . command <EOL> return [ cmd ] <EOL> def command ( self , lib , opts , args ) : <EOL> self . find_key ( lib . items ( ui . decargs ( args ) ) , write = ui . should_write ( ) ) <EOL> def imported ( self , session , task ) : <EOL> self . find_key ( task . items ) <EOL> def find_key ( self , items , write = False ) : <EOL> overwrite = self . config [ '<STR_LIT>' ] . get ( bool ) <EOL> bin = util . bytestring_path ( self . config [ '<STR_LIT>' ] . get ( unicode ) ) <EOL> for item in items : <EOL> if item [ '<STR_LIT>' ] and not overwrite : <EOL> continue <EOL> try : <EOL> output = util . command_output ( [ bin , b'<STR_LIT>' , <EOL> util . syspath ( item . path ) ] ) <EOL> except ( subprocess . CalledProcessError , OSError ) as exc : <EOL> self . _log . error ( u'<STR_LIT>' , exc ) <EOL> continue <EOL> except UnicodeEncodeError : <EOL> self . _log . error ( u'<STR_LIT>' , <EOL> item . path ) <EOL> continue <EOL> key_raw = output . rsplit ( None , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] <EOL> try : <EOL> key = key_raw . decode ( '<STR_LIT:utf8>' ) <EOL> except UnicodeDecodeError : <EOL> self . _log . error ( u'<STR_LIT>' ) <EOL> continue <EOL> item [ '<STR_LIT>' ] = key <EOL> self . _log . info ( u'<STR_LIT>' , <EOL> key , util . displayable_path ( item . path ) ) <EOL> if write : <EOL> item . try_write ( ) <EOL> item . store ( ) </s>
