Exemplo n.º 1
0
 def _script_to_filename(self,
                         naming_format,
                         file_metadata,
                         file_extension,
                         settings=None):
     if settings is None:
         config = get_config()
         settings = config.setting
     metadata = Metadata()
     if settings["clear_existing_tags"]:
         # script_to_filename_with_metadata guarantees this is not modified
         metadata = file_metadata
     else:
         metadata.copy(self.orig_metadata)
         metadata.update(file_metadata)
     (filename,
      new_metadata) = script_to_filename_with_metadata(naming_format,
                                                       metadata,
                                                       file=self,
                                                       settings=settings)
     if not filename:
         return None
     # NOTE: the filename generated by the naming script does not have a file extension
     ext = new_metadata.get('~extension', file_extension)
     return filename + '.' + ext.lstrip('.')
Exemplo n.º 2
0
 def test_script_to_filename_with_metadata(self):
     metadata = Metadata()
     metadata['artist'] = 'Foo'
     metadata['~extension'] = 'foo'
     (filename, new_metadata) = script_to_filename_with_metadata(
         '$set(_extension,bar)\n%artist%', metadata)
     self.assertEqual('Foo', filename)
     self.assertEqual('foo', metadata['~extension'])
     self.assertEqual('bar', new_metadata['~extension'])
Exemplo n.º 3
0
 def _script_to_filename(self,
                         naming_format,
                         file_metadata,
                         file_extension,
                         settings=None):
     if settings is None:
         settings = config.setting
     metadata = Metadata()
     if settings["clear_existing_tags"]:
         metadata.copy(file_metadata)
     else:
         metadata.copy(self.orig_metadata)
         metadata.update(file_metadata)
     (filename,
      new_metadata) = script_to_filename_with_metadata(naming_format,
                                                       metadata,
                                                       file=self,
                                                       settings=settings)
     # NOTE: the script_to_filename strips the extension away
     ext = new_metadata.get('~extension', file_extension)
     return filename + '.' + ext.lstrip('.')