Skip to content

Instantly share code, notes, and snippets.

@jrwarwick
Forked from insin/README.md
Last active October 16, 2019 06:13
Show Gist options
  • Save jrwarwick/2a55b332a75c5b49cb219d4a23bc9d7f to your computer and use it in GitHub Desktop.
Save jrwarwick/2a55b332a75c5b49cb219d4a23bc9d7f to your computer and use it in GitHub Desktop.
Extract Minecraft music

Extract Minecraft music (Windows-centric easy-cheezy edition)

As of 1.8, assets are stored by hash, which makes it fiddly to listen to Minecraft's amazing ambient soundtrack outside the game.

This script can be used to copy music files to appopriately-named and organised .ogg files for easier listening.

0. If you happen to have PowerShell 3.0, you might be able to just save and execute extract_mc_music.ps1 and then skip to step 5

1. Install Node.js. Actually, you don't even have to "install". You can just download the stand-alone zip archived version, extract it, and start a CMD shell in the subdirectory with node.exe in it.

2. Save extract_mc_music.js to your freshly extracted node directory.

3. Install dependencies

npm install fs-extra

4. Run the script

node extract-music.js

You should see output similar to this, after which .ogg files will be available in a new %AppData%\.minecraft\assets\sounds\ directory:

./objects/87/87722a59c8d488370f3d430cd4c97a3161081785 -> ./sounds/music/menu/menu3.ogg
./objects/df/df1ff11b79757432c5c3f279e5ecde7b63ceda64 -> ./sounds/music/game/hal1.ogg
./objects/62/6254527d626a2c7d80901cc2e62dce3ba4bd81f6 -> ./sounds/music/game/creative/creative6.ogg
...

5. Listen!

var fs = require('fs-extra');
console.log('Starting directory: ' + process.cwd());
try {
process.chdir(process.env['USERPROFILE'] + '/AppData/Roaming/.minecraft/assets');
console.log('New directory: ' + process.cwd());
}
catch (err) {
console.log('chdir: ' + err);
}
//Note that the version number here is hard to nail down if you have various revisions and mods locally.
var objects = JSON.parse(fs.readFileSync('./indexes/1.14.json', 'utf8')).objects;
for (var filePath in objects) {
if (!/\/(?:music|records)\//.test(filePath)) {
console.log(" skipping " + filePath)
continue
}
var copyPath = filePath.replace('minecraft/', './')
var hash = objects[filePath].hash
var objectPath = './objects/' + hash.substring(0, 2) + '/' + hash
console.log(objectPath, '->', copyPath)
fs.copySync(objectPath, copyPath)
}
write-output "Starting directory: $(Get-Location)"
Set-Location $env:USERPROFILE\AppData\Roaming\.minecraft\assets
Write-Output "New directory: $(Get-Location)"
#Note that the version number here is hard to nail down if you have various revisions and mods locally.
$objects = $(get-content -path '.\indexes\1.14.json' | convertform-JSON).objects
foreach ($filePath in $objects) {
if ($filePath -match "\\(?:music|records)\\") {
$copyPath = $filePath.replace('minecraft\', "$($env:USERPROFILE)\Downloads\"))
$hash = $objects[$filePath].hash
$objectPath = ".\objects\$($hash.substring(0, 2))\$($hash)"
write-output "`t$objectPath -> $copyPath"
copy-item -Path $objectPath -Destination $copyPath
} else {
write-verbose "`t`tskipping $filePath"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment