def download(): package = args.package filename = package + ".apk" # Connect api = GooglePlayAPI(args.device, lang='en_US') api.login(args.email, args.password, None) # Get the version code and the offer type from the app details m = api.details(package) doc = m.docV2 vc = doc.details.appDetails.versionCode ot = doc.offer[0].offerType # Download if args.target_arch: str_target_arch = '-%s' % args.target_arch else: str_target_arch = '' filename = '%s%s-%s.apk' % (get_datetime(), str_target_arch, package) dir_out = args.dir_out if dir_out: filename = dir_out + '/' + filename data = api.download(package, vc, ot) open(filename, "wb").write(data)
def run(packagename): if (len(sys.argv) == 3): filename = sys.argv[2] else: filename = packagename + ".apk" # Connect api = GooglePlayAPI(config.ANDROID_ID) api.login(config.GOOGLE_LOGIN, config.GOOGLE_PASSWORD, config.AUTH_TOKEN) # Get the version code and the offer type from the app details m = api.details(packagename) doc = m.docV2 vc = doc.details.appDetails.versionCode ot = doc.offer[0].offerType # Download print "Downloading %s..." % sizeof_fmt( doc.details.appDetails.installationSize), data = api.download(packagename, vc, ot) open(filename, "wb").write(data) print "Done"
class Downloader(): def __init__(self): self.api = GooglePlayAPI(ANDROID_ID) self.api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) def download(self, pkg, filename): doc = self.api.details(pkg).docV2 vc = doc.details.appDetails.versionCode data = self.api.download(pkg, vc) with open(filename, 'wb') as apk: apk.write(data) def downloadall(self, dbname, outdir, maxsize=None): mkdir(outdir) with sqlite3.connect(dbname, timeout=10) as db: with closing(db.cursor()) as cur: cur.execute(create) for pkg, size in cur.execute(select).fetchall(): print 'Processing %s (%s) ...' % (pkg, size) if not sizeallowed(size, maxsize): print Fore.YELLOW + ' [SKIP: too big (%s)]' % size continue path = os.path.join(outdir, pkg + '.apk') try: self.download(pkg, path) except Exception as e: print Fore.RED + ' [ERROR: %s]' % e.message else: print Fore.GREEN + ' [OK: downloaded to %s]' % path cur.execute(insert, (pkg, path)) db.commit()
def download_sdk_to_file(packagename, filename): # Connect api = GooglePlayAPI(ANDROID_ID) api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) # Download data = api.download(packagename) with open(filename, "wb") as f: f.write(data)
def scrape(id, package): packagename = package res = urllib2.urlopen("https://play.google.com/store/apps/details?id=%s&hl=en" % packagename) html = res.read() path = "assets/%d/" % id if not os.path.exists(path): os.makedirs(path) name = html.split('itemprop="name"')[1].split("</div>")[0].split("<div>")[1] desc = html.split('<div class="show-more-content text-body" itemprop="description">')[1].split( '<div class="show-more-end">' )[0] rating = html.split("Rated ")[1].split(" stars")[0] category = html.split('<span itemprop="genre">')[1].split("</span>")[0] stuff = [] for line in html.split("</div>"): if "full-screenshot" in line: url = line.split('src="')[1][:-3] stuff.append(url) x = 0 for img in stuff[1:]: print img urllib.urlretrieve(img, "%s%d.webp" % (path, x)) x += 1 filename = path + packagename + ".apk" # Connect api = GooglePlayAPI(ANDROID_ID) api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) # Get the version code and the offer type from the app details m = api.details(packagename) doc = m.docV2 vc = doc.details.appDetails.versionCode ot = doc.offer[0].offerType # Download print "Downloading %s..." % sizeof_fmt(doc.details.appDetails.installationSize), data = api.download(packagename, vc, ot) open(filename, "wb").write(data) print "Done" ap = apk.APK(filename) badging = os.popen("/home/thomas/dev/android-odroid/out/host/linux-x86/bin/aapt dump badging %s" % filename).read() for line in badging.split("\n"): if "launchable-activity" in line: activity = line.split("'")[1] return [name, desc, rating, package, activity, category]
def download_apk(packagename, filename): # Connect api = GooglePlayAPI(ANDROID_ID) api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) # Get the version code and the offer type from the app details m = api.details(packagename) doc = m.docV2 vc = doc.details.appDetails.versionCode ot = doc.offer[0].offerType # Download print "Downloading %s..." % sizeof_fmt(doc.details.appDetails.installationSize), data = api.download(packagename, vc, ot) open(filename, "wb").write(data) print "Done"
exit(1) doc = m.docV2 vc = doc.details.appDetails.versionCode # Set the version code if (len(sys.argv) == 3): vc = int(sys.argv[2]) else: vc = doc.details.appDetails.versionCode # Genarate the filename with version code if (len(sys.argv) == 4): filename = sys.argv[3] + ".vc" + str(vc) + ".apk" else: filename = packagename + ".vc" + str(vc) + ".apk" ot = doc.offer[0].offerType # Download print "versionCode:%d Downloading %s..." % (vc, sizeof_fmt(doc.details.appDetails.installationSize),) data = api.download(packagename, vc, ot) if data == False: print 'error in api.download' sys.exit(1) open(filename, "wb").write(data) print "Done"
if (len(sys.argv) < 2): print "Usage: %s packagename [filename]" print "Download an app." print "If filename is not present, will write to packagename.apk." sys.exit(0) packagename = sys.argv[1] if (len(sys.argv) == 3): filename = sys.argv[2] else: filename = packagename + ".apk" # Connect api = GooglePlayAPI("3eded73a231f2845") api.login("*****@*****.**", "gruegrue", AUTH_TOKEN) # Get the version code and the offer type from the app details m = api.details(packagename) doc = m.docV2 vc = doc.details.appDetails.versionCode ot = doc.offer[0].offerType # Download print "Downloading %s..." % sizeof_fmt( doc.details.appDetails.installationSize), data = api.download(packagename, vc, ot) open(filename, "wb").write(data) print "Done"
class GoogleAnalysis(object): """docstring for GoogleAnalysis.""" def __init__(self): super(GoogleAnalysis, self).__init__() self.api = GooglePlayAPI(ANDROID_ID) self.api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) def category_list(self): response = self.api.browse() return list( map( lambda c: SEPARATOR.join( i.encode('utf8') for i in [urlparse.parse_qs(c.dataUrl)['browse?cat'][0]]), response.category)) def read_files(self, cate): with open(dirname(__file__) + '/resource_list/' + cate + '.txt', 'r') as f: for line in f.readlines(): filename = line.strip() print Color.Green + '[!] Start: ' + Color.NoCo + filename self.details(filename) def details(self, packageName): message = self.api.details(packageName).docV2 result = { "docid": message.docid, "title": message.title, "creator": message.creator, "descriptionHtml": message.descriptionHtml, "offer": { "currencyCode": message.offer[0].currencyCode, "formattedAmount": message.offer[0].formattedAmount }, "details": { "appDetails": { "developerName": message.details.appDetails.developerName, "versionCode": message.details.appDetails.versionCode, "versionString": message.details.appDetails.versionString, "contentRating": message.details.appDetails.contentRating, "installationSize": message.details.appDetails.installationSize, # "permission": message.details.appDetails.permission, "numDownloads": message.details.appDetails.numDownloads, "packageName": message.details.appDetails.packageName, "uploadDate": message.details.appDetails.uploadDate, } }, "aggregateRating": { "starRating": message.aggregateRating.starRating, "ratingsCount": message.aggregateRating.ratingsCount, "oneStarRatings": message.aggregateRating.oneStarRatings, "twoStarRatings": message.aggregateRating.twoStarRatings, "threeStarRatings": message.aggregateRating.threeStarRatings, "fourStarRatings": message.aggregateRating.fourStarRatings, "fiveStarRatings": message.aggregateRating.fiveStarRatings, "commentCount": message.aggregateRating.commentCount } } doc = message vc = doc.details.appDetails.versionCode ot = doc.offer[0].offerType self.download(packageName, vc, ot) with open( dirname(abspath(__file__)) + '/detail_reports/' + packageName, 'w') as f: json.dump(result, f, sort_keys=True, indent=4, separators=(',', ': ')) f.close() # print json.dumps(result, sort_keys=True, indent=4, separators=(',', ': ')) def download(self, packageName, vc, ot): data = self.api.download(packageName, vc, ot) with open( dirname(abspath(__file__)) + '/apk_files/' + packageName + '.apk', 'w') as f: f.write(data) print "Done" f.close() def test(self): lists = list('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c') for i in lists: try: print self.api.list('ART_AND_DESIGN', 'apps_topselling_free', '1', 'CA' + i) except: print i
# print i.details.appDetails.packageName # APK version result['version'] = i.details.appDetails.versionCode # print i.details.appDetails.versionCode # APK size result['size'] = sizeof_fmt(i.details.appDetails.installationSize) # print sizeof_fmt(i.details.appDetails.installationSize) # Upload date result['upload_date'] = datetime.strptime(unicode(i.details.appDetails.uploadDate).encode('utf8'), locale_timestring[LANG]).strftime('%Y-%m-%d') # print datetime.strptime(unicode(i.details.appDetails.uploadDate).encode('utf8'), # "%Y\345\271\264%m\346\234\210%d\346\227\245").strftime('%Y-%m-%d') # Download APK result['apkdata'] = api.download(i.details.appDetails.packageName, i.details.appDetails.versionCode, i.offer[0].offerType) result.update(File(result['apkdata']).result) rank += 1 try: DB().insert_apk(result) except KeyError: logging.warn("Maybe the apk already exists: {}".format(result['pgname'])) # continue raise except: logging.error("DB insert error: {}".format(result['pgname'])) raise """ if ctr is None:
import requests api = GooglePlayAPI(ANDROID_ID) api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) package_name = "com.tellm.android.app" r = api.details(package_name) version = r.docV2.details.appDetails.versionString date = r.docV2.details.appDetails.uploadDate version_code = r.docV2.details.appDetails.versionCode file_size = r.docV2.details.appDetails.installationSize print "current version is ", version, "published on ", date f_name = "/root/jodeldecompile/apks/com.tellm.android.app-%s.apk" % version if os.path.isfile(f_name) and os.path.getsize(f_name) == file_size: print "already downloaded" else: print "downloading apk to %s" % f_name data = api.download(package_name, version_code) with open(f_name, "wb") as f: f.write(data) if len(data) != file_size: print("WARNING: file sizes don't match. downloaded %d, should be %d" % (len(data), file_size)) else: print "written %d bytes" % len(data)
def download_apk_via_url(apk): GOOGLE_LOGIN = "******" GOOGLE_PASSWORD = "******" AUTH_TOKEN = "aAX_7XGsaT4B5hIDvtdh8oM-R7B5iidTCgHxXOKQXXFDFdmdzPcXKslTr6SX0YpiDMIORA." f = 0 head, sep, tail = apk.partition('&') apk = head msg = "" if "." in apk: if (apk.startswith('http')): if "play.google.com/store/apps/details?id=" in apk: print "Link:" + apk link, packagename = apk.split("=") else: message = "Wrong URL!" return message else: packagename = apk else: message = "Invalid Package Name" return message if (len(sys.argv) == 3): filename = sys.argv[2] else: filename = packagename + ".apk" print("Package Name: " + packagename) # Connect requests.packages.urllib3.disable_warnings(InsecureRequestWarning) api = GooglePlayAPI(ANDROID_ID) api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) try: # Get the version code and the offer type from the app details m = api.details(packagename) doc = m.docV2 vc = doc.details.appDetails.versionCode ot = doc.offer[0].offerType size = sizeof_fmt(doc.details.appDetails.installationSize) l = len(size) ext = size[(l - 2):l] size = size[:-2] if ext == "MB": f = float(size) if ext == "GB": f = float(size) * 1024 if f > float(200): message = "App Size is Greater than 200MB. Please Enter a Different URL or Package Name" return message # Download print "Downloading %s..." % sizeof_fmt( doc.details.appDetails.installationSize), data, msg = api.download(packagename, vc, ot) DIR = settings.BASE_DIR ANAL_DIR = os.path.join(DIR) fullpath = ANAL_DIR + '/uploads/' + packagename + ".apk" open(fullpath, "wb").write(data) print "APK Downloaded!" return fullpath except Exception as e: print "Not able to fetch the apk: {}".format(e) if "Google Play purchases are not supported in your country" in msg: message = """App region isn't supported by the platform.""" elif "does not support this purchase." in msg: message = """The platform doesn't support paid app download.""" else: message = "Sorry! We are not able to fetch the APK at this moment. Please upload the APK." return message