add duration to music commands
This commit is contained in:
parent
bc89624ad3
commit
16c8b4ebec
@ -70,6 +70,7 @@ class Music(commands.Cog):
|
||||
|
||||
music_info = {
|
||||
'Category': song.category.name,
|
||||
'Duration': self.format_duration(self.get_music_duration(song)),
|
||||
'BPM': song.bpm,
|
||||
'Section Trend': song.section_trend.name,
|
||||
'Sort Order': song.default_order,
|
||||
@ -162,6 +163,7 @@ class Music(commands.Cog):
|
||||
|
||||
embed.add_field(name='Info',
|
||||
value=f'Level: {chart.display_level}\n'
|
||||
f'Duration: {self.format_duration(self.get_music_duration(song))}\n'
|
||||
f'Unit: {song.special_unit_name or song.unit.name}\n'
|
||||
f'Category: {song.category.name}\n'
|
||||
f'BPM: {song.bpm}',
|
||||
@ -260,6 +262,16 @@ class Music(commands.Cog):
|
||||
except (KeyError, ValueError):
|
||||
return self.music[name_or_id]
|
||||
|
||||
def get_music_duration(self, music: MusicMaster):
|
||||
with contextlib.closing(wave.open(str(music.audio_path.with_name(music.audio_path.name + '.wav')), 'r')) as f:
|
||||
frames = f.getnframes()
|
||||
rate = f.getframerate()
|
||||
duration = frames / float(rate)
|
||||
return duration
|
||||
|
||||
def format_duration(self, seconds):
|
||||
return f'{int(seconds // 60)}m {round(seconds % 60, 2)}s'
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Music(bot))
|
||||
|
@ -8,12 +8,18 @@ from d4dj_utils.manager.revision_manager import RevisionManager
|
||||
|
||||
async def main():
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
revision_manager = RevisionManager('assets')
|
||||
await revision_manager.repair_downloads()
|
||||
await revision_manager.update_assets()
|
||||
manager = AssetManager('assets')
|
||||
manager.render_charts_by_master()
|
||||
|
||||
for music in manager.music_master.values():
|
||||
if not music.audio_path.with_name(music.audio_path.name + '.wav').exists():
|
||||
music.decode_audio()
|
||||
logger.info(f'Decoded audio for {music.name}.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
|
Loading…
x
Reference in New Issue
Block a user