Exemplo n.º 1
0
    def _getAllFilesInDirectory(self, baseDir, includeSubDirs=True):
        videoFiles = []
        dirs, files = list_dir(baseDir)

        # Get the list of files that are to be excluded
        collectionCtrl = CollectSets()
        disabledVideos = collectionCtrl.getDisabledVideos()
        del collectionCtrl

        # Get all the files in the current directory
        for vidFile in files:
            # Check if this file is excluded
            if vidFile in disabledVideos:
                log("Ignoring disabled screensaver video %s" % vidFile)
                continue

            fullPath = os_path_join(baseDir, vidFile)
            videoFiles.append(fullPath)

        # Now check each directory
        if includeSubDirs and Settings.isFolderNested():
            for aDir in dirs:
                fullPath = os_path_join(baseDir, aDir)
                dirContents = self._getAllFilesInDirectory(fullPath)
                videoFiles = videoFiles + dirContents

        return videoFiles
Exemplo n.º 2
0
    def _getAllFilesInDirectory(self, baseDir, includeSubDirs=True):
        videoFiles = []
        dirs, files = list_dir(baseDir)

        # Get the list of files that are to be excluded
        collectionCtrl = CollectSets()
        disabledVideos = collectionCtrl.getDisabledVideos()
        del collectionCtrl

        # Get all the files in the current directory
        for vidFile in files:
            # Check if this file is excluded
            if vidFile in disabledVideos:
                log("Ignoring disabled screensaver video %s" % vidFile)
                continue

            fullPath = os_path_join(baseDir, vidFile)
            videoFiles.append(fullPath)

        # Now check each directory
        if includeSubDirs and Settings.isFolderNested():
            for aDir in dirs:
                fullPath = os_path_join(baseDir, aDir)
                dirContents = self._getAllFilesInDirectory(fullPath)
                videoFiles = videoFiles + dirContents

        return videoFiles
Exemplo n.º 3
0
    def removeCollection(self, name, link):
        if name in [None, ""]:
            return

        collectionCtrl = CollectSets()
        collectionDetails = collectionCtrl.loadCollection(link)

        filesToDelete = []
        # If the file was not processed just don't display anything
        if collectionDetails not in [None, ""]:
            screensaverFolder = Settings.getScreensaverFolder()

            for videoItem in collectionDetails['videos']:
                # If theme exists we need to check if we want to delete it
                if screensaverFolder not in [None, ""]:
                    videoLocation = os_path_join(screensaverFolder, videoItem['filename'])

                    log("VideoScreensaverPlugin: Checking if %s already downloaded to %s" % (videoItem['filename'], videoLocation))
                    if xbmcvfs.exists(videoLocation):
                        filesToDelete.append(videoLocation)

        # If there are possible files to delete, then prompt the user to see if we should
        if len(filesToDelete) > 0:
            needDelete = xbmcgui.Dialog().yesno(ADDON.getLocalizedString(32005), ADDON.getLocalizedString(32086))

            if needDelete:
                for vidFile in filesToDelete:
                    xbmcvfs.delete(vidFile)

        # Now remove the actual collection
        collectionCtrl.removeCustomCollection(name)
        del collectionCtrl

        # Now reload the screen to reflect the change
        xbmc.executebuiltin("Container.Refresh")
Exemplo n.º 4
0
    def viewCollection(self, name, link):
        log("VideoScreensaverPlugin: %s (%s)" % (name, link))

        collectionCtrl = CollectSets()
        collectionDetails = collectionCtrl.loadCollection(link)
        del collectionCtrl

        # If the file was not processed just don't display anything
        if collectionDetails in [None, ""]:
            return

        screensaverFolder = Settings.getScreensaverFolder()

        for videoItem in collectionDetails['videos']:
            displayName = videoItem['name']
            if videoItem['enabled'] is False:
                displayName = "%s %s" % (ADDON.getLocalizedString(32016),
                                         displayName)

            # Create the list-item for this video
            li = xbmcgui.ListItem(displayName, iconImage=videoItem['image'])
            if videoItem['duration'] not in [None, "", 0]:
                li.setInfo('video', {'Duration': videoItem['duration']})

            # Set the background image
#             if videoItem['fanart'] is not None:
#                 li.setProperty("Fanart_Image", videoItem['fanart'])

# If theme already exists flag it using the play count
# This will normally put a tick on the GUI
            if screensaverFolder not in [None, ""]:
                if self._getVideoLocation(
                        screensaverFolder,
                        videoItem['filename']) not in [None, ""]:
                    li.setInfo('video', {'PlayCount': 1})

            li.addContextMenuItems(self._getContextMenu(
                videoItem, collectionDetails['builtin']),
                                   replaceItems=True)

            url = self._build_url({
                'mode': 'download',
                'name': videoItem['name'],
                'filename': videoItem['filename'],
                'primary': videoItem['primary'],
                'builtin': collectionDetails['builtin']
            })

            xbmcplugin.addDirectoryItem(handle=self.addon_handle,
                                        url=url,
                                        listitem=li,
                                        isFolder=False)

        xbmcplugin.endOfDirectory(self.addon_handle)
Exemplo n.º 5
0
    def addCollection(self):
        # Prompt the user to select the file
        customXml = xbmcgui.Dialog().browse(1, ADDON.getLocalizedString(32082), 'files', '.xml')

        if not customXml:
            return

        # If file selected then check it is OK
        collectionCtrl = CollectSets()
        isCollectionValid = collectionCtrl.addCustomCollection(customXml)
        del collectionCtrl

        if isCollectionValid:
            log("VideoScreensaverPlugin: collection added: %s" % customXml)
        else:
            log("VideoScreensaverPlugin: Failed to add collection: %s" % customXml)
            xbmcgui.Dialog().notification(ADDON.getLocalizedString(32005), ADDON.getLocalizedString(32083), ICON, 5000, False)

        # Now reload the screen to reflect the change
        xbmc.executebuiltin("Container.Refresh")
Exemplo n.º 6
0
    def viewCollection(self, name, link):
        log("VideoScreensaverPlugin: %s (%s)" % (name, link))

        collectionCtrl = CollectSets()
        collectionDetails = collectionCtrl.loadCollection(link)
        del collectionCtrl

        # If the file was not processed just don't display anything
        if collectionDetails in [None, ""]:
            return

        screensaverFolder = Settings.getScreensaverFolder()

        for videoItem in collectionDetails['videos']:
            displayName = videoItem['name']
            if videoItem['enabled'] is False:
                displayName = "%s %s" % (ADDON.getLocalizedString(32016), displayName)

            # Create the list-item for this video
            li = xbmcgui.ListItem(displayName, iconImage=videoItem['image'])
            if videoItem['duration'] not in [None, "", 0]:
                li.setInfo('video', {'Duration': videoItem['duration']})

            # Set the background image
#             if videoItem['fanart'] is not None:
#                 li.setProperty("Fanart_Image", videoItem['fanart'])

            # If theme already exists flag it using the play count
            # This will normally put a tick on the GUI
            if screensaverFolder not in [None, ""]:
                if self._getVideoLocation(screensaverFolder, videoItem['filename']) not in [None, ""]:
                    li.setInfo('video', {'PlayCount': 1})

            li.addContextMenuItems(self._getContextMenu(videoItem), replaceItems=True)

            url = self._build_url({'mode': 'download', 'name': videoItem['name'], 'filename': videoItem['filename'], 'primary': videoItem['primary']})

            xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=False)

        xbmcplugin.endOfDirectory(self.addon_handle)
Exemplo n.º 7
0
    def enable(self, filename, disable):
        log("VideoScreensaverPlugin: Enable toggle %s" % filename)

        # Get the current list of disabled items
        collectionCtrl = CollectSets()
        disabledVideos = collectionCtrl.getDisabledVideos()

        # Check if we are adding or removing from the list
        if disable == 'false':
            if filename in disabledVideos:
                log("VideoScreensaverPlugin: Removing %s from the disabled videos" % filename)
                disabledVideos.remove(filename)
        else:
            if filename not in disabledVideos:
                log("VideoScreensaverPlugin: Adding %s to the disabled videos" % filename)
                disabledVideos.append(filename)

        collectionCtrl.saveDisabledVideos(disabledVideos)
        del collectionCtrl

        # Now reload the screen to reflect the change
        xbmc.executebuiltin("Container.Refresh")
Exemplo n.º 8
0
    def removeCollection(self, name, link):
        if name in [None, ""]:
            return

        collectionCtrl = CollectSets()
        collectionDetails = collectionCtrl.loadCollection(link)

        filesToDelete = []
        # If the file was not processed just don't display anything
        if collectionDetails not in [None, ""]:
            screensaverFolder = Settings.getScreensaverFolder()

            for videoItem in collectionDetails['videos']:
                # If theme exists we need to check if we want to delete it
                if screensaverFolder not in [None, ""]:
                    videoLocation = os_path_join(screensaverFolder,
                                                 videoItem['filename'])

                    log("VideoScreensaverPlugin: Checking if %s already downloaded to %s"
                        % (videoItem['filename'], videoLocation))
                    if xbmcvfs.exists(videoLocation):
                        filesToDelete.append(videoLocation)

        # If there are possible files to delete, then prompt the user to see if we should
        if len(filesToDelete) > 0:
            needDelete = xbmcgui.Dialog().yesno(
                ADDON.getLocalizedString(32005),
                ADDON.getLocalizedString(32086))

            if needDelete:
                for vidFile in filesToDelete:
                    xbmcvfs.delete(vidFile)

        # Now remove the actual collection
        collectionCtrl.removeCustomCollection(name)
        del collectionCtrl

        # Now reload the screen to reflect the change
        xbmc.executebuiltin("Container.Refresh")
Exemplo n.º 9
0
    def rootMenu(self):
        collectionCtrl = CollectSets()
        collectionMap = collectionCtrl.getCollections()

        log("VideoScreensaverPlugin: Available Number of Collections is %d" %
            len(collectionMap))

        for collectionKey in sorted(collectionMap.keys()):
            collectionDetail = collectionMap[collectionKey]
            li = xbmcgui.ListItem(collectionKey,
                                  iconImage=collectionDetail['image'])
            li.addContextMenuItems(
                self._getCollectionsContextMenu(collectionDetail),
                replaceItems=True)
            li.setProperty("Fanart_Image", FANART)
            url = self._build_url({
                'mode': 'collection',
                'name': collectionKey,
                'link': collectionDetail['filename']
            })
            xbmcplugin.addDirectoryItem(handle=self.addon_handle,
                                        url=url,
                                        listitem=li,
                                        isFolder=True)

        del collectionCtrl

        # Add a button to support adding a custom collection
        li = xbmcgui.ListItem(ADDON.getLocalizedString(32082), iconImage=ICON)
        li.addContextMenuItems([], replaceItems=True)
        li.setProperty("Fanart_Image", FANART)
        url = self._build_url({'mode': 'addcollection'})
        xbmcplugin.addDirectoryItem(handle=self.addon_handle,
                                    url=url,
                                    listitem=li,
                                    isFolder=False)

        xbmcplugin.endOfDirectory(self.addon_handle)
Exemplo n.º 10
0
    def rootMenu(self):
        collectionCtrl = CollectSets()
        collectionMap = collectionCtrl.getCollections()

        log("VideoScreensaverPlugin: Available Number of Collections is %d" % len(collectionMap))

        for collectionKey in sorted(collectionMap.keys()):
            collectionDetail = collectionMap[collectionKey]
            li = xbmcgui.ListItem(collectionKey, iconImage=collectionDetail['image'])
            li.addContextMenuItems(self._getCollectionsContextMenu(collectionDetail), replaceItems=True)
            li.setProperty("Fanart_Image", FANART)
            url = self._build_url({'mode': 'collection', 'name': collectionKey, 'link': collectionDetail['filename']})
            xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=True)

        del collectionCtrl

        # Add a button to support adding a custom collection
        li = xbmcgui.ListItem(ADDON.getLocalizedString(32082), iconImage=ICON)
        li.addContextMenuItems([], replaceItems=True)
        li.setProperty("Fanart_Image", FANART)
        url = self._build_url({'mode': 'addcollection'})
        xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=False)

        xbmcplugin.endOfDirectory(self.addon_handle)
Exemplo n.º 11
0
    def addCollection(self):
        # Prompt the user to select the file
        customXml = xbmcgui.Dialog().browse(1, ADDON.getLocalizedString(32082),
                                            'files', '.xml')

        if not customXml:
            return

        # If file selected then check it is OK
        collectionCtrl = CollectSets()
        isCollectionValid = collectionCtrl.addCustomCollection(customXml)
        del collectionCtrl

        if isCollectionValid:
            log("VideoScreensaverPlugin: collection added: %s" % customXml)
        else:
            log("VideoScreensaverPlugin: Failed to add collection: %s" %
                customXml)
            xbmcgui.Dialog().notification(ADDON.getLocalizedString(32005),
                                          ADDON.getLocalizedString(32083),
                                          ICON, 5000, False)

        # Now reload the screen to reflect the change
        xbmc.executebuiltin("Container.Refresh")
Exemplo n.º 12
0
    def enable(self, filename, disable):
        log("VideoScreensaverPlugin: Enable toggle %s" % filename)

        # Get the current list of disabled items
        collectionCtrl = CollectSets()
        disabledVideos = collectionCtrl.getDisabledVideos()

        # Check if we are adding or removing from the list
        if disable == 'false':
            if filename in disabledVideos:
                log("VideoScreensaverPlugin: Removing %s from the disabled videos"
                    % filename)
                disabledVideos.remove(filename)
        else:
            if filename not in disabledVideos:
                log("VideoScreensaverPlugin: Adding %s to the disabled videos"
                    % filename)
                disabledVideos.append(filename)

        collectionCtrl.saveDisabledVideos(disabledVideos)
        del collectionCtrl

        # Now reload the screen to reflect the change
        xbmc.executebuiltin("Container.Refresh")
Exemplo n.º 13
0
    def _getPlaylist(self):
        playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
        # Note: The playlist clear option seems to impact all playlist settings,
        # so will remove the repeat settings on a playlist that is currently playing,
        # not just this instance - a bit nasty, but not much we can do about it
        playlist.clear()

        # Check to see if we should be using a video from the schedule
        scheduleEntry = self.scheduler.getScheduleEntry()

        if scheduleEntry != -1:
            # There is an item scheduled, so check to see if the item has actually changed
            if scheduleEntry == self.currentScheduleItem:
                return None
            # Set the entry we are about to play
            self.currentScheduleItem = scheduleEntry
            # Get the actual video file that should be played
            scheduledVideo = self.scheduler.getScheduleVideo(scheduleEntry)
            # Do a quick check to see if the video exists
            if xbmcvfs.exists(scheduledVideo):
                log("Screensaver video for scheduled item %d is: %s" % (scheduleEntry, scheduledVideo))
                playlist.add(scheduledVideo)

        # Check if we are showing all the videos in a given folder
        elif Settings.isFolderSelection():
            videosFolder = Settings.getScreensaverFolder()

            # Check if we are dealing with a Folder of videos
            if videosFolder not in [None, ""]:
                if dir_exists(videosFolder):
                    self.currentScheduleItem = -1
                    files = self._getAllFilesInDirectory(videosFolder)

                    # Check if we are limiting to a single folder per session
                    if Settings.isLimitSessionToSingleCollection():
                        # Select just one file at random
                        singleVideo = random.choice(files)

                        # Check if this file is part of a collection
                        justFilename = (os_path_split(singleVideo))[-1]
                        collectionCtrl = CollectSets()
                        collectionVideos = collectionCtrl.getFilesInSameCollection(justFilename)
                        del collectionCtrl

                        # If it is part of a collection, then limit to only files in
                        # this collection
                        if len(collectionVideos) > 0:
                            log("Screensaver restricting to collection containing %s" % singleVideo)
                            # Check each of the videos to see which are in the collection
                            collectionFileList = []
                            for aFile in files:
                                # Get just the filename
                                aFilename = (os_path_split(aFile))[-1]
                                if aFilename in collectionVideos:
                                    log("Screensaver including collection video %s" % aFile)
                                    collectionFileList.append(aFile)
                                else:
                                    log("Screensaver excluding non collection video %s" % aFile)
                        else:
                            log("Screensaver restricting to directory containing %s" % singleVideo)
                            # Not in a collection, so just gather the files in the same directory
                            # Get the directory that file was part of
                            parentPath = (os_path_split(singleVideo))[0]

                            # Now only select videos from that directory
                            files = self._getAllFilesInDirectory(parentPath, False)

                    # Now shuffle the playlist to ensure that if there are more
                    # than one video a different one starts each time
                    random.shuffle(files)
                    for vidFile in files:
                        log("Screensaver video in directory is: %s" % vidFile)
                        playlist.add(vidFile)
        else:
            # Must be dealing with a single file
            videoFile = Settings.getScreensaverVideo()

            # Check to make sure the screensaver video file exists
            if videoFile not in [None, ""]:
                if xbmcvfs.exists(videoFile):
                    self.currentScheduleItem = -1
                    log("Screensaver video is: %s" % videoFile)
                    playlist.add(videoFile)

        # If there are no videos in the playlist yet, then display an error
        if playlist.size() < 1:
            errorLocation = Settings.getScreensaverVideo()
            if Settings.isFolderSelection():
                errorLocation = Settings.getScreensaverFolder()

            log("No Screensaver file set or not valid %s" % errorLocation)
            cmd = 'Notification("{0}", "{1}", 3000, "{2}")'.format(ADDON.getLocalizedString(32300).encode('utf-8'), errorLocation, ADDON.getAddonInfo('icon'))
            xbmc.executebuiltin(cmd)
            return None

        return playlist
Exemplo n.º 14
0
    def _getPlaylist(self):
        playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
        # Note: The playlist clear option seems to impact all playlist settings,
        # so will remove the repeat settings on a playlist that is currently playing,
        # not just this instance - a bit nasty, but not much we can do about it
        playlist.clear()

        # Check to see if we should be using a video from the schedule
        scheduleEntry = self.scheduler.getScheduleEntry()

        if scheduleEntry != -1:
            # There is an item scheduled, so check to see if the item has actually changed
            if scheduleEntry == self.currentScheduleItem:
                return None
            # Set the entry we are about to play
            self.currentScheduleItem = scheduleEntry
            # Get the actual video file that should be played
            scheduledVideo = self.scheduler.getScheduleVideo(scheduleEntry)
            # Do a quick check to see if the video exists
            if xbmcvfs.exists(scheduledVideo):
                log("Screensaver video for scheduled item %d is: %s" %
                    (scheduleEntry, scheduledVideo))
                playlist.add(scheduledVideo)

        # Check if we are showing all the videos in a given folder
        elif Settings.isFolderSelection():
            videosFolder = Settings.getScreensaverFolder()

            # Check if we are dealing with a Folder of videos
            if videosFolder not in [None, ""]:
                if dir_exists(videosFolder):
                    self.currentScheduleItem = -1
                    files = self._getAllFilesInDirectory(videosFolder)

                    # Check if we are limiting to a single folder per session
                    if Settings.isLimitSessionToSingleCollection():
                        # Select just one file at random
                        singleVideo = random.choice(files)

                        # Check if this file is part of a collection
                        justFilename = (os_path_split(singleVideo))[-1]
                        collectionCtrl = CollectSets()
                        collectionVideos = collectionCtrl.getFilesInSameCollection(
                            justFilename)
                        del collectionCtrl

                        # If it is part of a collection, then limit to only files in
                        # this collection
                        if len(collectionVideos) > 0:
                            log("Screensaver restricting to collection containing %s"
                                % singleVideo)
                            # Check each of the videos to see which are in the collection
                            collectionFileList = []
                            for aFile in files:
                                # Get just the filename
                                aFilename = (os_path_split(aFile))[-1]
                                if aFilename in collectionVideos:
                                    log("Screensaver including collection video %s"
                                        % aFile)
                                    collectionFileList.append(aFile)
                                else:
                                    log("Screensaver excluding non collection video %s"
                                        % aFile)
                        else:
                            log("Screensaver restricting to directory containing %s"
                                % singleVideo)
                            # Not in a collection, so just gather the files in the same directory
                            # Get the directory that file was part of
                            parentPath = (os_path_split(singleVideo))[0]

                            # Now only select videos from that directory
                            files = self._getAllFilesInDirectory(
                                parentPath, False)

                    # Now shuffle the playlist to ensure that if there are more
                    # than one video a different one starts each time
                    random.shuffle(files)
                    for vidFile in files:
                        log("Screensaver video in directory is: %s" % vidFile)
                        playlist.add(vidFile)
        else:
            # Must be dealing with a single file
            videoFile = Settings.getScreensaverVideo()

            # Check to make sure the screensaver video file exists
            if videoFile not in [None, ""]:
                if xbmcvfs.exists(videoFile):
                    self.currentScheduleItem = -1
                    log("Screensaver video is: %s" % videoFile)
                    playlist.add(videoFile)

        # If there are no videos in the playlist yet, then display an error
        if playlist.size() < 1:
            errorLocation = Settings.getScreensaverVideo()
            if Settings.isFolderSelection():
                errorLocation = Settings.getScreensaverFolder()

            log("No Screensaver file set or not valid %s" % errorLocation)
            cmd = 'Notification("{0}", "{1}", 3000, "{2}")'.format(
                ADDON.getLocalizedString(32300).encode('utf-8'), errorLocation,
                ADDON.getAddonInfo('icon'))
            xbmc.executebuiltin(cmd)
            return None

        return playlist