Example #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)
Example #2
0
    def test_audio_picture_extract_data(self):
        # test picture update and extract and data is same
        with test_utils.temp_audio_file(open_data=False) as temp_audio:
            # test with jpg
            with test_utils.temp_image_file() as temp_pic:
                with open(temp_pic, 'rb') as reader:
                    temp_pic_data = reader.read()
                metadata.picture_update(temp_audio, temp_pic)
                with utils.temp_file(suffix='.jpg') as new_temp_pic:
                    metadata.picture_extract(temp_audio, new_temp_pic)
                    with open(new_temp_pic, 'rb') as reader:
                        new_temp_data = reader.read()
                    self.assertEqual(new_temp_data, temp_pic_data)

            # test with png
            with test_utils.temp_image_file(suffix='.png') as temp_pic:
                with open(temp_pic, 'rb') as reader:
                    temp_pic_data = reader.read()
                metadata.picture_update(temp_audio, temp_pic)

                with utils.temp_file(suffix='.png') as new_temp_pic:
                    metadata.picture_extract(temp_audio, new_temp_pic)
                    with open(new_temp_pic, 'rb') as reader:
                        new_temp_data = reader.read()
                    self.assertEqual(new_temp_data, temp_pic_data)
Example #3
0
    def test_episode_download_remove_commercial_with_picture(self):
        # curl download used for rss and soundcloud
        pod_args = {"archive_type": "rss", "max_allowed": 1, "remove_commercials": True}
        with test_utils.temp_podcast(self.client, broadcast_url=True, **pod_args) as podcast:
            httpretty.register_uri(httpretty.GET, podcast["broadcast_id"], body=history_on_fire.DATA)
            self.client.episode_sync()
            episode_list = self.client.episode_list(only_files=False)
            with test_utils.temp_audio_file(open_data=False) as mp3_file:
                with test_utils.temp_image_file() as image_file:
                    metadata.picture_update(mp3_file, image_file)
                    with open(mp3_file, "r") as f:
                        mp3_body = f.read()
                        test_utils.mock_mp3_download(episode_list[0]["download_url"], mp3_body)
                        self.client.episode_download(episode_list[0]["id"])
                        episode = self.client.episode_show(episode_list[0]["id"])[0]
                        self.assert_not_none(episode["file_path"])
                        # make sure episode list shows episode with only_files=True
                        episode_list = self.client.episode_list()
                        self.assert_length(episode_list, 1)
                        self.assert_not_none(episode_list[0]["file_size"])
                        self.assertTrue(episode_list[0]["file_size"] > 0)

                        # make sure image file is right
                        with utils.temp_file(suffix=".jpg") as temper:
                            metadata.picture_extract(episode_list[0]["file_path"], temper)
                            with open(temper, "r") as f:
                                with open(image_file, "r") as ff:
                                    self.assertEqual(f.read(), ff.read())
Example #4
0
 def test_audio_picture_extract_name_overriden(self):
     with test_utils.temp_audio_file(open_data=False) as temp_audio:
         # give it a bad ending, should be overriden with .jpg
         with test_utils.temp_image_file() as temp_pic:
             metadata.picture_update(temp_audio, temp_pic)
             with utils.temp_file(suffix='.foo') as new_temp_pic:
                 output = metadata.picture_extract(temp_audio, new_temp_pic)
                 actual_path = output['output_path']
                 self.assertNotEqual(actual_path, new_temp_pic)
                 self.assertTrue(actual_path.endswith('.jpg'))
                 # make sure file gets deleted
                 os.remove('%s.jpg' % new_temp_pic)
         # give it a bad ending, should be overriden with .png
         with test_utils.temp_image_file(suffix='.png') as temp_pic:
             metadata.picture_update(temp_audio, temp_pic)
             with utils.temp_file(suffix='.foo') as new_temp_pic:
                 output = metadata.picture_extract(temp_audio, new_temp_pic)
                 actual_path = output['output_path']
                 self.assertNotEqual(actual_path, new_temp_pic)
                 self.assertTrue(actual_path.endswith('.png'))
                 # make sure file gets deleted
                 os.remove('%s.png' % new_temp_pic)
Example #5
0
def picture_extract(args):
    metadata.picture_extract(args.audio_file, args.picture_output_path)
    print 'Picture extracted to path: %s' % args.picture_output_path