org.fourthline.cling.support.contentdirectory.ContentDirectoryException Java Examples

The following examples show how to use org.fourthline.cling.support.contentdirectory.ContentDirectoryException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DispatchingContentDirectory.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@Override
public BrowseResult search(String containerId,
                           String searchCriteria, String filter,
                           long firstResult, long maxResults,
                           SortCriterion[] orderBy) throws ContentDirectoryException {
    // i don't see a parser for upnp search criteria anywhere, so this will
    // have to do
    String upnpClass = searchCriteria.replaceAll("^.*upnp:class\\s+[\\S]+\\s+\"([\\S]*)\".*$", "$1");
    String titleSearch = searchCriteria.replaceAll("^.*dc:title\\s+[\\S]+\\s+\"([\\S]*)\".*$", "$1");
    BrowseResult returnValue = null;
    if ("object.container.person.musicArtist".equalsIgnoreCase(upnpClass)) {
        returnValue = getArtistProcessor().searchByName(titleSearch, firstResult, maxResults, orderBy);
    } else if ("object.item.audioItem".equalsIgnoreCase(upnpClass)) {
        returnValue = getMediaFileProcessor().searchByName(titleSearch, firstResult, maxResults, orderBy);
    } else if ("object.container.album.musicAlbum".equalsIgnoreCase(upnpClass)) {
        returnValue = getAlbumProcessor().searchByName(titleSearch, firstResult, maxResults, orderBy);
    }

    return returnValue != null ? returnValue : super.search(containerId, searchCriteria, filter, firstResult, maxResults, orderBy);
}
 
Example #2
Source File: DispatchingContentDirectory.java    From airsonic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public BrowseResult search(String containerId,
                           String searchCriteria, String filter,
                           long firstResult, long maxResults,
                           SortCriterion[] orderBy) throws ContentDirectoryException {
    // i don't see a parser for upnp search criteria anywhere, so this will
    // have to do
    String upnpClass = searchCriteria.replaceAll("^.*upnp:class\\s+[\\S]+\\s+\"([\\S]*)\".*$", "$1");
    String titleSearch = searchCriteria.replaceAll("^.*dc:title\\s+[\\S]+\\s+\"([\\S]*)\".*$", "$1");
    BrowseResult returnValue = null;
    if ("object.container.person.musicArtist".equalsIgnoreCase(upnpClass)) {
        returnValue = getArtistProcessor().searchByName(titleSearch, firstResult, maxResults, orderBy);
    } else if ("object.item.audioItem".equalsIgnoreCase(upnpClass)) {
        returnValue = getMediaFileProcessor().searchByName(titleSearch, firstResult, maxResults, orderBy);
    } else if ("object.container.album.musicAlbum".equalsIgnoreCase(upnpClass)) {
        returnValue = getAlbumProcessor().searchByName(titleSearch, firstResult, maxResults, orderBy);
    }

    return returnValue != null ? returnValue : super.search(containerId, searchCriteria, filter, firstResult, maxResults, orderBy);
}
 
Example #3
Source File: BeyondContentDirectoryService.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: CustomContentDirectory.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BrowseResult search(String containerId,
                           String searchCriteria, String filter,
                           long firstResult, long maxResults,
                           SortCriterion[] orderBy) throws ContentDirectoryException {
    // You can override this method to implement searching!
    return super.search(containerId, searchCriteria, filter, firstResult, maxResults, orderBy);
}
 
Example #5
Source File: FolderBasedContentDirectory.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@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());
    }
}
 
Example #6
Source File: CustomContentDirectory.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BrowseResult search(String containerId,
                           String searchCriteria, String filter,
                           long firstResult, long maxResults,
                           SortCriterion[] orderBy) throws ContentDirectoryException {
    // You can override this method to implement searching!
    return super.search(containerId, searchCriteria, filter, firstResult, maxResults, orderBy);
}
 
Example #7
Source File: FolderBasedContentDirectory.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
@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());
    }
}
 
Example #8
Source File: SubsonicContentDirectory.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BrowseResult search(String containerId,
                           String searchCriteria, String filter,
                           long firstResult, long maxResults,
                           SortCriterion[] orderBy) throws ContentDirectoryException {
    // You can override this method to implement searching!
    return super.search(containerId, searchCriteria, filter, firstResult, maxResults, orderBy);
}
 
Example #9
Source File: FolderBasedContentDirectory.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BrowseResult browse(String objectId, BrowseFlag browseFlag, String filter, long firstResult,
        long maxResults, SortCriterion[] orderby) throws ContentDirectoryException {

    if (!settingsService.getLicenseInfo().isLicenseOrTrialValid()) {
        LOG.warn("UPnP/DLNA media server not available. Please upgrade to Subsonic Premium.");
        throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, "Please upgrade to Subsonic Premium");
    }

    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());
    }
}
 
Example #10
Source File: ContentDirectoryService.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BrowseResult search(String containerId, String searchCriteria,
		String filter, long firstResult, long maxResults,
		SortCriterion[] orderBy) throws ContentDirectoryException {
	// You can override this method to implement searching!
	return super.search(containerId, searchCriteria, filter, firstResult,
			maxResults, orderBy);
}
 
Example #11
Source File: DispatchingContentDirectory.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
@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);

    if (objectId == null)
        throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, "objectId is null");

    // maxResult == 0 means all.
    if (maxResults == 0) {
        maxResults = Long.MAX_VALUE;
    }

    BrowseResult returnValue = null;
    try {
        String[] splitId = objectId.split(SEPARATOR);
        String browseRoot = splitId[0];
        String itemId = splitId.length == 1 ? null : splitId[1];

        UpnpContentProcessor processor = findProcessor(browseRoot);
        if (processor == null) {
            // if it's null then assume it's a file, and that the id
            // is all that's there.
            itemId = browseRoot;
            processor = getMediaFileProcessor();
        }

        if (itemId == null) {
            returnValue = browseFlag == BrowseFlag.METADATA ? processor.browseRootMetadata() : processor.browseRoot(filter, firstResult, maxResults, orderBy);
        } else {
            returnValue = browseFlag == BrowseFlag.METADATA ? processor.browseObjectMetadata(itemId) : processor.browseObject(itemId, filter, firstResult, maxResults, orderBy);
        }
        return returnValue;
    } catch (Throwable x) {
        LOG.error("UPnP error: " + x, x);
        throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, x.toString());
    }
}
 
Example #12
Source File: DispatchingContentDirectory.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
@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);

    if (objectId == null)
        throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, "objectId is null");

    // maxResult == 0 means all.
    if (maxResults == 0) {
        maxResults = Long.MAX_VALUE;
    }

    BrowseResult returnValue = null;
    try {
        String[] splitId = objectId.split(SEPARATOR);
        String browseRoot = splitId[0];
        String itemId = splitId.length == 1 ? null : splitId[1];

        UpnpContentProcessor processor = findProcessor(browseRoot);
        if (processor == null) {
            // if it's null then assume it's a file, and that the id
            // is all that's there.
            itemId = browseRoot;
            processor = getMediaFileProcessor();
        }

        if (itemId == null) {
            returnValue = browseFlag == BrowseFlag.METADATA ? processor.browseRootMetadata() : processor.browseRoot(filter, firstResult, maxResults, orderBy);
        } else {
            returnValue = browseFlag == BrowseFlag.METADATA ? processor.browseObjectMetadata(itemId) : processor.browseObject(itemId, filter, firstResult, maxResults, orderBy);
        }
        return returnValue;
    } catch (Throwable x) {
        LOG.error("UPnP error: " + x, x);
        throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, x.toString());
    }
}
 
Example #13
Source File: ContentDirectoryService.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public BrowseResult browse(String objectID, BrowseFlag browseFlag, String s1, long l, long l1,
                           SortCriterion[] sortCriterions) throws ContentDirectoryException {
    try {

        DIDLContent didl = new DIDLContent();

        ContentNode contentNode = ContentTree.getNode(objectID);

        Log.d(TAG, "someone's browsing id: " + objectID);

        if (contentNode == null) { // 没有共享资源
            return new BrowseResult("", 0, 0);
        }

        if (contentNode.isItem()) { // 是文件
            didl.addItem(contentNode.getItem());

            Log.v(TAG, "returing item: " + contentNode.getItem().getTitle());

            return new BrowseResult(new DIDLParser().generate(didl), 1, 1);

        } else { // 是文件夹
            if (browseFlag == BrowseFlag.METADATA) {
                didl.addContainer(contentNode.getContainer());

                Log.v(TAG, "returning metadata of container: " + contentNode.getContainer().getTitle());

                return new BrowseResult(new DIDLParser().generate(didl), 1, 1);

            } else {
                for (Container container : contentNode.getContainer().getContainers()) {
                    didl.addContainer(container);

                    Log.v(TAG, "getting child container: " + container.getTitle());
                }
                for (Item item : contentNode.getContainer().getItems()) {
                    didl.addItem(item);

                    Log.v(TAG, "getting child item: " + item.getTitle());
                }
                return new BrowseResult(new DIDLParser().generate(didl),
                        contentNode.getContainer().getChildCount(),
                        contentNode.getContainer().getChildCount());
            }

        }

    } catch (Exception e) {
        throw new ContentDirectoryException(
                ContentDirectoryErrorCode.CANNOT_PROCESS, e.toString());
    }
}
 
Example #14
Source File: ContentDirectoryService.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BrowseResult browse(String objectID, BrowseFlag browseFlag,
		String filter, long firstResult, long maxResults,
		SortCriterion[] orderby) throws ContentDirectoryException {
	// TODO Auto-generated method stub
	try {

		DIDLContent didl = new DIDLContent();

		ContentNode contentNode = ContentTree.getNode(objectID);
		
		Log.v(LOGTAG, "someone's browsing id: " + objectID);

		if (contentNode == null)
			return new BrowseResult("", 0, 0);

		if (contentNode.isItem()) {
			didl.addItem(contentNode.getItem());
			
			Log.v(LOGTAG, "returing item: " + contentNode.getItem().getTitle());
			
			return new BrowseResult(new DIDLParser().generate(didl), 1, 1);
		} else {
			if (browseFlag == BrowseFlag.METADATA) {
				didl.addContainer(contentNode.getContainer());
				
				Log.v(LOGTAG, "returning metadata of container: " + contentNode.getContainer().getTitle());
				
				return new BrowseResult(new DIDLParser().generate(didl), 1,
						1);
			} else {
				for (Container container : contentNode.getContainer()
						.getContainers()) {
					didl.addContainer(container);
					
					Log.v(LOGTAG, "getting child container: " + container.getTitle());
				}
				for (Item item : contentNode.getContainer().getItems()) {
					didl.addItem(item);
					
					Log.v(LOGTAG, "getting child item: " + item.getTitle());
				}
				return new BrowseResult(new DIDLParser().generate(didl),
						contentNode.getContainer().getChildCount(),
						contentNode.getContainer().getChildCount());
			}

		}

	} catch (Exception ex) {
		throw new ContentDirectoryException(
				ContentDirectoryErrorCode.CANNOT_PROCESS, ex.toString());
	}
}