How to use delete_tags method in localstack

Best Python code snippet using localstack_python

fix_music_files.py

Source:fix_music_files.py Github

copy

Full Screen

1#!/usr/bin/env python2import argparse3import json4import logging5from logging import FileHandler6import os7import re8from hathor.audio import metadata9from hathor.exc import AudioFileException10FEAT_MATCH = r"^(?P<title>.*[^\[\(]) ([\(\[] ?)?(?P<featuring>[Ff](ea)?t(uring)?(.)? .*[^\]\) ])( [\)\]])?"11def parse_args():12 parser = argparse.ArgumentParser(description="Fix artist tags")13 parser.add_argument("-d", "--dry-run", action="store_true", help="Only do dry run")14 parser.add_argument("-l", "--log-file", default="/tmp/music-tags.log",15 help="Log File")16 parser.add_argument("file_dir", help="File Dir with Music Files")17 return parser.parse_args()18def setup_logger(log_file):19 logger = logging.getLogger(__name__)20 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s',21 datefmt='%Y-%m-%d %H:%M:%S')22 logger.setLevel(logging.DEBUG)23 fh = FileHandler(log_file)24 fh.setLevel(logging.DEBUG)25 fh.setFormatter(formatter)26 logger.addHandler(fh)27 return logger28def check_file(log, update_data, delete_tags, full_path):29 try:30 tags = metadata.tags_show(full_path)31 except AudioFileException:32 log.error("Cannot get tags for file:%s", full_path)33 return update_data, delete_tags34 update_data = check_featured_artists_in_title(log, update_data,35 full_path, tags)36 delete_tags = check_genre_defined(log, delete_tags, full_path, tags)37 return update_data, delete_tags38def check_genre_defined(log, delete_tags, full_path, tags):39 '''40 I dont like the genre tag in the audio file41 unless its a podcast42 '''43 try:44 genre = tags['genre']45 except KeyError:46 return delete_tags47 if genre.lower() != 'podcast':48 log.debug("File:%s has genre:%s, marking for deletion",49 full_path, tags['genre'])50 delete_tags.setdefault('genre', set([]))51 delete_tags['genre'].add(full_path)52 return delete_tags53def check_featured_artists_in_title(log, update_data, full_path, tags):54 '''55 Most audio files you download tend to put the featured notes within the song title56 Theres a better way to deal with this, which is put this info in the "artist" tag57 of the audio file58 The "albumartist" tag should contain the main artist59 '''60 # Check title for featuring61 try:62 title = tags['title']63 except KeyError:64 log.error("No title tag for audio file:%s", full_path)65 return update_data66 # Check for possible featuring files67 matcher = re.match(FEAT_MATCH, title)68 if not matcher:69 log.warning("Unable to find matching regex for file:%s", full_path)70 return update_data71 # Combine featuring to end of album artist72 try:73 artist = '%s %s' % (tags['albumartist'], matcher.group('featuring'))74 except KeyError:75 log.warning("No albumartist tag:%s", full_path)76 return update_data77 # Use stripped title78 title = matcher.group('title')79 # Dont assume nothing in update_data key yet80 update_data.setdefault(full_path, {})81 update_data[full_path]['artist'] = artist82 update_data[full_path]['title'] = title83 return update_data84def main():85 args = parse_args()86 log = setup_logger(args.log_file)87 file_dir = os.path.abspath(args.file_dir)88 # Update data will track the file path89 # And what tags will need to be updated90 update_data = dict()91 # Delete tags will track tags that should be deleted92 delete_tags = dict()93 for base_path, _, file_list in os.walk(file_dir):94 for file_name in file_list:95 # Don't check 'low-quality' files96 if file_name == 'low-quality':97 continue98 full_path = os.path.join(base_path, file_name)99 log.debug("Checking file:%s", full_path)100 update_data, delete_tags = check_file(log, update_data, delete_tags, full_path)101 # Print out data fixes before continuing102 for path, new_tags in update_data.items():103 print("Will attempt to edit tags on file:", path)104 print("New tags\n:", json.dumps(new_tags, indent=4))105 for tag, data_set in delete_tags.items():106 print("Will attempt to delete tag:%s from the following files" % tag)107 for item in data_set:108 print(item)109 if not args.dry_run:110 user_input = input("Continue with fixing files?(y/n)")111 if user_input.lower() == 'y':112 for path, new_data in update_data.items():113 log.info("Updating file:%s", path)114 metadata.tags_update(path, new_data)115 for tag, data_set in delete_tags.items():116 for item in data_set:117 log.info("Removing tag:%s from file:%s", tag, item)118 metadata.tags_delete(item, [tag])119if __name__ == '__main__':...

Full Screen

Full Screen

deletetags.py

Source:deletetags.py Github

copy

Full Screen

...10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13from boto3.resources.action import CustomModeledAction14def inject_delete_tags(event_emitter, **kwargs):15 action_model = {16 'request': {17 'operation': 'DeleteTags',18 'params': [19 {20 'target': 'Resources[0]',21 'source': 'identifier',22 'name': 'Id',23 }24 ],25 }26 }27 action = CustomModeledAction(28 'delete_tags', action_model, delete_tags, event_emitter29 )30 action.inject(**kwargs)31def delete_tags(self, **kwargs):32 kwargs['Resources'] = [self.id]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful