Skip to content

Instantly share code, notes, and snippets.

@owenvoke
Last active August 24, 2021 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owenvoke/c4eb4ff376617a6644177c22de8c5481 to your computer and use it in GitHub Desktop.
Save owenvoke/c4eb4ff376617a6644177c22de8c5481 to your computer and use it in GitHub Desktop.
A simple script to parse Beat Saber metadata
#!/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