use of com.sonos.services._1.MediaCollection 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 com.sonos.services._1.MediaCollection in project SonosOneDriveServer by bertique.
the class SonosService method buildMC.
private static MediaCollection buildMC(Item m) {
MediaCollection mc = new MediaCollection();
if (m.getType().equals(Item.FileType.audio) || (m.getType().equals(Item.FileType.file) && m.getName().endsWith(".flac")) || (m.getType().equals(Item.FileType.file) && m.getMimeType().contains("audio"))) {
mc.setId(SonosService.AUDIO + ":" + m.getId());
mc.setItemType(ItemType.TRACK);
if (m.getTitle() != null && !m.getTitle().isEmpty()) {
mc.setTitle(m.getTitle());
} else {
mc.setTitle(m.getName());
}
if (m.getArtist() != null) {
mc.setArtist(m.getArtist());
}
if (m.getThumbnail() != null) {
AlbumArtUrl art = new AlbumArtUrl();
art.setValue(m.getThumbnail());
mc.setAlbumArtURI(art);
}
mc.setCanPlay(true);
mc.setCanEnumerate(false);
} else if (m.getType().equals(Item.FileType.file)) {
mc.setId(SonosService.FILE + ":" + m.getId());
mc.setItemType(ItemType.OTHER);
mc.setTitle(m.getName());
mc.setCanPlay(false);
mc.setCanEnumerate(false);
} else if (m.getType().equals(Item.FileType.folder)) {
mc.setId(SonosService.FOLDER + ":" + m.getId());
mc.setItemType(ItemType.COLLECTION);
mc.setTitle(m.getName());
if (m.getChildCount() < 40) {
mc.setCanPlay(true);
} else {
mc.setCanPlay(false);
}
mc.setCanEnumerate(true);
}
return mc;
}
Aggregations