use of me.michaeldick.sonosonedrive.model.GraphAuth in project SonosOneDriveServer by bertique.
the class SonosService method getMetadata.
@Override
public GetMetadataResponse getMetadata(GetMetadata parameters) throws CustomFault {
logger.debug("getMetadata id:" + parameters.getId() + " count:" + parameters.getCount() + " index:" + parameters.getIndex());
GraphAuth auth = getGraphAuth();
// Mixpanel event
// if(parameters.getId().equals(SonosService.PROGRAM+":"+SonosService.DEFAULT)
// || parameters.getId().equals(ItemType.SEARCH.value())) {
//
// JSONObject props = new JSONObject();
// try {
// props.put("Program", parameters.getId());
// } catch (JSONException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// sentMetricsEvent(auth.getHouseholdId(), "getMetadata", props);
// }
GetMetadataResponse response = new GetMetadataResponse();
MediaList ml = new MediaList();
if (parameters.getId().equals("root")) {
String path = DRIVE_ROOT + "/children";
if (isAppFolder()) {
path = DRIVE_APPFOLDER + "/children";
}
String skipToken = null;
if (parameters.getIndex() > 0) {
skipToken = getSkipToken(path, parameters.getIndex(), auth);
}
String json = graphApiGetRequest(path, parameters.getCount(), skipToken, auth);
ml = parseMediaListResponse(auth.getHouseholdId(), json);
} else if (parameters.getId().startsWith(SonosService.FOLDER)) {
String path = String.format("/me/drive/items/%s/children", parameters.getId().replaceAll(SonosService.FOLDER + ":", ""));
String skipToken = null;
if (parameters.getIndex() > 0) {
skipToken = getSkipToken(path, parameters.getIndex(), auth);
}
String json = graphApiGetRequest(path, parameters.getCount(), skipToken, auth);
ml = parseMediaListResponse(auth.getHouseholdId(), json);
} else if (parameters.getId().equals(ItemType.SEARCH.value())) {
List<AbstractMedia> mcList = ml.getMediaCollectionOrMediaMetadata();
MediaCollection mc1 = new MediaCollection();
mc1.setTitle("Files");
mc1.setId(SonosService.FILES);
mc1.setItemType(ItemType.SEARCH);
mc1.setCanPlay(false);
mcList.add(mc1);
ml.setCount(mcList.size());
ml.setTotal(mcList.size());
} else {
return null;
}
ml.setIndex(parameters.getIndex());
response.setGetMetadataResult(ml);
logger.info(auth.getHouseholdId().hashCode() + ": Got Metadata for " + parameters.getId() + ", " + response.getGetMetadataResult().getCount() + " Index:" + ml.getIndex() + " Count:" + ml.getCount() + " Total: " + ml.getTotal());
return response;
}
use of me.michaeldick.sonosonedrive.model.GraphAuth in project SonosOneDriveServer by bertique.
the class SonosService method search.
@Override
public SearchResponse search(Search parameters) throws CustomFault {
logger.debug("search");
GraphAuth auth = getGraphAuth();
String path = String.format("/me/drive/root/search(q='%s')", parameters.getTerm());
String skipToken = null;
if (parameters.getIndex() > 0) {
skipToken = getSkipToken(path, parameters.getIndex(), auth);
}
String json = graphApiGetRequest(path, parameters.getCount(), skipToken, auth);
SearchResponse response = new SearchResponse();
MediaList ml = new MediaList();
ml = parseMediaListResponse(auth.getHouseholdId(), json);
// Remove 1 since personal vault is not included in response
ml.setTotal(ml.getTotal());
ml.setIndex(parameters.getIndex());
response.setSearchResult(ml);
return response;
}
use of me.michaeldick.sonosonedrive.model.GraphAuth in project SonosOneDriveServer by bertique.
the class SonosService method getGraphAuth.
private GraphAuth getGraphAuth() {
Credentials creds = getCredentialsFromHeaders();
if (creds == null)
throwSoapFault(SESSION_INVALID);
logger.debug("Got userId from header:" + creds.getLoginToken().getHouseholdId());
String access_token = null;
if (creds.getLoginToken().getToken().startsWith("{") && creds.getLoginToken().getToken().contains("###")) {
String[] tokenParts = creds.getLoginToken().getToken().split("###");
if (tokenParts.length == 3) {
byte[] encodedFirstTokenPart = Base64.getEncoder().encode(tokenParts[0].getBytes());
byte[] encodedSecondTokenPart = Base64.getEncoder().encode(tokenParts[1].getBytes());
access_token = String.format("%s.%s.%s", new String(encodedFirstTokenPart).replace("=", ""), new String(encodedSecondTokenPart).replace("=", ""), tokenParts[2]);
} else {
throwSoapFault(NOT_LINKED_FAILURE);
}
} else {
access_token = creds.getLoginToken().getToken();
}
return new GraphAuth(creds.getLoginToken().getHouseholdId(), access_token, creds.getLoginToken().getKey());
}
use of me.michaeldick.sonosonedrive.model.GraphAuth in project SonosOneDriveServer by bertique.
the class SonosService method getMediaURI.
@Override
public void getMediaURI(String id, MediaUriAction action, Integer secondsSinceExplicit, Holder<String> deviceSessionToken, Holder<String> getMediaURIResult, Holder<EncryptionContext> deviceSessionKey, Holder<EncryptionContext> contentKey, Holder<HttpHeaders> httpHeaders, Holder<Integer> uriTimeout, Holder<PositionInformation> positionInformation, Holder<String> privateDataFieldName) throws CustomFault {
logger.debug("getMediaURI id:" + id);
GraphAuth auth = getGraphAuth();
String json = graphApiGetRequest("me/drive/items/" + id.replaceAll(SonosService.AUDIO + ":", "") + "", 1, null, auth);
JsonElement element = JsonParser.parseString(json);
Item m = new Item(element.getAsJsonObject());
getMediaURIResult.value = m.getFileUri();
}
use of me.michaeldick.sonosonedrive.model.GraphAuth in project SonosOneDriveServer by bertique.
the class SonosService method getLastUpdate.
@Override
public LastUpdate getLastUpdate() throws CustomFault {
logger.debug("getLastUpdate");
GraphAuth auth = getGraphAuth();
sentMetricsEvent(auth.getHouseholdId(), "getLastUpdate", null);
String path = DRIVE_ROOT + "/delta";
String json = graphApiGetRequest(path, 1, null, auth);
LastUpdate response = new LastUpdate();
JsonElement element = JsonParser.parseString(json);
JsonArray mainResultList = element.getAsJsonObject().getAsJsonArray("value");
String lastUpdate = null;
if (mainResultList != null && mainResultList.size() > 0) {
lastUpdate = mainResultList.get(0).getAsJsonObject().get("lastModifiedDateTime").getAsString();
}
logger.debug("Last modifed: " + lastUpdate);
response.setCatalog(lastUpdate);
return response;
}
Aggregations