Esempio n. 1
0
    def _makeDir(path):
        # make sure the path ends with a slash
        path = Url.addTrailingSlash(path)

        path = xbmc.translatePath(path)
        if xbmcvfs.exists(path):
            return True

        try:
            _ = xbmcvfs.mkdirs(path)
        except:  # noqa: E722 # nosec
            pass

        if xbmcvfs.exists(path):
            return True

        try:
            os.makedirs(path)
        except:  # noqa: E722 # nosec
            pass

        return xbmcvfs.exists(path)
Esempio n. 2
0
    def getPlaybackUrl(embyServer, itemId, itemObj, allowDirectPlay=True):
        isFolder = itemObj.get(constants.PROPERTY_ITEM_IS_FOLDER)
        itemPath = None
        if constants.PROPERTY_ITEM_MEDIA_SOURCES in itemObj:
            mediaSources = itemObj.get(constants.PROPERTY_ITEM_MEDIA_SOURCES)
            if len(mediaSources) > 0:
                mediaSource = mediaSources[0]
                if mediaSource:
                    itemPath = mediaSource.get(
                        constants.PROPERTY_ITEM_MEDIA_SOURCES_PATH)
                    protocol = mediaSource.get(
                        constants.PROPERTY_ITEM_MEDIA_SOURCES_PROTOCOL)
                    container = mediaSource.get(
                        constants.PROPERTY_ITEM_MEDIA_SOURCES_CONTAINER)
                    supportsDirectPlay = mediaSource.get(
                        constants.
                        PROPERTY_ITEM_MEDIA_SOURCES_SUPPORTS_DIRECT_PLAY)
                    supportsDirectStream = \
                        mediaSource.get(constants.PROPERTY_ITEM_MEDIA_SOURCES_SUPPORTS_DIRECT_STREAM)
                    if not supportsDirectPlay and not supportsDirectStream:
                        log(
                            'cannot import item with ID {} because it neither support Direct Play nor Direct Stream'
                            .format(itemId), xbmc.LOGWARNING)
                        return None
                    if not allowDirectPlay and not supportsDirectStream:
                        log(
                            'cannot import item with ID {} because it doesn\'t support Direct Stream'
                            .format(itemId), xbmc.LOGWARNING)
                        return None

                    # handle Direct Play for directly accessible or HTTP items
                    if allowDirectPlay and supportsDirectPlay:
                        if protocol == constants.PROPERTY_ITEM_MEDIA_SOURCES_PROTOCOL_HTTP or xbmcvfs.exists(
                                itemPath):
                            return itemPath

                        mappedItemPath = Api._mapPath(itemPath,
                                                      container=container)
                        if xbmcvfs.exists(mappedItemPath):
                            return mappedItemPath

                    # STRMs require Direct Play
                    if not allowDirectPlay and (container == 'strm'
                                                or itemPath.endswith('.strm')):
                        log(
                            'cannot import item with ID {} because STRMs require Direct Play'
                            .format(itemId), xbmc.LOGWARNING)
                        return None

                    # let the rest be handled as Direct Stream

        if not itemPath:
            # get the direct path
            itemPath = itemObj.get(constants.PROPERTY_ITEM_PATH)
            if not itemPath:
                if isFolder:
                    return embyServer.BuildItemUrl(itemId)

                log(
                    'cannot import item with ID {} because it doesn\'t have a proper path'
                    .format(itemId), xbmc.LOGWARNING)
                return None

        if isFolder:
            # make sure folders have a trailing slash
            itemPath = Url.addTrailingSlash(itemPath)

        # if we can access the direct path we can use Direct Play
        if allowDirectPlay:
            if xbmcvfs.exists(itemPath):
                return itemPath

            mappedItemPath = Api._mapPath(itemPath)
            if xbmcvfs.exists(mappedItemPath):
                return mappedItemPath

        if isFolder:
            return embyServer.BuildItemUrl(itemId)

        # fall back to Direct Stream
        return embyServer.BuildDirectStreamUrl(
            itemObj.get(constants.PROPERTY_ITEM_MEDIA_TYPE), itemId)