Search in sources :

Example 1 with Item

use of me.michaeldick.sonosonedrive.model.Item in project SonosOneDriveServer by bertique.

the class SonosService method parseMediaListResponse.

private static MediaList parseMediaListResponse(String userId, String json) {
    JsonElement element = JsonParser.parseString(json);
    JsonArray mainResultList = element.getAsJsonObject().getAsJsonArray("value");
    if (mainResultList != null) {
        MediaList ml = new MediaList();
        List<AbstractMedia> mcList = ml.getMediaCollectionOrMediaMetadata();
        for (int i = 0; i < mainResultList.size(); i++) {
            Item m = new Item(mainResultList.get(i).getAsJsonObject());
            if (m.getType() == null) {
                logger.debug("Ignoring item with null type (e.g. .url files): " + m.getName());
            } else if (m.getType() == Item.FileType.audio || (m.getType() == Item.FileType.file && m.getName().endsWith(".flac")) || (m.getType().equals(Item.FileType.file) && m.getMimeType().contains("audio"))) {
                mcList.add(buildMMD(m));
            } else if (m.getType() == Item.FileType.folder || m.getType() == Item.FileType.file) {
                mcList.add(buildMC(m));
            }
        }
        ml.setCount(mcList.size());
        if (element.getAsJsonObject().has("@odata.count")) {
            ml.setTotal(element.getAsJsonObject().get("@odata.count").getAsInt());
            if (ml.getTotal() < 100 && ml.getTotal() > mcList.size()) {
                ml.setTotal(ml.getTotal() - 1);
            }
        } else {
            ml.setTotal(mcList.size());
        }
        logger.debug("Got program list: " + mcList.size());
        return ml;
    } else {
        return new MediaList();
    }
}
Also used : JsonArray(com.google.gson.JsonArray) MediaList(com.sonos.services._1.MediaList) Item(me.michaeldick.sonosonedrive.model.Item) RateItem(com.sonos.services._1.RateItem) JsonElement(com.google.gson.JsonElement) AbstractMedia(com.sonos.services._1.AbstractMedia)

Example 2 with Item

use of me.michaeldick.sonosonedrive.model.Item 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();
}
Also used : Item(me.michaeldick.sonosonedrive.model.Item) RateItem(com.sonos.services._1.RateItem) GraphAuth(me.michaeldick.sonosonedrive.model.GraphAuth) JsonElement(com.google.gson.JsonElement)

Example 3 with Item

use of me.michaeldick.sonosonedrive.model.Item in project SonosOneDriveServer by bertique.

the class SonosService method getMediaMetadata.

@Override
public GetMediaMetadataResponse getMediaMetadata(GetMediaMetadata parameters) throws CustomFault {
    logger.debug("getMediaMetadata id:" + parameters.getId());
    GraphAuth auth = getGraphAuth();
    String json = graphApiGetRequest("me/drive/items/" + parameters.getId(), 1, null, auth);
    JsonElement element = JsonParser.parseString(json);
    Item m = new Item(element.getAsJsonObject());
    GetMediaMetadataResponse response = new GetMediaMetadataResponse();
    response.setGetMediaMetadataResult(buildMMD(m));
    return response;
}
Also used : Item(me.michaeldick.sonosonedrive.model.Item) RateItem(com.sonos.services._1.RateItem) GraphAuth(me.michaeldick.sonosonedrive.model.GraphAuth) GetMediaMetadataResponse(com.sonos.services._1.GetMediaMetadataResponse) JsonElement(com.google.gson.JsonElement)

Aggregations

JsonElement (com.google.gson.JsonElement)3 RateItem (com.sonos.services._1.RateItem)3 Item (me.michaeldick.sonosonedrive.model.Item)3 GraphAuth (me.michaeldick.sonosonedrive.model.GraphAuth)2 JsonArray (com.google.gson.JsonArray)1 AbstractMedia (com.sonos.services._1.AbstractMedia)1 GetMediaMetadataResponse (com.sonos.services._1.GetMediaMetadataResponse)1 MediaList (com.sonos.services._1.MediaList)1