From 777e423aa558d1896e56edf50a970394f8c6ec75 Mon Sep 17 00:00:00 2001 From: qwewqa <198e559dbd446d973355f415bdfa34@gmail.com> Date: Sat, 23 Jan 2021 13:02:33 -0500 Subject: [PATCH] export music jackets --- export_assets.py | 51 +++++++++---------------- miyu_bot/commands/common/asset_paths.py | 46 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 33 deletions(-) create mode 100644 miyu_bot/commands/common/asset_paths.py diff --git a/export_assets.py b/export_assets.py index 81a2af9..ac688d1 100644 --- a/export_assets.py +++ b/export_assets.py @@ -4,6 +4,7 @@ from pathlib import Path from d4dj_utils.manager.asset_manager import AssetManager from miyu_bot.bot.master_asset_manager import hash_master +from miyu_bot.commands.common.asset_paths import * def main(): @@ -12,54 +13,38 @@ def main(): asset_manager = AssetManager('assets') - music_dir = target_dir / 'music' - chart_dir = music_dir / 'charts' - card_dir = target_dir / 'cards' - card_icon_dir = card_dir / 'icons' - card_art_dir = card_dir / 'art' - event_dir = target_dir / 'events' - event_logo_dir = event_dir / 'logos' - - music_dir.mkdir(exist_ok=True) - chart_dir.mkdir(exist_ok=True) - card_dir.mkdir(exist_ok=True) - card_icon_dir.mkdir(exist_ok=True) - card_art_dir.mkdir(exist_ok=True) - event_dir.mkdir(exist_ok=True) - event_logo_dir.mkdir(exist_ok=True) + (target_dir / music_dir).mkdir(exist_ok=True) + (target_dir / chart_dir).mkdir(exist_ok=True) + (target_dir / jacket_dir).mkdir(exist_ok=True) + (target_dir / card_dir).mkdir(exist_ok=True) + (target_dir / card_icon_dir).mkdir(exist_ok=True) + (target_dir / card_art_dir).mkdir(exist_ok=True) + (target_dir / event_dir).mkdir(exist_ok=True) + (target_dir / event_logo_dir).mkdir(exist_ok=True) for music in asset_manager.music_master.values(): + try: + shutil.copy(music.jacket_path, target_dir / get_music_jacket_path(music)) + except FileNotFoundError: + pass for chart in music.charts.values(): try: - chart_hash = hash_master(chart) - chart_path = chart.image_path - target_path = chart_dir / f'{chart_path.stem}_{chart_hash}{chart_path.suffix}' - shutil.copy(chart_path, target_path) - mix_path = chart.mix_path - target_path = chart_dir / f'{mix_path.stem}_{chart_hash}{mix_path.suffix}' - shutil.copy(mix_path, target_path) + shutil.copy(chart.image_path, target_dir / get_chart_image_path(chart)) + shutil.copy(chart.image_path, target_dir / get_chart_mix_path(chart)) except FileNotFoundError: pass for card in asset_manager.card_master.values(): - card_hash = hash_master(card) try: for lb in range(2): - art_path = card.art_path(lb) - art_target = card_art_dir / f'{art_path.stem}_{card_hash}{art_path.suffix}' - icon_path = card.icon_path(lb) - icon_target = card_icon_dir / f'{icon_path.stem}_{card_hash}{icon_path.suffix}' - shutil.copy(art_path, art_target) - shutil.copy(icon_path, icon_target) + shutil.copy(card.art_path(lb), target_dir / get_card_art_path(card, lb)) + shutil.copy(card.icon_path(lb), target_dir / get_card_icon_path(card, lb)) except FileNotFoundError: pass for event in asset_manager.event_master.values(): try: - event_hash = hash_master(event) - logo_path = event.logo_path - logo_target = event_logo_dir / f'{logo_path.stem}_{event_hash}{logo_path.suffix}' - shutil.copy(logo_path, logo_target) + shutil.copy(event.logo_path, target_dir / get_event_logo_path(event)) except FileNotFoundError: pass diff --git a/miyu_bot/commands/common/asset_paths.py b/miyu_bot/commands/common/asset_paths.py new file mode 100644 index 0000000..cda7990 --- /dev/null +++ b/miyu_bot/commands/common/asset_paths.py @@ -0,0 +1,46 @@ +from pathlib import Path + +from d4dj_utils.master.card_master import CardMaster +from d4dj_utils.master.chart_master import ChartMaster +from d4dj_utils.master.event_master import EventMaster +from d4dj_utils.master.music_master import MusicMaster + +from miyu_bot.bot.master_asset_manager import hash_master + + +def _get_asset_path(master, parent, path): + return Path(parent) / f'{path.stem}_{hash_master(master)}{path.suffix}' + + +music_dir = Path('.') / 'music' +chart_dir = music_dir / 'charts' +jacket_dir = music_dir / 'jacket' +card_dir = Path('.') / 'cards' +card_icon_dir = card_dir / 'icons' +card_art_dir = card_dir / 'art' +event_dir = Path('.') / 'events' +event_logo_dir = event_dir / 'logos' + + +def get_music_jacket_path(music: MusicMaster): + return _get_asset_path(music, jacket_dir, music.jacket_path) + + +def get_chart_image_path(chart: ChartMaster): + return _get_asset_path(chart, chart_dir, chart.image_path) + + +def get_chart_mix_path(chart: ChartMaster): + return _get_asset_path(chart, chart_dir, chart.mix_path) + + +def get_card_art_path(card: CardMaster, lb): + return _get_asset_path(card, card_art_dir, card.art_path(lb)) + + +def get_card_icon_path(card: CardMaster, lb): + return _get_asset_path(card, card_icon_dir, card.icon_path(lb)) + + +def get_event_logo_path(event: EventMaster): + return _get_asset_path(event, event_logo_dir, event.logo_path)