Search in sources :

Example 1 with GetMetadataResponse

use of com.sonos.services._1.GetMetadataResponse 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;
}
Also used : MediaList(com.sonos.services._1.MediaList) GraphAuth(me.michaeldick.sonosonedrive.model.GraphAuth) GetMetadataResponse(com.sonos.services._1.GetMetadataResponse) MediaCollection(com.sonos.services._1.MediaCollection) AbstractMedia(com.sonos.services._1.AbstractMedia)

Aggregations

AbstractMedia (com.sonos.services._1.AbstractMedia)1 GetMetadataResponse (com.sonos.services._1.GetMetadataResponse)1 MediaCollection (com.sonos.services._1.MediaCollection)1 MediaList (com.sonos.services._1.MediaList)1 GraphAuth (me.michaeldick.sonosonedrive.model.GraphAuth)1