def test_serialized_date(self): info = AlbumInfo() info.date = date(2021, 1, 2) info_dict = info.to_dict() self.assertEqual(info_dict['date'], '2021-01-02')
def test_set_date_in_init(self): info = AlbumInfo(date='2021-01-01') self.assertEqual(info.date, date(2021, 1, 1))
def test_set_date(self): info = AlbumInfo() info.date = '2021-01-01' self.assertEqual(info.date, date(2021, 1, 1)) info.date = date(2021, 1, 2) self.assertEqual(info.date, date(2021, 1, 2))
def test_deserialized_type(self): info_dict = AlbumInfo().to_dict() info_dict['type'] = 'Album' info = AlbumInfo.from_dict(info_dict) self.assertEqual(info.type, DiscoEntryType.Album)
def test_serialized_type(self): info = AlbumInfo() info_dict = info.to_dict() self.assertNotIn('_type', info_dict) self.assertIs(info_dict['type'], None)
def test_default_type(self): info = AlbumInfo() self.assertEqual(info.type, DiscoEntryType.UNKNOWN)
def test_entry_type_from_str(self): info = AlbumInfo(type='Album') self.assertEqual(info.type, DiscoEntryType.Album)
def main(): args = parser().parse_args() from ds_tools.logging import init_logging init_logging(args.verbose, log_path=None, names=None) from music.common.utils import can_add_bpm from music.files.patches import apply_mutagen_patches apply_mutagen_patches() # logging.getLogger('wiki_nodes.http.query').setLevel(logging.DEBUG) if args.match_log: logging.getLogger('music.manager.wiki_match.matching').setLevel( logging.DEBUG) action, sub_action = args.action, getattr(args, 'sub_action', None) if action == 'show': from music.manager.file_info import (print_track_info, table_song_tags, table_tag_type_counts, table_unique_tag_values, print_processed_info) if sub_action == 'info': print_track_info(args.path, args.tags, trim=not args.no_trim) elif sub_action == 'meta': print_track_info(args.path, meta_only=True) elif sub_action == 'count': table_tag_type_counts(args.path) elif sub_action == 'unique': table_unique_tag_values(args.path, args.tags) elif sub_action == 'table': table_song_tags(args.path, args.tags) elif sub_action == 'processed': print_processed_info(args.path, args.expand, args.only_errors) else: raise ValueError(f'Unexpected sub-action: {sub_action!r}') elif action in ('path2tag', 'clean', 'remove', 'bpm') or (action == 'update' and not args.load): from music.manager.file_update import (path_to_tag, update_tags_with_value, clean_tags, remove_tags, add_track_bpm) if action == 'path2tag': path_to_tag(args.path, args.dry_run, args.yes, args.title) elif action == 'clean': bpm = can_add_bpm() if args.bpm is None else args.bpm clean_tags(args.path, args.dry_run, bpm) elif action == 'remove': if not args.tag and not args.all: raise ValueError( 'Either --tag/-t or --all/-A must be provided') remove_tags(args.path, args.tag, args.dry_run, args.all) elif action == 'bpm': add_track_bpm(args.path, args.parallel, args.dry_run) elif action == 'update': if not args.tag or not args.value: raise ValueError('Both --tag/-t and --value/-V are required') update_tags_with_value(args.path, args.tag, args.value, args.replace, args.partial, args.dry_run) elif action == 'wiki': if sub_action == 'update': from music.manager.wiki_update import update_tracks bpm = can_add_bpm() if args.bpm is None else args.bpm update_tracks(args.path, args.dry_run, args.soloist, args.hide_edition, args.collab_mode, args.url, bpm, args.destination, args.title_case, args.sites, args.dump, args.load, args.artist, args.update_cover, args.no_album_move, args.artist_only, not args.replace_genre) elif sub_action in ('match', 'test'): from music.manager.wiki_match import show_matches, test_match if sub_action == 'match': show_matches(args.path) elif sub_action == 'test': test_match(args.path, args.url) elif sub_action in ('show', 'pprint', 'raw'): from music.manager.wiki_info import show_wiki_entity, pprint_wiki_page if sub_action == 'show': show_wiki_entity(args.identifier, args.expand, args.limit, args.types, args.type) elif sub_action == 'pprint': pprint_wiki_page(args.url, args.mode) elif sub_action == 'raw': pprint_wiki_page(args.url, 'raw') else: raise ValueError(f'Unexpected sub-action: {sub_action!r}') elif action in ('update', 'dump'): from music.manager.update import AlbumInfo if action == 'dump': AlbumInfo.from_path(args.path).dump(args.output, args.title_case) elif action == 'update': if not args.load: raise ValueError('--load PATH is required') AlbumInfo.load(args.load).update_and_move( dest_base_dir=args.destination, dry_run=args.dry_run, no_album_move=args.no_album_move, add_genre=not args.replace_genre, ) elif action == 'cover': from music.manager.images import extract_album_art, set_album_art, del_album_art if args.save: extract_album_art(args.path, args.save) elif args.load: set_album_art(args.path, args.load, args.max_width, args.dry_run) elif args.remove: del_album_art(args.path, args.dry_run) else: raise ValueError(f'Unexpected action: {action!r}')