def tags_update(args): update_args = vars(args) update_args.pop('command') update_args.pop('module') inputy = update_args.pop('input_file') metadata.tags_update(inputy, **update_args) print 'Tags reset on file:%s' % inputy
def test_audio_tags_reset_mp4(self): with test_utils.temp_audio_file(open_data=False, suffix='.mp4') as temp: args = { 'title' : utils.random_string(), } metadata.tags_update(temp, **args) metadata.tags_delete(temp, 'foo', 'bar') new_tags = metadata.tags_show(temp) self.assertEqual(new_tags, args)
def test_audio_tags_none_isnt_set(self): with test_utils.temp_audio_file(open_data=False) as temp: args = { 'title' : utils.random_string(), 'album' : None, } metadata.tags_update(temp, **args) new_tags = metadata.tags_show(temp) self.assertEqual(new_tags, {'title' : args['title']})
def test_audio_tags_delete_args_not_there(self): with test_utils.temp_audio_file(open_data=False) as temp: args = { 'title' : utils.random_string(), 'album' : utils.random_string(), 'artist' : utils.random_string(), 'album_artist' : utils.random_string(), } metadata.tags_update(temp, **args) metadata.tags_delete(temp, 'foo') new_tags = metadata.tags_show(temp) self.assertEqual(args, new_tags)
def __episode_download_input(self, episode_input): def build_episode_path(episode, podcast): pod_path = podcast['file_location'] title = utils.normalize_name(episode.title) date = utils.normalize_name(episode.date.strftime(self.datetime_output_format)) file_name = '%s.%s' % (date, title) return os.path.join(pod_path, file_name) podcast_cache = dict() episodes_downloaded = [] for episode in episode_input: try: podcast = podcast_cache[episode.podcast_id] except KeyError: podcast = self.db_session.query(Podcast).get(episode.podcast_id).as_dict(self.datetime_output_format) podcast_cache[episode.podcast_id] = podcast manager = self._archive_manager(podcast['archive_type']) self.logger.debug("Downloading data from url:%s", episode.download_url) episode_path_prefix = build_episode_path(episode, podcast) output_path, download_size = manager.episode_download(episode.download_url, episode_path_prefix) if output_path is None and download_size is None: self.logger.error("Unable to download episode:%s, skipping", episode.id) continue self.logger.info("Downloaded episode %s data to file %s", episode.id, output_path) if podcast['remove_commercial']: self.logger.info("Removing commercials for episode:%s", episode.id) download_size = self.__remove_commercials(output_path) episode.file_path = utils.clean_string(output_path) episode.file_size = download_size self.db_session.commit() # use artist name if possible artist_name = podcast['artist_name'] or podcast['name'] try: metadata.tags_update(output_path, artist=artist_name, album_artist=artist_name, album=podcast['name'], title=episode.title, date=episode.date.strftime(self.datetime_output_format)) self.logger.debug("Updated database audio tags for episode %s", episode.id) except AudioFileException as error: self.logger.warn("Unable to update tags on file %s : %s", output_path, str(error)) episodes_downloaded.append(episode.id) return episodes_downloaded
def test_audio_tags(self): with test_utils.temp_audio_file(open_data=False) as temp: args = { 'title' : utils.random_string(), 'album' : utils.random_string(), 'performer' : utils.random_string(), 'track_number' : '1/2', 'disc_number' : '1/1', 'genre' : utils.random_string(), 'date' : '2015', 'copyright' : utils.random_string(), 'album_artist' : utils.random_string(), } metadata.tags_update(temp, **args) new_tags = metadata.tags_show(temp) self.assertEqual(args, new_tags) for key in args: metadata.tags_delete(temp, key) new_tags = metadata.tags_show(temp) self.assertEqual(new_tags, {})