Skip to content

Instantly share code, notes, and snippets.

@r15ch13
Created June 9, 2019 16:34
Show Gist options
  • Save r15ch13/5b9db753315853d4a5985fe932f7c0b9 to your computer and use it in GitHub Desktop.
Save r15ch13/5b9db753315853d4a5985fe932f7c0b9 to your computer and use it in GitHub Desktop.

Revisions

  1. r15ch13 created this gist Jun 9, 2019.
    33 changes: 33 additions & 0 deletions audible.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    function Read-AudioBookChecksum {
    param(
    [Parameter(Mandatory=$true,
    Position=0,
    ParameterSetName="Path",
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
    [ValidateNotNullOrEmpty()]
    [ValidateScript({ Test-Path $_ -Type Leaf })]
    [string]
    $Path
    )
    Process {
    try {
    $buffer = New-Object Byte[] 20
    $fs = [IO.File]::OpenRead($Path)
    $fs.Seek(581, [System.IO.SeekOrigin]::Begin) | Out-Null
    $fs.Read($buffer, 0, 4) | Out-Null
    if([System.Text.Encoding]::UTF8.GetString($buffer) -eq 'adrm') {
    $fs.Seek(653, [System.IO.SeekOrigin]::Begin) | Out-Null
    $fs.Read($buffer, 0, 20) | Out-Null
    return ($buffer | ForEach-Object ToString x2) -join ''
    }
    return $null
    }
    finally {
    $fs.Close();
    }
    }
    }


    Get-ChildItem "*.aax" | Read-AudioBookChecksum $_