Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Last active January 23, 2023 07:27
Show Gist options
  • Save kou1okada/67729443c83859c2789b5d9ef0782fe4 to your computer and use it in GitHub Desktop.
Save kou1okada/67729443c83859c2789b5d9ef0782fe4 to your computer and use it in GitHub Desktop.
getappx - Get URLs of .appx files from Microsoft Store.
#!/usr/bin/env bash
# getappx - Get URLs of .appx files from Microsoft Store.
# Copyright 2020 (c) Koichi OKADA. All rights reserved.
# This script is destributed under the MIT license.
source hhs.bash 0.2.0
function fetch_post () # URL POSTDATA
{
local cachedir=/tmp/.cache
local url="${1}??${2}"
local hash="$(echo "$url" | sha512sum | awk '{printf($1)}')"
local cache="$cachedir/$hash"
[ -d "$cachedir" ] || mkdir -p "$cachedir" || { error "can not make cachedir: $cachedir"; exit 1;}
if [ ! -e "$cache" ]; then
wget https://store.rg-adguard.net/api/GetFiles --post-data="$post" -qO "$cache"
printf "%s\t%s\n" "$hash" "$url" >> "$cachedir/list.txt"
fi
cat "$cache"
}
function get_appxlist ()
{
sed -E 's@<a[^>]*>@\n\0@g;s@</a>@\0\n@g' | \
grep '<a' |\
sed -E 's/.*href="([^"]*)".*>([^>]*)<.*/\2\t\1/g'
}
function optparse_getappx ()
{
case "$1" in
-l|--lang) # <LANG>
# Set language. (default: ja)
nparams 1
optset LANG "$2"
;;
-r|--ring) # <RING>
# Set ring. RING is one of WIF, WIS, RP of Retail. (default: PR)
nparams 1
optset RING "$2"
;;
*) return 1 ;;
esac
}
function getappx () # <URL>|<ProductID>
# Get URLs of .appx files from Microsoft Store.
# This script uses https://store.rg-adguard.net/.
{
local ProductID="$1"
ProductID="${ProductID/\?*/}"
ProductID="${ProductID//*\//}"
local post="type=ProductId&url=${ProductID}&ring=${OPT_RING:-RP}&lang=${OPT_LANG:-ja}"
fetch_post https://store.rg-adguard.net/api/GetFiles "$post" | \
get_appxlist
}
invoke_command "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment