Skip to content

Instantly share code, notes, and snippets.

@arulrajnet
Last active December 13, 2023 20:33
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save arulrajnet/d50d0e81eaa354297347 to your computer and use it in GitHub Desktop.
Save arulrajnet/d50d0e81eaa354297347 to your computer and use it in GitHub Desktop.
Script to download apk file from Google Play a.k.a Android Market.
#!/bin/bash
#
# Script to download apk file from Google Play a.k.a Android Market.
# Accepts package name or Google Play URL as input.
# Files are download from apk-dl.com
# author : Arul (@arulrajnet)
#
APK_DL_URL="http://apk-dl.com/store/apps/details?id=%s"
PACKAGE_NAME=""
# Parse the user given input
function parse() {
# TODO for parse package and google play url
package_re="/^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/i"
if [[ $1 =~ $package_re ]]; then
echo ${BASH_REMATCH[1]}
fi
url_re="*play.google.com/store/apps/details?id=*"
PACKAGE_NAME=$1
}
# Download the apk file
function download() {
echo -e "Downloading..."
local ua="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36"
local url=`printf ${APK_DL_URL} ${PACKAGE_NAME}`
curl "$url" -o "$PACKAGE_NAME.apk" --write-out "%{http_code}" --compressed --retry 10 --retry-max-time 0 \
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \
-H "Connection: keep-alive" -H "Accept-Encoding: gzip,deflate,sdch" \
-H "Accept-Language: en-US,en;q=0.8,ta;q=0.6" \
-H "User-Agent: $ua"
}
# Validate basic requirement for this script
function validate() {
# Commands used in this script
local CMDS="curl"
for i in ${CMDS}
do
type -P ${i} &>/dev/null && continue || { echo "$i command not found."; exit 1; }
done
}
function usage() {
echo -e "Usage: \n\t$0 com.whatsapp \n\t$0 https://play.google.com/store/apps/details?id=com.whatsapp"
exit 1
}
# How its called
if test -z "$1"
then
usage
fi
validate
parse $1
download ${PACKAGE_NAME}
exit 0
@wjk20120522
Copy link

Hi, thanks for your scripts. I try to use your scripts to download an apk file, but got an error: connection reset by peer. Is it my network problem or the scripts?

@arulrajnet
Copy link
Author

Which apk you are trying to download.?

@sanjaykumar2338
Copy link

Hi
Its giving me error

( ! ) Parse error: syntax error, unexpected '=' in /var/www/default/public_html/sanjay/index.php on line 10

I need php script to download a file from google play store.

@DJwa163
Copy link

DJwa163 commented Nov 16, 2015

Dear sir,
can you please reshape this script as a Greasemonkey script (for Firefox)?
More info here
https://greasyfork.org/en

@zollic
Copy link

zollic commented Dec 22, 2015

Dear Sir,
Could you please give me some advice to use this code please.
I need to adapt with my senior project.
would be my pleasure that you could help me.
I stuck for a long time.
Thank a alot

@A-Garrido5
Copy link

I,m sorry but the script doesn't download the apk. Only creates html file with apk extension. Can you help me to solve this please?

@iamtayyabrashid
Copy link

hi,
i need a script for making Repository site for android apps(apk). the script i am looking for is to use getting fresh data from Playstore and save into my cloud and then automaticly publish on my site.
can you help me for this script

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