Last active
August 24, 2021 10:11
-
-
Save owenvoke/c4eb4ff376617a6644177c22de8c5481 to your computer and use it in GitHub Desktop.
A simple script to parse Beat Saber metadata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| Beat Saber Metadata Parser | |
|-------------------------------------------------------------------------- | |
| | |
| This application will parse the metadata from downloaded compressed | |
| Beat Saber song files. | |
| | |
| Usage: ./bs-meta-parser [path/to/song.zip] | |
| | |
*/ | |
$zip = new ZipArchive(); | |
if ($zip->open($argv[1])) { | |
$content = $zip->getFromName('info.dat') ?: $zip->getFromName('Info.dat') ?: null; | |
if ($content === null) { | |
echo 'Failed to find `info.dat` or `Info.dat` in the provided ZIP archive'; | |
exit(1); | |
} | |
$song = json_decode($content, true, 512, JSON_THROW_ON_ERROR); | |
echo "Name: {$song['_songName']} {$song['_songSubName']}".PHP_EOL; | |
echo "Artist: {$song['_songAuthorName']}".PHP_EOL; | |
echo "BPM: {$song['_beatsPerMinute']}".PHP_EOL; | |
echo "Level Author: {$song['_levelAuthorName']}".PHP_EOL; | |
$difficulties = []; | |
foreach ($song['_difficultyBeatmapSets'] as $difficulty) { | |
foreach ($difficulty['_difficultyBeatmaps'] as $version) { | |
$difficulties[] = "{$version['_difficulty']} ({$difficulty['_beatmapCharacteristicName']})"; | |
} | |
} | |
echo 'Difficulties: '.implode(', ', $difficulties).PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment