Search in sources :

Example 1 with ContentDirectoryException

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());
    }
}
Also used : ContentDirectoryException(org.fourthline.cling.support.contentdirectory.ContentDirectoryException)

Example 2 with ContentDirectoryException

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);
}
Also used : Item(org.fourthline.cling.support.model.item.Item) Container(org.fourthline.cling.support.model.container.Container) DIDLParser(org.fourthline.cling.support.contentdirectory.DIDLParser) ContentDirectoryException(org.fourthline.cling.support.contentdirectory.ContentDirectoryException) DIDLContent(org.fourthline.cling.support.model.DIDLContent) BrowseResult(org.fourthline.cling.support.model.BrowseResult) ContentDirectoryException(org.fourthline.cling.support.contentdirectory.ContentDirectoryException)

Aggregations

ContentDirectoryException (org.fourthline.cling.support.contentdirectory.ContentDirectoryException)2 DIDLParser (org.fourthline.cling.support.contentdirectory.DIDLParser)1 BrowseResult (org.fourthline.cling.support.model.BrowseResult)1 DIDLContent (org.fourthline.cling.support.model.DIDLContent)1 Container (org.fourthline.cling.support.model.container.Container)1 Item (org.fourthline.cling.support.model.item.Item)1