Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to download an already-purchased APP. No purchase flow yet... #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/main/java/com/akdeniz/googleplaycrawler/GooglePlayAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/akdeniz/googleplaycrawler/cli/googleplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 6 additions & 0 deletions src/main/protobuf/GooglePlay.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down