Skip to content

Instantly share code, notes, and snippets.

@for2ando
Last active June 16, 2018 11:54
Show Gist options
  • Save for2ando/ca6845e802184ba251138ec5efd6453a to your computer and use it in GitHub Desktop.
Save for2ando/ca6845e802184ba251138ec5efd6453a to your computer and use it in GitHub Desktop.
Get Android Application's pet name and print for given application IDs.
#!/bin/bash
pname=$(basename "$0")
usage="$pname [-h|--help|-inpqw] {AppId [...]|-}
FEATURES
print an application name of an Android application that designated with
AppId.
OPTIONS
-h --help
print this help message.
-i
if unable to get appname, echos null string as an appname by default,
when -i is specified, if unable, echos the appid instead of the appname.
-n
suppress priting of an application name.
-p
print the AppId before an appname.
-q
quietly supress error message from wget.
-w
open the web page that includes an appname.
AppId
Android App\'s Application ID.
-
get AppId from stdin."
echoidp=false
echonamep=true
prefixidp=false
quietp=false
openwebp=false
getstdinp=false
while true; do
case "$1" in
-h|--help) shift; echo "$usage"; exit 0;;
-i) shift; echoidp=true;;
-n) shift; echonamep=false;;
-p) shift; prefixidp=true;;
-q) shift; quietp=true;;
-w) shift; openwebp=true;;
-) shift; getstdinp=true;;
--*) shift;;
-*) shift;;
*) break;;
esac
done
test $# -eq 0 -a $getstdinp = false && { echo "$usage"; exit 0; }
get-title() {
$prefixidp && echo -n "$1 "
url="https://play.google.com/store/apps/details?id=${1}&hl=ja"
htmlfile="$(mktemp --suffix .html)"
errfile="$(mktemp --suffix .txt)"
rmtmp="rm -f $htmlfile $errfile"
trap "$rmtmp" EXIT
wget -O "$htmlfile" "$url" 2>"$errfile" || {
$quietp || cat "$errfile" >&2
}
$echonamep && {
appname=$(sed -n -r '
/<title[^>]*>/,/<\/title[^>]*>/H
/<\/title[^>]*>/{
g
s/\n//g
s/^.*<title[^>]*>//
s/ - Google Play ....<\/title[^>]*>/\n/
P
}' "$htmlfile")
if test -n "$appname"; then
echo "$appname"
else
$echoidp && echo $1
fi
} ||
echo
$openwebp && cygstart --wait "$htmlfile"
$rmtmp
trap - EXIT
}
if $getstdinp; then
for appid in `cat -`; do
get-title "$appid"
done
else
for appid in "$@"; do
get-title "$appid"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment