Skip to content

Instantly share code, notes, and snippets.

@insin
Last active February 13, 2024 21:59
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save insin/b1a294e440548e0d5860 to your computer and use it in GitHub Desktop.
Save insin/b1a294e440548e0d5860 to your computer and use it in GitHub Desktop.
Extract Minecraft music

Extract Minecraft music

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.

1. Install Node.js or io.js

2. Save extract-music.js to your Minecraft assets directory:

  • Windows: %AppData%\.minecraft\assets
  • Linux: ~/.minecraft/assets
  • OS X: ~/Library/Application Support/minecraft/assets

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 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')
var objects = require('./indexes/1.8.json').objects
for (var filePath in objects) {
if (!/\/(?:music|records)\//.test(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)
}
@alanrme
Copy link

alanrme commented Aug 23, 2017

I think for people like me you should have included a version that extracts and renames all sounds because that's what I wanted:

var fs = require('fs-extra')
var objects = require('./indexes/1.12.json').objects

for (var filePath in objects) {
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)
}

And you should also have said:

  • That step 3 and 4 need to be done in command prompt
  • And to use cd to navigate to the folder (for beginners)

Anyway, this was still a massive help, even when it was a bit confusing.

@oldfox303
Copy link

For version 1.12.2 I had to change the location of the index and object path for this work.

`var fs = require('fs-extra')

var objects = require('./assets/indexes/1.12.json').objects

for (var filePath in objects) {
if (!//(?:music|records)//.test(filePath)) continue

var copyPath = filePath.replace('minecraft/', './')
var hash = objects[filePath].hash
var objectPath = './assets/objects/' + hash.substring(0, 2) + '/' + hash
console.log(objectPath, '->', copyPath)
fs.copySync(objectPath, copyPath)
}`

Cheers!

@TheWildNooblet
Copy link

Ummmmmmm...... If i wanted the ambience too what changes would i have to make to the extract-music.js code?

@DatrixTHLK
Copy link

DatrixTHLK commented Dec 24, 2019

No changes need to be made since all music and sounds are extracted from the assets file, but it depends on what version you want to extract the music from, If you need it from a specific version of minecraft such as 1.7 just change the line with 1.12.json to 1.7.json or if you want the sounds from 1.8+ then substitute that for 1.12.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment