Example #1
0
    def fetchTheme(self, title, path, originaltitle=None, isTvShow=None, year=None, imdb=None):
        # If there is already a theme then start playing it
        self._startPlayingExistingTheme(path)

        if Settings.isThemeDirEnabled() and self._doesThemeExist(path, True):
            # Prompt user if we should move themes in the parent
            # directory into the theme directory
            moveExistingThemes = xbmcgui.Dialog().yesno(ADDON.getLocalizedString(32105), ADDON.getLocalizedString(32206), ADDON.getLocalizedString(32207))

            # Check if we need to move a theme file
            if moveExistingThemes:
                log("fetchAllMissingThemes: Moving theme for %s" % title)
                self._moveToThemeFolder(path)
                # Stop playing any theme that started
                self._stopPlayingTheme()
                # Now reload the screen to reflect the change
                xbmc.executebuiltin("Container.Refresh")
                return

        if originaltitle is not None:
            originaltitle = normalize_string(originaltitle)

        # Perform the fetch
        videoList = []
        normtitle = normalize_string(title)
        videoItem = {'title': normtitle, 'path': path, 'originalTitle': originaltitle, 'isTvShow': isTvShow, 'year': year, 'imdb': imdb}
        videoList.append(videoItem)
        TvTunesFetcher(videoList)

        # Stop playing any theme that started
        self._stopPlayingTheme()

        # Now reload the screen to reflect the change
        xbmc.executebuiltin("Container.Refresh")
Example #2
0
    def fetchTheme(self,
                   title,
                   path,
                   originaltitle=None,
                   isTvShow=None,
                   year=None,
                   imdb=None):
        # If there is already a theme then start playing it
        self._startPlayingExistingTheme(path)

        if Settings.isThemeDirEnabled() and self._doesThemeExist(path, True):
            # Prompt user if we should move themes in the parent
            # directory into the theme directory
            moveExistingThemes = xbmcgui.Dialog().yesno(
                ADDON.getLocalizedString(32105),
                ADDON.getLocalizedString(32206),
                ADDON.getLocalizedString(32207))

            # Check if we need to move a theme file
            if moveExistingThemes:
                log("fetchAllMissingThemes: Moving theme for %s" % title)
                self._moveToThemeFolder(path)
                # Stop playing any theme that started
                self._stopPlayingTheme()
                # Now reload the screen to reflect the change
                xbmc.executebuiltin("Container.Refresh")
                return

        if originaltitle is not None:
            originaltitle = normalize_string(originaltitle)

        # Perform the fetch
        videoList = []
        normtitle = normalize_string(title)
        videoItem = {
            'title': normtitle,
            'path': path,
            'originalTitle': originaltitle,
            'isTvShow': isTvShow,
            'year': year,
            'imdb': imdb
        }
        videoList.append(videoItem)
        TvTunesFetcher(videoList)

        # Stop playing any theme that started
        self._stopPlayingTheme()

        # Now reload the screen to reflect the change
        xbmc.executebuiltin("Container.Refresh")
Example #3
0
    def __init__(self, rawPath, pathList=None, videotitle=None, debug_logging_enabled=True, audioOnly=False):
        self.debug_logging_enabled = debug_logging_enabled
        self.forceShuffle = False
        self.doNotShuffle = False
        self.audioOnly = audioOnly
        self.rawPath = rawPath
        if rawPath in [None, ""]:
            self.clear()
        else:
            # Check for the case where there is a custom path set so we need to use
            # the custom location rather than the rawPath
            if Settings.isCustomPathEnabled() and (videotitle not in [None, ""]):
                customRoot = Settings.getCustomPath()
                # Make sure that the path passed in has not already been converted
                if customRoot not in self.rawPath:
                    self.rawPath = os_path_join(customRoot, normalize_string(videotitle))
                    log("ThemeFiles: Setting custom path to %s" % self.rawPath, self.debug_logging_enabled)

            if (pathList is not None) and (len(pathList) > 0):
                self.themeFiles = []
                for aPath in pathList:
                    subThemeList = self._generateThemeFilelistWithDirs(aPath)
                    # add these files to the existing list
                    self.themeFiles = self._mergeThemeLists(self.themeFiles, subThemeList)
                # If we were given a list, then we should shuffle the themes
                # as we don't always want the first path playing first
                self.forceShuffle = True
            else:
                self.themeFiles = self._generateThemeFilelistWithDirs(self.rawPath)

        # Check if we need to handle the ordering for video themes
        if not audioOnly:
            self.doNotShuffle = self._filterForVideoThemesRule()
            self.forceShuffle = False
Example #4
0
    def getPathForVideoItem(self, videoItem):
        path = ""
        # Get the path where the theme should be stored
        if Settings.isCustomPathEnabled():
            path = os_path_join(Settings.getCustomPath(), normalize_string(videoItem['title']))
        else:
            path = videoItem['file']
            # Handle stacked files that have a custom file name format
            if path.startswith("stack://"):
                path = path.replace("stack://", "").split(" , ", 1)[0]
            # Need to remove the filename from the end  as we just want the directory
            fileExt = os.path.splitext(path)[1]
            # If this is a file, then get it's parent directory
            if fileExt is not None and fileExt != "":
                path = os_path_split(path)[0]

        return path
Example #5
0
    def getPathForVideoItem(self, videoItem):
        path = ""
        # Get the path where the theme should be stored
        if Settings.isCustomPathEnabled():
            path = os_path_join(Settings.getCustomPath(), normalize_string(videoItem['title']))
        else:
            path = videoItem['file']
            # Handle stacked files that have a custom file name format
            if path.startswith("stack://"):
                path = path.replace("stack://", "").split(" , ", 1)[0]
            # Need to remove the filename from the end  as we just want the directory
            fileExt = os.path.splitext(path)[1]
            # If this is a file, then get it's parent directory
            if fileExt is not None and fileExt != "":
                path = os_path_split(path)[0]

        return path
Example #6
0
    def fetchMissingThemes(self, incAudioThemes=True, incVideoThemes=False):
        # Prompt the user to see if they want all the themes or just some
        # of them
        displayList = []
        displayList.append(ADDON.getLocalizedString(32210))
        displayList.append(ADDON.getLocalizedString(32211))
        displayList.append(ADDON.getLocalizedString(32212))
        displayList.append(ADDON.getLocalizedString(32213))

        # Show the list to the user
        select = xbmcgui.Dialog().select(ADDON.getLocalizedString(32105), displayList)
        if select < 0:
            log("fetchMissingThemes: Cancelled by user")
            return

        # It could take a little while to get the videos so show the busy dialog
        xbmc.executebuiltin("ActivateWindow(busydialog)")

        tvShows = []
        if (select == 0) or (select == 1):
            log("fetchMissingThemes: Checking TV Shows")
            tvShows = self.getVideos('GetTVShows', MenuNavigator.TVSHOWS)
        movies = []
        if (select == 0) or (select == 2):
            log("fetchMissingThemes: Checking Movies")
            movies = self.getVideos('GetMovies', MenuNavigator.MOVIES)
        music = []
        if (select == 0) or (select == 3):
            log("fetchMissingThemes: Checking Music Videos")
            music = self.getVideos('GetMusicVideos', MenuNavigator.MUSICVIDEOS)

        videoList = []

        moveExistingThemes = None

        for videoItem in (tvShows + movies + music):
            # Get the path where the theme should be stored
            path = self.getPathForVideoItem(videoItem)
            # Skip items that already have themes
            if self._doesThemeExist(path, False, incAudioThemes, incVideoThemes):
                continue

            if Settings.isThemeDirEnabled() and self._doesThemeExist(path, True, incAudioThemes, incVideoThemes):
                if moveExistingThemes is None:
                    xbmc.executebuiltin("Dialog.Close(busydialog)")
                    # Prompt user if we should move themes in the parent
                    # directory into the theme directory
                    moveExistingThemes = xbmcgui.Dialog().yesno(ADDON.getLocalizedString(32105), ADDON.getLocalizedString(32206), ADDON.getLocalizedString(32207))
                    xbmc.executebuiltin("ActivateWindow(busydialog)")

                # Check if we need to move a theme file
                if moveExistingThemes:
                    log("fetchAllMissingThemes: Moving theme for %s" % videoItem['title'])
                    self._moveToThemeFolder(path)
                continue

            normtitle = normalize_string(videoItem['title']).encode("utf-8")
            normOriginalTitle = None
            if videoItem['originaltitle'] is not None:
                normOriginalTitle = normalize_string(videoItem['originaltitle']).encode("utf-8")

            videoItem = {'title': normtitle, 'path': path.encode("utf-8"), 'originalTitle': normOriginalTitle, 'isTvShow': videoItem['isTvShow'], 'year': videoItem['year'], 'imdb': videoItem['imdb']}
            videoList.append(videoItem)

        xbmc.executebuiltin("Dialog.Close(busydialog)")

        if len(videoList) > 0:
            fetcher = TvTunesFetcher(videoList, incAudioThemes, incVideoThemes)
            del fetcher
Example #7
0
    def fetchMissingThemes(self, incAudioThemes=True, incVideoThemes=False):
        # Prompt the user to see if they want all the themes or just some
        # of them
        displayList = []
        displayList.append(ADDON.getLocalizedString(32210))
        displayList.append(ADDON.getLocalizedString(32211))
        displayList.append(ADDON.getLocalizedString(32212))
        displayList.append(ADDON.getLocalizedString(32213))

        # Show the list to the user
        select = xbmcgui.Dialog().select(ADDON.getLocalizedString(32105),
                                         displayList)
        if select < 0:
            log("fetchMissingThemes: Cancelled by user")
            return

        # It could take a little while to get the videos so show the busy dialog
        xbmc.executebuiltin("ActivateWindow(busydialog)")

        tvShows = []
        if (select == 0) or (select == 1):
            log("fetchMissingThemes: Checking TV Shows")
            tvShows = self.getVideos('GetTVShows', MenuNavigator.TVSHOWS)
        movies = []
        if (select == 0) or (select == 2):
            log("fetchMissingThemes: Checking Movies")
            movies = self.getVideos('GetMovies', MenuNavigator.MOVIES)
        music = []
        if (select == 0) or (select == 3):
            log("fetchMissingThemes: Checking Music Videos")
            music = self.getVideos('GetMusicVideos', MenuNavigator.MUSICVIDEOS)

        videoList = []

        moveExistingThemes = None

        for videoItem in (tvShows + movies + music):
            # Get the path where the theme should be stored
            path = self.getPathForVideoItem(videoItem)
            # Skip items that already have themes
            if self._doesThemeExist(path, False, incAudioThemes,
                                    incVideoThemes):
                continue

            if Settings.isThemeDirEnabled() and self._doesThemeExist(
                    path, True, incAudioThemes, incVideoThemes):
                if moveExistingThemes is None:
                    xbmc.executebuiltin("Dialog.Close(busydialog)")
                    # Prompt user if we should move themes in the parent
                    # directory into the theme directory
                    moveExistingThemes = xbmcgui.Dialog().yesno(
                        ADDON.getLocalizedString(32105),
                        ADDON.getLocalizedString(32206),
                        ADDON.getLocalizedString(32207))
                    xbmc.executebuiltin("ActivateWindow(busydialog)")

                # Check if we need to move a theme file
                if moveExistingThemes:
                    log("fetchAllMissingThemes: Moving theme for %s" %
                        videoItem['title'])
                    self._moveToThemeFolder(path)
                continue

            normtitle = normalize_string(videoItem['title']).encode("utf-8")
            normOriginalTitle = None
            if videoItem['originaltitle'] is not None:
                normOriginalTitle = normalize_string(
                    videoItem['originaltitle']).encode("utf-8")

            videoItem = {
                'title': normtitle,
                'path': path.encode("utf-8"),
                'originalTitle': normOriginalTitle,
                'isTvShow': videoItem['isTvShow'],
                'year': videoItem['year'],
                'imdb': videoItem['imdb']
            }
            videoList.append(videoItem)

        xbmc.executebuiltin("Dialog.Close(busydialog)")

        if len(videoList) > 0:
            fetcher = TvTunesFetcher(videoList, incAudioThemes, incVideoThemes)
            del fetcher
Example #8
0
    def getThemes(self):
        themePath = ""
        # Only need the theme path for videos
        if not WindowShowing.isMusicSection():
            # Check if the files are stored in a custom path
            if Settings.isCustomPathEnabled():
                if not WindowShowing.isMovies():
                    videotitle = xbmc.getInfoLabel("ListItem.TVShowTitle")
                else:
                    videotitle = xbmc.getInfoLabel("ListItem.Title")
                videotitle = normalize_string(videotitle)
                themePath = os_path_join(Settings.getCustomPath(), videotitle)

            # Looking at the TV Show information page
            elif WindowShowing.isMovieInformation() and (
                    WindowShowing.isTvShowTitles()
                    or WindowShowing.isTvShows()):
                themePath = xbmc.getInfoLabel("ListItem.FilenameAndPath")
            else:
                themePath = xbmc.getInfoLabel("ListItem.Path")

        # To try and reduce the amount of "noise" in the logging, where the
        # same check is logged again and again, we record if it has been
        # logged for this video, and then do not do it again until the
        # video changes and what we would print wound be different
        debug_logging_enabled = False

        # Only log if something is different from the last time we logged
        if self.lastLoggedThemePath != themePath:
            debug_logging_enabled = True
            self.lastLoggedThemePath = themePath

        log("TunesBackend: themePath = %s" % themePath, debug_logging_enabled)

        # Check if the selection is a Movie Set
        if WindowShowing.isMovieSet():
            movieSetMap = self._getMovieSetFileList()

            if Settings.isCustomPathEnabled():
                # Need to make the values part (the path) point to the custom path
                # rather than the video file
                for aKey in movieSetMap.keys():
                    videotitle = normalize_string(aKey)
                    movieSetMap[aKey] = os_path_join(Settings.getCustomPath(),
                                                     videotitle)

            if len(movieSetMap) < 1:
                themefile = ThemeFiles(
                    "", debug_logging_enabled=debug_logging_enabled)
            else:
                themefile = ThemeFiles(
                    themePath,
                    movieSetMap.values(),
                    debug_logging_enabled=debug_logging_enabled)

        # When the reference is into the database and not the file system
        # then don't return it
        elif themePath.startswith("videodb:"):
            # If in either the Tv Show List or the Movie list then
            # need to stop the theme is selecting the back button
            if WindowShowing.isMovies() or WindowShowing.isTvShowTitles():
                themefile = ThemeFiles(
                    "", debug_logging_enabled=debug_logging_enabled)
            else:
                # Load the previous theme
                themefile = self.newThemeFiles
        else:
            if WindowShowing.isMusicSection():
                themefile = MusicThemeFiles(debug_logging_enabled)
            else:
                themefile = ThemeFiles(
                    themePath, debug_logging_enabled=debug_logging_enabled)

                # Check if no themes were found for this item, there is a case if it is a
                # TV Show and it is nested Show-Name/Series-X/Episode-Directory/Episode.ext
                # Then this will not pick up themes in the root of the TV Show directory
                if (not themefile.hasThemes()) and (
                        not Settings.isCustomPathEnabled()
                ) and WindowShowing.isEpisodes():
                    tvshowTitle = xbmc.getInfoLabel("ListItem.TVShowTitle")
                    if tvshowTitle not in [None, ""]:
                        try:
                            # Make a call to the database to find out the root path of this TV Show
                            filterStr = '{"operator": "is", "field": "title", "value": "%s"}' % tvshowTitle
                            cmd = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["file"], "filter": %s},"id": 1 }' % filterStr
                            json_query = executeJSONRPC(cmd)
                            json_query = simplejson.loads(json_query)
                            if ("result" in json_query) and (
                                    'tvshows' in json_query['result']):
                                # Get the path to the TV Show and compare it to where we were previously
                                # looking
                                tvshowList = json_query['result']['tvshows']
                                if len(tvshowList) == 1:
                                    tvshowPath = json_query['result'][
                                        'tvshows'][0]['file']
                                    # Make sure we have not already checked this path
                                    # We will already have checked the parent path as well
                                    if (tvshowPath != themePath) and (
                                            tvshowPath !=
                                            os_path_split(themePath)[0]):
                                        # So we know that we haven't checked the root of this TV Show yet
                                        log(
                                            "TunesBackend: Checking root TV Show Path = %s"
                                            % tvshowPath,
                                            debug_logging_enabled)
                                        themefile = ThemeFiles(
                                            tvshowPath,
                                            debug_logging_enabled=
                                            debug_logging_enabled)
                        except:
                            log(
                                "TunesBackend: Failed to check root TV Show %s"
                                % traceback.format_exc(),
                                debug_logging_enabled)

        return themefile