use of org.fourthline.cling.support.contentdirectory.ContentDirectoryException in project libresonic by Libresonic.
the class FolderBasedContentDirectory method browse.
@Override
public BrowseResult browse(String objectId, BrowseFlag browseFlag, String filter, long firstResult, long maxResults, SortCriterion[] orderby) throws ContentDirectoryException {
LOG.info("UPnP request - objectId: " + objectId + ", browseFlag: " + browseFlag + ", filter: " + filter + ", firstResult: " + firstResult + ", maxResults: " + maxResults);
// maxResult == 0 means all.
if (maxResults == 0) {
maxResults = Integer.MAX_VALUE;
}
try {
if (CONTAINER_ID_ROOT.equals(objectId)) {
return browseFlag == BrowseFlag.METADATA ? browseRootMetadata() : browseRoot(firstResult, maxResults);
}
if (CONTAINER_ID_PLAYLIST_ROOT.equals(objectId)) {
return browseFlag == BrowseFlag.METADATA ? browsePlaylistRootMetadata() : browsePlaylistRoot(firstResult, maxResults);
}
if (objectId.startsWith(CONTAINER_ID_PLAYLIST_PREFIX)) {
int playlistId = Integer.parseInt(objectId.replace(CONTAINER_ID_PLAYLIST_PREFIX, ""));
Playlist playlist = playlistService.getPlaylist(playlistId);
return browseFlag == BrowseFlag.METADATA ? browsePlaylistMetadata(playlist) : browsePlaylist(playlist, firstResult, maxResults);
}
int mediaFileId = Integer.parseInt(objectId.replace(CONTAINER_ID_FOLDER_PREFIX, ""));
MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId);
return browseFlag == BrowseFlag.METADATA ? browseMediaFileMetadata(mediaFile) : browseMediaFile(mediaFile, firstResult, maxResults);
} catch (Throwable x) {
LOG.error("UPnP error: " + x, x);
throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, x.toString());
}
}
use of org.fourthline.cling.support.contentdirectory.ContentDirectoryException in project BeyondUPnP by kevinshine.
the class BeyondContentDirectoryService method browse.
@Override
public BrowseResult browse(String objectID, BrowseFlag browseFlag, String filter, long firstResult, long maxResults, SortCriterion[] orderby) throws ContentDirectoryException {
String address = Utils.getIPAddress(true);
String serverUrl = "http://" + address + ":" + JettyResourceServer.JETTY_SERVER_PORT;
//Create container by id
Container resultBean = ContainerFactory.createContainer(objectID, serverUrl);
DIDLContent content = new DIDLContent();
for (Container c : resultBean.getContainers()) content.addContainer(c);
for (Item item : resultBean.getItems()) content.addItem(item);
int count = resultBean.getChildCount();
String contentModel = "";
try {
contentModel = new DIDLParser().generate(content);
} catch (Exception e) {
throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, e.toString());
}
return new BrowseResult(contentModel, count, count);
}
Aggregations