From d4913449004b3d29b14bea8286ecb8336ed73aab Mon Sep 17 00:00:00 2001 From: Zhanglei Wang Date: Fri, 5 Jul 2013 12:48:36 -0700 Subject: [PATCH] Added support to download an already-purchased APP. No purchase flow yet! --- .../googleplaycrawler/GooglePlayAPI.java | 20 ++++++++++++++++--- .../googleplaycrawler/cli/googleplay.java | 12 ++++++----- src/main/protobuf/GooglePlay.proto | 6 ++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/akdeniz/googleplaycrawler/GooglePlayAPI.java b/src/main/java/com/akdeniz/googleplaycrawler/GooglePlayAPI.java index f5abc01..6af56bf 100644 --- a/src/main/java/com/akdeniz/googleplaycrawler/GooglePlayAPI.java +++ b/src/main/java/com/akdeniz/googleplaycrawler/GooglePlayAPI.java @@ -72,6 +72,7 @@ public class GooglePlayAPI { private static final String REVIEWS_URL = FDFE_URL + "rev"; private static final String UPLOADDEVICECONFIG_URL = FDFE_URL + "uploadDeviceConfig"; private static final String RECOMMENDATIONS_URL = FDFE_URL + "rec"; + private static final String DELIVERY_URL = FDFE_URL + "delivery"; private static final String ACCOUNT_TYPE_HOSTED_OR_GOOGLE = "HOSTED_OR_GOOGLE"; @@ -310,11 +311,24 @@ public InputStream download(String packageName, int versionCode, int offerType) AndroidAppDeliveryData appDeliveryData = buyResponse.getPurchaseStatusResponse().getAppDeliveryData(); String downloadUrl = appDeliveryData.getDownloadUrl(); - HttpCookie downloadAuthCookie = appDeliveryData.getDownloadAuthCookie(0); + try { + HttpCookie downloadAuthCookie = appDeliveryData.getDownloadAuthCookie(0); + return executeDownload(downloadUrl, downloadAuthCookie.getName() + "=" + downloadAuthCookie.getValue()); + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } - return executeDownload(downloadUrl, downloadAuthCookie.getName() + "=" + downloadAuthCookie.getValue()); + public InputStream delivery (String packageName, int versionCode, int offerType) throws IOException { + ResponseWrapper responseWrapper = executeGETRequest(DELIVERY_URL, new String[][] { { "ot", String.valueOf(offerType) }, + { "doc", packageName }, { "vc", String.valueOf(versionCode) }, }); - } + AndroidAppDeliveryData appDeliveryData = responseWrapper.getPayload().getDeliveryResponse().getAppDeliveryData(); + String downloadUrl = appDeliveryData.getDownloadUrl(); + HttpCookie downloadAuthCookie = appDeliveryData.getDownloadAuthCookie(0); + + return executeDownload(downloadUrl, downloadAuthCookie.getName() + "=" + downloadAuthCookie.getValue()); + } /** * Posts given check-in request content and returns diff --git a/src/main/java/com/akdeniz/googleplaycrawler/cli/googleplay.java b/src/main/java/com/akdeniz/googleplaycrawler/cli/googleplay.java index 9533ce6..ee70b13 100644 --- a/src/main/java/com/akdeniz/googleplaycrawler/cli/googleplay.java +++ b/src/main/java/com/akdeniz/googleplaycrawler/cli/googleplay.java @@ -581,15 +581,17 @@ private void download(String packageName) throws IOException { int offerType = offer.getOfferType(); boolean checkoutRequired = offer.getCheckoutFlowRequired(); + System.out.println("Downloading..." + appDetails.getPackageName() + " : " + installationSize + " bytes"); + InputStream downloadStream; + // paid application...ignore if (checkoutRequired) { - System.out.println("Checkout required! Ignoring.." + appDetails.getPackageName()); - return; + System.out.println("Checkout required! Assuming you have already purchased it, use the delivery flow for " + appDetails.getPackageName()); + downloadStream = service.delivery(appDetails.getPackageName(), versionCode, offerType); + } else { + downloadStream = service.download(appDetails.getPackageName(), versionCode, offerType); } - System.out.println("Downloading..." + appDetails.getPackageName() + " : " + installationSize + " bytes"); - InputStream downloadStream = service.download(appDetails.getPackageName(), versionCode, offerType); - FileOutputStream outputStream = new FileOutputStream(appDetails.getPackageName() + ".apk"); byte buffer[] = new byte[1024]; diff --git a/src/main/protobuf/GooglePlay.proto b/src/main/protobuf/GooglePlay.proto index 81f2d70..b6a688b 100755 --- a/src/main/protobuf/GooglePlay.proto +++ b/src/main/protobuf/GooglePlay.proto @@ -156,6 +156,11 @@ message BuyResponse { optional string purchaseCookie = 46; optional Challenge challenge = 49; } + +message DeliveryResponse { + optional AndroidAppDeliveryData appDeliveryData = 2; +} + message Challenge { optional AddressChallenge addressChallenge = 1; optional AuthenticationChallenge authenticationChallenge = 2; @@ -757,6 +762,7 @@ message Payload { optional BulkDetailsResponse bulkDetailsResponse = 19; optional UploadDeviceConfigResponse uploadDeviceConfigResponse = 25; optional AndroidCheckinResponse androidCheckinResponse = 26; + optional DeliveryResponse deliveryResponse = 21; } message PreFetch { optional string url = 1;