Example #1
0
 def getQuickSearch(self, searchTerm):
     """
     Retrieve data for quick search
     We will check for search term to be (partially) present in showname or title
      
     Parameters
     ----------
     searchTerm : str, optional
         search term which is contained in showname or title
     Returns
     -------
     Array
         Resultset of the query
     """
     self.logger.debug('getQuickSearch')
     #
     esModel = ExtendedSearchModel.ExtendedSearchModel('')
     esModel.setShow(searchTerm)
     esModel.setTitle(searchTerm)
     cacheKey = searchTerm + esModel.generateMinLength(
     ) + esModel.generateIgnoreTrailer() + esModel.generateMaxRows()
     cached_data = self._cache.load_cache('quickSearch', cacheKey)
     if cached_data is not None:
         rs = cached_data
     else:
         rs = self.extendedSearchQuery(esModel)
         self._cache.save_cache('quickSearch', cacheKey, rs)
     #
     return rs
 def migrateExtendedSearch(self):
     import resources.lib.mvutils as mvutils
     oldExtSearchFilename = os.path.join(
         appContext.MVSETTINGS.getDatapath(), 'recent_ext_searches.json')
     self.logger.debug("migrateExtendedSearch {}",
                       mvutils.file_exists(oldExtSearchFilename))
     if mvutils.file_exists(oldExtSearchFilename):
         oldData = mvutils.loadJsonFile(oldExtSearchFilename)
         self.logger.debug("Found legacy ext search entries to be migrated")
         if (oldData != None):
             newData = []
             lid = int(time.time())
             for entry in oldData:
                 esm = ExtendedSearchModel.ExtendedSearchModel(
                     entry.get('search'))
                 esm.setId(lid)
                 lid += 1
                 esm.setTitle(entry.get('search'))
                 esm.setDescription(entry.get('search'))
                 esm.setWhen(int(entry.get('when')))
                 newData.append(esm.toDict())
             #
             newExtSearchFilename = os.path.join(
                 appContext.MVSETTINGS.getDatapath(), 'searchConfig.json')
             mvutils.saveJsonFile(newExtSearchFilename, newData)
             self.logger.debug(
                 "Migrated {} legacy ext search entries to new format",
                 len(newData))
         #
         oldExtSearchFilenameBackup = os.path.join(
             appContext.MVSETTINGS.getDatapath(),
             'recent_ext_searches.json.bk')
         mvutils.file_rename(oldExtSearchFilename,
                             oldExtSearchFilenameBackup)
Example #3
0
 def _getModelById(self, pId):
     for entry in self.recents:
         if int(entry['id']) == int(pId):
             x = ExtendedSearchModel.ExtendedSearchModel("")
             x.fromDict(entry)
             return x
     return None
Example #4
0
 def getLivestreams(self):
     """
     Retrieve data for livestream screen
     """
     self.logger.debug('getLivestreams')
     #
     cached_data = self._cache.load_cache('livestreams', '')
     if cached_data is not None:
         rs = cached_data
     else:
         esModel = ExtendedSearchModel.ExtendedSearchModel('')
         esModel.reset()
         esModel.setShow('LIVESTREAM')
         esModel.setExactMatchForShow(True)
         rs = self.extendedSearchQuery(esModel)
         self._cache.save_cache('livestreams', '', rs)
     #
     return rs
Example #5
0
 def getFilms(self, channel='', showIds=''):
     """
     Retrieve data for recent films
     """
     self.logger.debug('getFilms')
     #
     esModel = ExtendedSearchModel.ExtendedSearchModel('')
     esModel.setChannel(channel)
     esModel.setShowId(showIds)
     #
     cacheKey = channel + showIds + esModel.generateMinLength(
     ) + esModel.generateIgnoreTrailer() + esModel.generateRecentCondition(
     ) + esModel.generateMaxRows()
     cached_data = self._cache.load_cache('films', cacheKey)
     if cached_data is not None:
         rs = cached_data
     else:
         rs = self.extendedSearchQuery(esModel)
         self._cache.save_cache('films', cacheKey, rs)
     #
     if len(rs) >= self.settings.getMaxResults():
         self.notifier.show_limit_results(self.settings.getMaxResults())
     #
     return rs
Example #6
0
    def show(self):
        """ populate UI with extended search elements """
        self.logger.debug('show action: {} searchId:{}', self.action,
                          self.searchId)
        start = time.time()
        #
        if self.action == "SHOW":
            self.showList()
            self.plugin.setViewId(self.plugin.resolveViewId('MAIN'))
        elif self.action == "RUN":
            data = self._getModelById(self.searchId)
            # self.database.extendedSearchQuery(data, FilmUI(self.plugin))
            ui = FilmlistUi.FilmlistUi(self.plugin)
            ui.generate(self.database.extendedSearch(data))

        elif self.action == "NEW":
            (txt, confirm) = self.notifier.get_entered_text(heading=30419)
            if confirm:
                x = ExtendedSearchModel.ExtendedSearchModel(txt)
                self.recents.append(x.toDict())
                self._save()
                self._load()
                #
                cmd = 'Container.update({}, replace)'.format(
                    self.plugin.build_url({
                        'mode': "extendedSearchScreen",
                        'extendedSearchAction': 'EDIT',
                        'searchId': x.getId()
                    }))
                self.plugin.end_of_directory(True, False, False)
                self.plugin.run_builtin(cmd)
            self.plugin.setViewId(self.plugin.resolveViewId('MAIN'))

        elif self.action == "EDIT":
            data = self._getModelById(self.searchId)
            self.showEntry(data)
            self.plugin.setViewId(self.plugin.resolveViewId('MAIN'))

        elif self.action == "DELETE":
            self.recents.remove(self._getItemById(self.searchId))
            self._save()
            #
            cmd = 'Container.refresh({})'.format(
                self.plugin.build_url({
                    'mode': "extendedSearchScreen",
                    'extendedSearchAction': 'SHOW'
                }))
            # def end_of_directory(self, succeeded=True, update_listing=False, cache_to_disc=False):
            self.plugin.end_of_directory(True, False, False)
            self.plugin.run_builtin(cmd)
            self.plugin.setViewId(self.plugin.resolveViewId('MAIN'))

        if self.action[:5] == 'EDIT-':
            #
            cmd = 'Container.update({}, replace)'.format(
                self.plugin.build_url({
                    'mode': "extendedSearchScreen",
                    'extendedSearchAction': 'EDIT',
                    'searchId': self.searchId
                }))
            #
            dataModel = self._getModelById(self.searchId)
            #
            if self.action == "EDIT-NAME":
                (txt, confirm) = self.notifier.get_entered_text(
                    deftext=dataModel.getNameAsString(), heading=30419)
                if confirm:
                    dataModel.setName(txt)

            elif self.action == "EDIT-TITLE":
                (txt, confirm) = self.notifier.get_entered_text(
                    deftext=dataModel.getTitleAsString(), heading=30412)
                if confirm:
                    dataModel.setTitle(txt)

            elif self.action == "EDIT-SHOW":
                (txt, confirm) = self.notifier.get_entered_text(
                    deftext=dataModel.getShowAsString(), heading=30411)
                if confirm:
                    dataModel.setShow(txt)

            elif self.action == "EDIT-DESCRIPTION":
                (txt, confirm) = self.notifier.get_entered_text(
                    deftext=dataModel.getDescriptionAsString(), heading=30413)
                if confirm:
                    dataModel.setDescription(txt)

            elif self.action == "EDIT-CHANNEL":
                channelList = self.database.getChannelList()
                #
                preselect = []
                for i, channelName in enumerate(channelList):
                    for selectedChannelName in dataModel.getChannel():
                        if selectedChannelName == channelName:
                            preselect.append(i)
                #
                selectedIdxList = self.notifier.get_entered_multiselect(
                    heading=30414, options=channelList, preselect=preselect)
                if selectedIdxList is not None:
                    selectedChannels = []
                    for idx in selectedIdxList:
                        selectedChannels.append(channelList[idx])
                    dataModel.setChannel("|".join(selectedChannels))

            elif self.action == "EDIT-MINLENGTH":
                (txt, confirm) = self.notifier.get_entered_text(
                    deftext=dataModel.getMinLengthAsString(), heading=30418)
                if confirm:
                    dataModel.setMinLength(txt)

            elif self.action == "EDIT-NOFUTURE":
                selectedIdx = self.notifier.get_entered_select(
                    heading=30417,
                    list=[
                        self.plugin.language(30409),
                        self.plugin.language(30410)
                    ],
                    preselect=int(dataModel.getIgnoreTrailerAsString()))
                if selectedIdx is not None and selectedIdx > -1:
                    dataModel.setIgnoreTrailer(selectedIdx)

            elif self.action == "EDIT-BLACKLIST":
                (txt, confirm) = self.notifier.get_entered_text(
                    deftext=dataModel.getExcludeTitleAsString(), heading=30415)
                if confirm:
                    dataModel.setExcludeTitle(txt)

            elif self.action == "EDIT-MAXROWS":
                (txt, confirm) = self.notifier.get_entered_text(
                    deftext=dataModel.getMaxResultsAsString(), heading=30115)
                if confirm:
                    dataModel.setMaxResults(txt)
            #
            #
            self._saveModel(dataModel)
            #
            self.plugin.end_of_directory(True, False, False)
            self.plugin.run_builtin(cmd)
        self.logger.debug('show processed: {} sec', time.time() - start)