Esempio n. 1
0
    def _doesThemeExist(self, directory):
        log("doesThemeExist: Checking directory: %s" % directory)
        # Check for custom theme directory
        if Settings.isThemeDirEnabled():
            themeDir = os_path_join(directory, Settings.getThemeDirectory())
            # Check if this directory exists
            if not dir_exists(themeDir):
                workingPath = directory
                # If the path currently ends in the directory separator
                # then we need to clear an extra one
                if (workingPath[-1] == os.sep) or (workingPath[-1]
                                                   == os.altsep):
                    workingPath = workingPath[:-1]
                # If not check to see if we have a DVD VOB
                if (os_path_split(workingPath)[1]
                        == 'VIDEO_TS') or (os_path_split(workingPath)[1]
                                           == 'BDMV'):
                    # Check the parent of the DVD Dir
                    themeDir = os_path_split(workingPath)[0]
                    themeDir = os_path_join(themeDir,
                                            Settings.getThemeDirectory())
            directory = themeDir

        # check if the directory exists before searching
        if dir_exists(directory):
            # Generate the regex
            themeFileRegEx = Settings.getThemeFileRegEx(audioOnly=True)

            dirs, files = list_dir(directory)
            for aFile in files:
                m = re.search(themeFileRegEx, aFile, re.IGNORECASE)
                if m:
                    log("doesThemeExist: Found match: " + aFile)
                    return True
        return False
Esempio n. 2
0
    def _getThemeFiles(self, directory, extensionOnly=False):
        # First read from the NFO file if it exists
        nfoRead = NfoReader(directory, self.debug_logging_enabled)
        themeFiles = nfoRead.getThemeFiles()

        # Get the theme directories that are referenced and process the data in them
        for nfoDir in nfoRead.getThemeDirs():
            # Do not want the theme keyword if looking at an entire directory
            themeFiles = themeFiles + self._getThemeFiles(nfoDir, True)

        del nfoRead
        log("ThemeFiles: Searching %s for %s" % (directory, Settings.getThemeFileRegEx(directory, extensionOnly, self.audioOnly)), self.debug_logging_enabled)

        # Make sure that the path does not point to a plugin, as we are checking the
        # file-system for themes, not plugins. This can be the case with Emby
        if "plugin://" in directory:
            log("ThemeFiles: Plugin paths do not support theme files: %s" % directory, self.debug_logging_enabled)
        else:
            # check if the directory exists before searching
            if dir_exists(directory):
                dirs, files = list_dir(directory)
                for aFile in files:
                    m = re.search(Settings.getThemeFileRegEx(directory, extensionOnly, self.audioOnly), aFile, re.IGNORECASE)
                    if m:
                        path = os_path_join(directory, aFile)
                        log("ThemeFiles: Found match: %s" % path, self.debug_logging_enabled)
                        # Add the theme file to the list
                        themeFiles.append(path)

        return themeFiles
Esempio n. 3
0
    def _moveToThemeFolder(self, directory):
        log("moveToThemeFolder: path = %s" % directory)

        # Handle the case where we have a disk image
        if (os_path_split(directory)[1] == 'VIDEO_TS') or (os_path_split(directory)[1] == 'BDMV'):
            directory = os_path_split(directory)[0]

        dirs, files = list_dir(directory)
        for aFile in files:
            m = re.search(Settings.getThemeFileRegEx(directory), aFile, re.IGNORECASE)
            if m:
                srcpath = os_path_join(directory, aFile)
                log("fetchAllMissingThemes: Found match: %s" % srcpath)
                targetpath = os_path_join(directory, Settings.getThemeDirectory())
                # Make sure the theme directory exists
                if not dir_exists(targetpath):
                    try:
                        xbmcvfs.mkdir(targetpath)
                    except:
                        log("fetchAllMissingThemes: Failed to create directory: %s" % targetpath, True, xbmc.LOGERROR)
                        break
                else:
                    log("moveToThemeFolder: directory already exists %s" % targetpath)
                # Add the filename to the path
                targetpath = os_path_join(targetpath, aFile)
                if not xbmcvfs.rename(srcpath, targetpath):
                    log("moveToThemeFolder: Failed to move file from %s to %s" % (srcpath, targetpath))
Esempio n. 4
0
    def _doesThemeExist(self, directory):
        log("doesThemeExist: Checking directory: %s" % directory)
        # Check for custom theme directory
        if Settings.isThemeDirEnabled():
            themeDir = os_path_join(directory, Settings.getThemeDirectory())
            # Check if this directory exists
            if not dir_exists(themeDir):
                workingPath = directory
                # If the path currently ends in the directory separator
                # then we need to clear an extra one
                if (workingPath[-1] == os.sep) or (workingPath[-1] == os.altsep):
                    workingPath = workingPath[:-1]
                # If not check to see if we have a DVD VOB
                if (os_path_split(workingPath)[1] == 'VIDEO_TS') or (os_path_split(workingPath)[1] == 'BDMV'):
                    # Check the parent of the DVD Dir
                    themeDir = os_path_split(workingPath)[0]
                    themeDir = os_path_join(themeDir, Settings.getThemeDirectory())
            directory = themeDir

        # check if the directory exists before searching
        if dir_exists(directory):
            # Generate the regex
            themeFileRegEx = Settings.getThemeFileRegEx(audioOnly=True)

            dirs, files = list_dir(directory)
            for aFile in files:
                m = re.search(themeFileRegEx, aFile, re.IGNORECASE)
                if m:
                    log("doesThemeExist: Found match: " + aFile)
                    return True
        return False
Esempio n. 5
0
    def _getThemeFiles(self, directory, extensionOnly=False):
        # First read from the NFO file if it exists
        nfoRead = NfoReader(directory, self.debug_logging_enabled)
        themeFiles = nfoRead.getThemeFiles()

        # Get the theme directories that are referenced and process the data in them
        for nfoDir in nfoRead.getThemeDirs():
            # Do not want the theme keyword if looking at an entire directory
            themeFiles = themeFiles + self._getThemeFiles(nfoDir, True)

        del nfoRead
        log("ThemeFiles: Searching %s for %s" % (directory, Settings.getThemeFileRegEx(directory, extensionOnly, self.audioOnly)), self.debug_logging_enabled)

        # check if the directory exists before searching
        if dir_exists(directory):
            dirs, files = list_dir(directory)
            for aFile in files:
                m = re.search(Settings.getThemeFileRegEx(directory, extensionOnly, self.audioOnly), aFile, re.IGNORECASE)
                if m:
                    path = os_path_join(directory, aFile)
                    log("ThemeFiles: Found match: %s" % path, self.debug_logging_enabled)
                    # Add the theme file to the list
                    themeFiles.append(path)

        return themeFiles
Esempio n. 6
0
    def _getAllFilesInDirectory(self, baseDir):
        videoFiles = []
        dirs, files = list_dir(baseDir)

        # Get all the files in the current directory
        for vidFile in files:
            fullPath = os_path_join(baseDir, vidFile)
            videoFiles.append(fullPath)

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

        return videoFiles
Esempio n. 7
0
    def _getAllFilesInDirectory(self, baseDir):
        videoFiles = []
        dirs, files = list_dir(baseDir)

        # Get all the files in the current directory
        for vidFile in files:
            fullPath = os_path_join(baseDir, vidFile)
            videoFiles.append(fullPath)

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

        return videoFiles
Esempio n. 8
0
    def _getPlaylist(self):
        playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
        playlist.clear()

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

            # Check if we are dealing with a Folder of videos
            if videosFolder != "" and dir_exists(videosFolder):
                dirs, files = list_dir(videosFolder)
                # 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:
                    fullPath = os_path_join(videosFolder, vidFile)
                    log("Screensaver video in directory is: %s" % fullPath)
                    playlist.add(fullPath)
        else:
            # Must be dealing with a single file
            videoFile = Settings.getScreensaverVideo()
            if (videoFile is None):
                videoFile == ""

            # Check to make sure the screensaver video file exists
            if (videoFile != "") and xbmcvfs.exists(videoFile):
                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 = 'XBMC.Notification("{0}", "{1}", 5, "{2}")'.format(
                __addon__.getLocalizedString(32300).encode('utf-8'),
                errorLocation, __icon__)
            xbmc.executebuiltin(cmd)
            return None

        return playlist
Esempio n. 9
0
    def _getThemeFiles(self, directory, extensionOnly=False):
        # First read from the NFO file if it exists
        nfoRead = NfoReader(directory, self.debug_logging_enabled)
        themeFiles = nfoRead.getThemeFiles()

        # Get the theme directories that are referenced and process the data in them
        for nfoDir in nfoRead.getThemeDirs():
            # Do not want the theme keyword if looking at an entire directory
            themeFiles = themeFiles + self._getThemeFiles(nfoDir, True)

        del nfoRead

        themeRegex = Settings.getThemeFileRegEx(directory, extensionOnly, self.audioOnly)
        log("ThemeFiles: Searching %s for %s" % (directory, themeRegex), self.debug_logging_enabled)

        # Make sure that the path does not point to a plugin, as we are checking the
        # file-system for themes, not plugins. This can be the case with Emby
        if "plugin://" in directory:
            log("ThemeFiles: Plugin paths do not support theme files: %s" % directory, self.debug_logging_enabled)
        else:
            # check if the directory exists before searching
            if dir_exists(directory):
                dirs, files = list_dir(directory)
                for aFile in files:
                    m = re.search(themeRegex, aFile, re.IGNORECASE)
                    if m:
                        path = os_path_join(directory, aFile)
                        log("ThemeFiles: Found match: %s" % path, self.debug_logging_enabled)
                        # Add the theme file to the list
                        themeFiles.append(path)
                # Check to see if any themes were found, and if not see if we should try
                # and use a trailer file instead
                if (len(themeFiles) < 1) and (not self.audioOnly) and (not extensionOnly) and Settings.useTrailers():
                    trailerRegEx = Settings.getTrailerFileRegEx()
                    for aFile in files:
                        m = re.search(trailerRegEx, aFile, re.IGNORECASE)
                        if m:
                            path = os_path_join(directory, aFile)
                            log("ThemeFiles: Found trailer match: %s" % path, self.debug_logging_enabled)
                            # Add the trailer file to the list
                            themeFiles.append(path)

        return themeFiles
Esempio n. 10
0
    def _getPlaylist(self):
        playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
        playlist.clear()

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

            # Check if we are dealing with a Folder of videos
            if videosFolder != "" and dir_exists(videosFolder):
                dirs, files = list_dir(videosFolder)
                # 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:
                    fullPath = os_path_join(videosFolder, vidFile)
                    log("Screensaver video in directory is: %s" % fullPath)
                    playlist.add(fullPath)
        else:
            # Must be dealing with a single file
            videoFile = Settings.getScreensaverVideo()
            if (videoFile is None):
                videoFile == ""

            # Check to make sure the screensaver video file exists
            if (videoFile != "") and xbmcvfs.exists(videoFile):
                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 = 'XBMC.Notification("{0}", "{1}", 5, "{2}")'.format(__addon__.getLocalizedString(32300).encode('utf-8'), errorLocation, __icon__)
            xbmc.executebuiltin(cmd)
            return None

        return playlist
Esempio n. 11
0
    def _getDisplayList(self):
        # Check the directory where the default videos are stored to see if
        # there are any videos already stored there
        dirs, files = list_dir(self.videoDir)

        displayList = []
        for videoItem in Settings.PRESET_VIDEOS:
            displayNamePrefix = "   "
            # Check if the file already exists, and has been downloaded already
            if videoItem[1] in files:
                log("Downloader: File %s already exists" % videoItem[1])
                displayNamePrefix = "* "

            displayList.append("%s%s" % (displayNamePrefix, __addon__.getLocalizedString(videoItem[0])))

        # Now add the option to allow the user randomly play the downloaded
        # videos
        displayList.append(__addon__.getLocalizedString(32100))

        return displayList
Esempio n. 12
0
    def _getDisplayList(self):
        # Check the directory where the default videos are stored to see if
        # there are any videos already stored there
        dirs, files = list_dir(self.videoDir)

        displayList = []
        for videoItem in Settings.PRESET_VIDEOS:
            displayNamePrefix = '   '
            # Check if the file already exists, and has been downloaded already
            if videoItem[1] in files:
                log("Downloader: File %s already exists" % videoItem[1])
                displayNamePrefix = '* '

            displayList.append("%s%s" %
                               (displayNamePrefix,
                                __addon__.getLocalizedString(videoItem[0])))

        # Now add the option to allow the user randomly play the downloaded
        # videos
        displayList.append(__addon__.getLocalizedString(32100))

        return displayList
Esempio n. 13
0
    def _getPlaylist(self):
        playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
        # Note: The playlist clear option seems to creat 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()
            if (videosFolder is None):
                videosFolder == ""

            # Check if we are dealing with a Folder of videos
            if videosFolder != "" and dir_exists(videosFolder):
                self.currentScheduleItem = -1
                recursive = Settings.isFolderSelectionRecursive()
                dirs, files = list_dir(videosFolder, recursive)
                # 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()
            if (videoFile is None):
                videoFile == ""

            # Check to make sure the screensaver video file exists
            if (videoFile != "") and 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, __icon__)
            xbmc.executebuiltin(cmd)
            return None

        return playlist