Exemple #1
0
    def scan_library(self, my_status=None, rescan=False):
        # Check if operation is supported by the API
        if not self.mediainfo.get('can_play'):
            raise utils.EngineError(
                'Operation not supported by current site or mediatype.')
        if not self.config['searchdir']:
            raise utils.EngineError('Media directory is not set.')
        if not utils.dir_exists(self.config['searchdir']):
            raise utils.EngineError('The set media directory doesn\'t exist.')

        t = time.time()
        library = {}
        library_cache = self.data_handler.library_cache_get()

        if not my_status:
            my_status = self.mediainfo['status_start']

        self.msg.info(self.name, "Scanning local library...")
        self.msg.debug(self.name, "Directory: %s" % self.config['searchdir'])
        tracker_list = self._get_tracker_list(my_status)

        # Do a full listing of the media directory
        for fullpath, filename in utils.regex_find_videos(
                'mkv|mp4|avi', self.config['searchdir']):
            (library, library_cache) = self._add_show_to_library(
                library, library_cache, rescan, fullpath, filename,
                tracker_list)

        self.msg.debug(self.name, "Time: %s" % (time.time() - t))
        self.data_handler.library_save(library)
        self.data_handler.library_cache_save(library_cache)
        return library
Exemple #2
0
 def _searchdir_exists(self, path):
     """Variation of dir_exists that warns the user if the path doesn't exist."""
     if not utils.dir_exists(path):
         self.msg.warn(
             self.name, "The specified media directory {} doesn't exist!".format(path))
         return False
     return True
Exemple #3
0
    def scan_library(self, my_status=None, rescan=False):
        # Check if operation is supported by the API
        if not self.mediainfo.get('can_play'):
            raise utils.EngineError('Operation not supported by current site or mediatype.')
        if not self.config['searchdir']:
            raise utils.EngineError('Media directory is not set.')
        if not utils.dir_exists(self.config['searchdir']):
            raise utils.EngineError('The set media directory doesn\'t exist.')

        t = time.time()
        library = {}
        library_cache = self.data_handler.library_cache_get()

        if not my_status:
            if self.config['scan_whole_list']:
                my_status = self.mediainfo['statuses']
            else:
                my_status = self.mediainfo['status_start']

        self.msg.info(self.name, "Scanning local library...")
        self.msg.debug(self.name, "Directory: %s" % self.config['searchdir'])
        tracker_list = self._get_tracker_list(my_status)


        # Do a full listing of the media directory
        for fullpath, filename in utils.regex_find_videos('mkv|mp4|avi', self.config['searchdir']):
            (library, library_cache) = self._add_show_to_library(library, library_cache, rescan, fullpath, filename, tracker_list)

        self.msg.debug(self.name, "Time: %s" % (time.time() - t))
        self.data_handler.library_save(library)
        self.data_handler.library_cache_save(library_cache)
        return library
Exemple #4
0
    def play_episode(self, show, playep=0):
        """
        Does a local search in the hard disk (in the folder specified by the config file)
        for the specified episode (**playep**) for the specified **show**.

        If no **playep** is specified, the next episode of the show will be played.
        """
        # Check if operation is supported by the API
        if not self.mediainfo.get('can_play'):
            raise utils.EngineError(
                'Operation not supported by current site or mediatype.')
        if not self.config['searchdir']:
            raise utils.EngineError('Media directory is not set.')
        if not utils.dir_exists(self.config['searchdir']):
            raise utils.EngineError('The set media directory doesn\'t exist.')

        try:
            playep = int(playep)
        except ValueError:
            raise utils.EngineError('Episode must be numeric.')

        if show:
            playing_next = False
            if not playep:
                playep = show['my_progress'] + 1
                playing_next = True

            if show['total'] and playep > show['total']:
                raise utils.EngineError('Episode beyond limits.')

            if self.config.get('debug_oldsearch'):
                # Deprecated
                self.msg.info(
                    self.name,
                    "Searching for %s %s..." % (show['title'], playep))
                titles = self.data_handler.get_show_titles(show)
                filename, endep = self._search_video(titles, playep)
            else:
                self.msg.info(
                    self.name,
                    "Getting %s %s from library..." % (show['title'], playep))
                filename = self.get_episode_path(show, playep)
                endep = playep

            if filename:
                self.msg.info(self.name, 'Found. Starting player...')
                arg_list = shlex.split(self.config['player'])
                arg_list.append(filename)
                try:
                    with open(os.devnull, 'wb') as DEVNULL:
                        subprocess.Popen(arg_list,
                                         stdout=DEVNULL,
                                         stderr=DEVNULL)
                except OSError:
                    raise utils.EngineError(
                        'Player not found, check your config.json')
                return endep
            else:
                raise utils.EngineError('Episode file not found.')
Exemple #5
0
    def scan_library(self, my_status=None, ignorecache=False):
        # Check if operation is supported by the API
        if not self.mediainfo.get('can_play'):
            raise utils.EngineError('Operation not supported by current site or mediatype.')
        if not self.config['searchdir']:
            raise utils.EngineError('Media directory is not set.')
        if not utils.dir_exists(self.config['searchdir']):
            raise utils.EngineError('The set media directory doesn\'t exist.')

        t = time.time()
        library = {}
        library_cache = self.data_handler.library_cache_get()

        if not my_status:
            my_status = self.mediainfo['status_start']

        self.msg.info(self.name, "Scanning local library...")
        tracker_list = self._get_tracker_list(my_status)

        # Do a full listing of the media directory
        for fullpath, filename in utils.regex_find_videos('mkv|mp4|avi', self.config['searchdir']):
            show_id = None
            if not ignorecache and filename in library_cache.keys():
                # If the filename was already seen before
                # use the cached information, if there's no information (None)
                # then it means it doesn't correspond to any show in the list
                # and can be safely skipped.
                if library_cache[filename]:
                    show_id = library_cache[filename][0]
                    show_ep = library_cache[filename][1]
                else:
                    continue
            else:
                # If the filename has not been seen, extract
                # the information from the filename and do a fuzzy search
                # on the user's list. Cache the information.
                # If it fails, cache it as None.
                aie = AnimeInfoExtractor(filename)
                (show_title, show_ep) = (aie.getName(), aie.getEpisode())
                if show_title:
                    show = utils.guess_show(show_title, tracker_list)
                    if show:
                        show_id = show['id']
                        library_cache[filename] = (show['id'], show_ep)
                    else:
                        library_cache[filename] = None
                else:
                    library_cache[filename] = None

            # After we got our information, add it to our library
            if show_id:
                if show_id not in library.keys():
                    library[show_id] = {}
                library[show_id][show_ep] = fullpath

        self.msg.debug(self.name, "Time: %s" % (time.time() - t))
        self.data_handler.library_save(library)
        self.data_handler.library_cache_save(library_cache)
        return library
Exemple #6
0
    def play_episode(self, show, playep=0):
        """
        Does a local search in the hard disk (in the folder specified by the config file)
        for the specified episode (**playep**) for the specified **show**.

        If no **playep** is specified, the next episode of the show will be played.
        """
        # Check if operation is supported by the API
        if not self.mediainfo.get('can_play'):
            raise utils.EngineError('Operation not supported by current site or mediatype.')
        if not self.config['searchdir']:
            raise utils.EngineError('Media directory is not set.')
        if not utils.dir_exists(self.config['searchdir']):
            raise utils.EngineError('The set media directory doesn\'t exist.')

        try:
            playep = int(playep)
        except ValueError:
            raise utils.EngineError('Episode must be numeric.')

        if show:
            playing_next = False
            if not playep:
                playep = show['my_progress'] + 1
                playing_next = True

            if show['total'] and playep > show['total']:
                raise utils.EngineError('Episode beyond limits.')

            if self.config.get('debug_oldsearch'):
                # Deprecated
                self.msg.info(self.name, "Searching for %s %s..." % (show['title'], playep))
                titles = self.data_handler.get_show_titles(show)
                filename, endep = self._search_video(titles, playep)
            else:
                self.msg.info(self.name, "Getting %s %s from library..." % (show['title'], playep))
                filename = self.get_episode_path(show, playep)
                endep = playep

            if filename:
                self.msg.info(self.name, 'Found. Starting player...')
                arg_list = shlex.split(self.config['player'])
                arg_list.append(filename)
                try:
                    with open(os.devnull, 'wb') as DEVNULL:
                        subprocess.Popen(arg_list, stdout=DEVNULL, stderr=DEVNULL)
                except OSError:
                    raise utils.EngineError('Player not found, check your config.json')
                return endep
            else:
                raise utils.EngineError('Episode file not found.')
Exemple #7
0
 def _searchdir_exists(self, path):
     """Variation of dir_exists that warns the user if the path doesn't exist."""
     if not utils.dir_exists(path):
         self.msg.warn(self.name, "The specified media directory {} doesn't exist!".format(path))
         return False
     return True