Exemple #1
0
 def __remove_commercials(self, output_path):
     with utils.temp_file(suffix='.jpg') as temp_picture:
         # check whether or not to save picture cover
         # function will throw exception if cant identify cover picture properly
         save_cover_picture = True
         try:
             metadata.picture_extract(output_path, temp_picture)
             self.logger.debug("Cover picture for file %s being saved to file %s", output_path, temp_picture)
         except AudioFileException:
             save_cover_picture = False
             self.logger.warn("No cover picture found for file %s", output_path)
         with utils.temp_file(suffix='.mp3', delete=False) as temp_audio:
             self.logger.debug("Generating audio volume list for commercial identify")
             volume_list = editor.generate_audio_volume_array(output_path)
             self.logger.debug("Gathering commercial data for file %s", output_path)
             commercial_intervals, non_commercial_intervals = \
                     editor.commercial_identify(output_path, volume_list=volume_list)
             self.logger.debug("Found commercial intervals %s in file %s, removing commercials",
                               commercial_intervals, output_path)
             self.logger.debug("Writing new audio file %s with non commercial intervals %s",
                               temp_audio, non_commercial_intervals)
             editor.commercial_remove(output_path, temp_audio, non_commercial_intervals, verbose=False)
             self.logger.debug("Moving commercial free file %s back to original path %s", temp_audio, output_path)
             if save_cover_picture:
                 self.logger.debug("Reset cover picture on file %s from file %s", temp_audio, temp_picture)
                 metadata.picture_update(temp_audio, temp_picture)
             self.logger.debug("Moving contents of file %s back to correct path %s", temp_audio, output_path)
             os.rename(temp_audio, output_path)
             # make sure you get the right file size
             return os.path.getsize(output_path)
Exemple #2
0
 def test_generate_volume_data(self):
     length = 12
     with test_utils.temp_audio_file(open_data=False, duration=length) as temp_audio:
         volume_data = editor.generate_audio_volume_array(temp_audio)
         self.assert_length(volume_data, length - 1)