Created
February 20, 2017 22:00
-
-
Save noelleleigh/80621869ae3bdce3555adc317f947382 to your computer and use it in GitHub Desktop.
Download and extract some background music from http://middle-earth.thehobbit.com/
This file contains 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
<# | |
.SYNOPSIS | |
Download and extract music from http://middle-earth.thehobbit.com/ | |
#> | |
# Get dmaf JSON file | |
$dmaf_assets_url = 'http://middle-earth.thehobbit.com/stable.380729695375977266/assets/dmaf_assets/' | |
$data = Invoke-WebRequest -Uri ($dmaf_assets_url + 'json/dmaf_data.json') | ConvertFrom-Json | |
# Get the section of JSON that we're interested in | |
$webaudio_loader_json = (( | |
$data.configs | Where-Object { $_.name -eq 'init_and_loading' }).actions | | |
Where-Object { $_.instanceId -eq 'webglmap_webaudio_loader' }).files | | |
Where-Object { $_.path -eq 'bin/webglmap_webaudio_loader' } | |
# Download the combined OGG file | |
$ogg_url = $dmaf_assets_url + $webaudio_loader_json.path + '.ogg.bin' | |
$ogg_filename = 'webglmap_webaudio_loader.ogg' | |
Invoke-WebRequest -Uri $ogg_url -OutFile $ogg_filename | |
$ogg_file = [System.IO.File]::ReadAllBytes($(Join-Path $PSScriptRoot $ogg_filename)) | |
# Extract all the tracks from the OGG file | |
foreach ($track in $webaudio_loader_json.files) { | |
# Extract the track to new file using the byte counts defined in ogg_start and ogg_end | |
$track_filename = "$($track.name).ogg" | |
Write-Output "Extracting $($track_filename)" | |
# Extract the track to a new file (http://stackoverflow.com/a/24687573) | |
$output_file = [System.IO.File]::OpenWrite($(Join-Path $PSScriptRoot $track_filename)) | |
$output_file.Write($ogg_file, $track.ogg.start, ($track.ogg.end - $track.ogg.start)) | |
$output_file.close() | |
} | |
Write-Output "Done! $($webaudio_loader_json.files.length) files produced." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment