Ejemplo n.º 1
0
    def get_show_info(self, showid=None, title=None, filename=None):
        """
        Returns the show dictionary for the specified **showid**.
        """
        showdict = self.data_handler.get()

        if showid:
            # Get show by ID
            try:
                return showdict[showid]
            except KeyError:
                raise utils.EngineError("Show not found.")
        elif title:
            showdict = self.data_handler.get()
            # Get show by title, slower
            for k, show in showdict.items():
                if show['title'] == title:
                    return show
            raise utils.EngineError("Show not found.")
        elif filename:
            # Guess show by filename
            self.msg.debug(self.name, "Guessing by filename.")

            aie = AnimeInfoExtractor(filename)
            (show_title, ep) = aie.getName(), aie.getEpisode()
            self.msg.debug(self.name, "Guessed {}".format(show_title))

            if show_title:
                show = utils.guess_show(show_title, self._get_tracker_list())
                if show:
                    return (show, ep)
                else:
                    raise utils.EngineError("Show not found.")
            else:
                raise utils.EngineError("File name not recognized.")
Ejemplo n.º 2
0
    def _get_playing_show(self, filename):
        if not self.active:
            # Don't do anything if the Tracker is disabled
            return (utils.TRACKER_NOVIDEO, None)

        if filename:
            if filename == self.last_filename:
                # It's the exact same filename, there's no need to do the processing again
                return (self.last_state, self.last_show_tuple)

            self.last_filename = filename

            # Do a regex to the filename to get
            # the show title and episode number
            aie = AnimeInfoExtractor(filename)
            (show_title, show_ep) = (aie.getName(), aie.getEpisode())
            if not show_title:
                return (utils.TRACKER_UNRECOGNIZED, None)  # Format not recognized

            playing_show = utils.guess_show(show_title, self.list)
            if playing_show:
                return (utils.TRACKER_PLAYING, (playing_show, show_ep))
            else:
                # Show not in list
                if self.not_found_prompt:
                    # Dummy show to search for
                    show = {'id': 0, 'title': show_title}
                    return (utils.TRACKER_NOT_FOUND, (show, show_ep))
                else:
                    return (utils.TRACKER_NOT_FOUND, None)
        else:
            self.last_filename = None
            return (utils.TRACKER_NOVIDEO, None)  # Not playing
Ejemplo n.º 3
0
    def _get_playing_show(self, filename):
        if not self.active:
            # Don't do anything if the Tracker is disabled
            return (utils.TRACKER_NOVIDEO, None)

        if filename:
            if filename == self.last_filename:
                # It's the exact same filename, there's no need to do the processing again
                return (self.last_state, self.last_show_tuple)

            self.last_filename = filename

            # Do a regex to the filename to get
            # the show title and episode number
            aie = AnimeInfoExtractor(filename)
            (show_title, show_ep) = (aie.getName(), aie.getEpisode())
            if not show_title:
                return (utils.TRACKER_UNRECOGNIZED, None
                        )  # Format not recognized

            playing_show = utils.guess_show(show_title, self.list)
            if playing_show:
                return (utils.TRACKER_PLAYING, (playing_show, show_ep))
            else:
                # Show not in list
                if self.not_found_prompt:
                    # Dummy show to search for
                    show = {'id': 0, 'title': show_title}
                    return (utils.TRACKER_NOT_FOUND, (show, show_ep))
                else:
                    return (utils.TRACKER_NOT_FOUND, None)
        else:
            self.last_filename = None
            return (utils.TRACKER_NOVIDEO, None)  # Not playing
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def _add_show_to_library(self, library, library_cache, rescan, fullpath,
                             filename, tracker_list):
        show_id = None
        if not rescan and filename in library_cache:
            # 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, show_ep) = library_cache[filename]
                if type(show_ep) is tuple:
                    (show_ep_start, show_ep_end) = show_ep
                else:
                    show_ep_start = show_ep_end = show_ep
                self.msg.debug(self.name, "File in cache: {}".format(fullpath))
            else:
                self.msg.debug(
                    self.name,
                    "File in cache but skipped: {}".format(fullpath))
                return library, library_cache
        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 = aie.getName()
            (show_ep_start, show_ep_end) = aie.getEpisodeNumbers(True)
            if show_title:
                show = utils.guess_show(show_title, tracker_list)
                if show:
                    self.msg.debug(self.name,
                                   "Adding to library: {}".format(fullpath))

                    show_id = show['id']
                    if show_ep_start == show_ep_end:
                        library_cache[filename] = (show['id'], show_ep_start)
                    else:
                        library_cache[filename] = (show['id'], (show_ep_start,
                                                                show_ep_end))
                else:
                    self.msg.debug(self.name,
                                   "Not a show, skipping: {}".format(fullpath))
                    library_cache[filename] = None
            else:
                self.msg.debug(self.name,
                               "Not recognized, skipping: {}".format(fullpath))
                library_cache[filename] = None

        # After we got our information, add it to our library
        if show_id:
            if show_id not in library:
                library[show_id] = {}
            for show_ep in range(show_ep_start, show_ep_end + 1):
                library[show_id][show_ep] = fullpath
        return library, library_cache
Ejemplo n.º 6
0
    def _add_show_to_library(self, library, library_cache, rescan, fullpath, filename, tracker_list):
        show_id = None
        if not rescan and filename in library_cache:
            # 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, show_ep) = library_cache[filename]
                if type(show_ep) is tuple:
                    (show_ep_start, show_ep_end) = show_ep
                else:
                    show_ep_start = show_ep_end = show_ep
                self.msg.debug(self.name, "File in cache: {}".format(fullpath))
            else:
                self.msg.debug(self.name, "File in cache but skipped: {}".format(fullpath))
                return library, library_cache
        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 = aie.getName()
            (show_ep_start, show_ep_end) = aie.getEpisodeNumbers(True)
            if show_title:
                show = utils.guess_show(show_title, tracker_list)
                if show:
                    self.msg.debug(self.name, "Adding to library: {}".format(fullpath))

                    if show_ep_start == show_ep_end:
                        # TODO : Support redirections for episode ranges
                        (show, show_ep) = utils.redirect_show((show, show_ep_start), self.redirections, tracker_list)
                        show_ep_end = show_ep_start = show_ep

                        self.msg.debug(self.name, "Redirected to {} {}".format(show['title'], show_ep))
                        library_cache[filename] = (show['id'], show_ep)
                    else:
                        library_cache[filename] = (show['id'], (show_ep_start, show_ep_end))

                    show_id = show['id']
                else:
                    self.msg.debug(self.name, "Not a show, skipping: {}".format(fullpath))
                    library_cache[filename] = None
            else:
                self.msg.debug(self.name, "Not recognized, skipping: {}".format(fullpath))
                library_cache[filename] = None

        # After we got our information, add it to our library
        if show_id:
            if show_id not in library:
                library[show_id] = {}
            for show_ep in range(show_ep_start, show_ep_end+1):
                library[show_id][show_ep] = fullpath

        return library, library_cache
Ejemplo n.º 7
0
    def _get_playing_show(self, filename):
        if not self.active:
            # Don't do anything if the Tracker is disabled
            return (utils.TRACKER_NOVIDEO, None)

        if filename:
            self.msg.debug(self.name, "Guessing filename: {}".format(filename))

            # Trim out watch dir
            if os.path.isabs(filename):
                for watch_prefix in self.watch_dirs:
                    if filename.startswith(watch_prefix):
                        filename = filename[len(watch_prefix):]
                        if filename.startswith(os.path.sep):
                            filename = filename[len(os.path.sep):]
                        break

            if filename == self.last_filename:
                # It's the exact same filename, there's no need to do the processing again
                self.msg.debug(self.name, "Same filename as before. Skipping.")
                return (self.last_state, self.last_show_tuple)

            self.last_filename = filename

            # Do a regex to the filename to get
            # the show title and episode number
            aie = AnimeInfoExtractor(filename)
            (show_title, show_ep) = (aie.getName(), aie.getEpisode())
            if not show_title:
                # Format not recognized
                return (utils.TRACKER_UNRECOGNIZED, None)

            playing_show = utils.guess_show(show_title, self.list)
            self.msg.debug(
                self.name, "Show guess: {}: {}".format(show_title,
                                                       playing_show))

            if playing_show:
                (playing_show, show_ep) = utils.redirect_show(
                    (playing_show, show_ep), self.redirections, self.list)

                return (utils.TRACKER_PLAYING, (playing_show, show_ep))
            else:
                # Show not in list
                if self.config['tracker_not_found_prompt']:
                    # Dummy show to search for
                    show = {'id': 0, 'title': show_title}
                    return (utils.TRACKER_NOT_FOUND, (show, show_ep))
                else:
                    return (utils.TRACKER_NOT_FOUND, None)
        else:
            self.last_filename = None
            return (utils.TRACKER_NOVIDEO, None)  # Not playing
Ejemplo n.º 8
0
    def _get_playing_show(self, filename):
        if not self.active:
            # Don't do anything if the Tracker is disabled
            return (utils.TRACKER_NOVIDEO, None)

        if filename:
            self.msg.debug(self.name, "Guessing filename: {}".format(filename))

            # Trim out watch dir
            if os.path.isabs(filename):
                for watch_prefix in self.watch_dirs:
                    if filename.startswith(watch_prefix):
                        filename = filename[len(watch_prefix):]
                        if filename.startswith(os.path.sep):
                            filename = filename[len(os.path.sep):]
                        break

            if filename == self.last_filename:
                # It's the exact same filename, there's no need to do the processing again
                return (self.last_state, self.last_show_tuple)

            self.last_filename = filename

            # Do a regex to the filename to get
            # the show title and episode number
            aie = AnimeInfoExtractor(filename)
            (show_title, show_ep) = (aie.getName(), aie.getEpisode())
            if not show_title:
                return (utils.TRACKER_UNRECOGNIZED, None)  # Format not recognized

            playing_show = utils.guess_show(show_title, self.list)
            if playing_show:
                (playing_show, show_ep) = utils.redirect_show((playing_show, show_ep), self.redirections, self.list)

                return (utils.TRACKER_PLAYING, (playing_show, show_ep))
            else:
                # Show not in list
                if self.config['tracker_not_found_prompt']:
                    # Dummy show to search for
                    show = {'id': 0, 'title': show_title}
                    return (utils.TRACKER_NOT_FOUND, (show, show_ep))
                else:
                    return (utils.TRACKER_NOT_FOUND, None)
        else:
            self.last_filename = None
            return (utils.TRACKER_NOVIDEO, None)  # Not playing
Ejemplo n.º 9
0
    def get_show_info(self, showid=None, title=None, filename=None):
        """
        Returns the show dictionary for the specified **showid**.
        """
        showdict = self.data_handler.get()

        if showid:
            # Get show by ID
            try:
                return showdict[showid]
            except KeyError:
                raise utils.EngineError("Show not found.")
        elif title:
            showdict = self.data_handler.get()
            # Get show by title, slower
            for show in showdict.values():
                if show['title'] == title:
                    return show
            raise utils.EngineError("Show not found.")
        elif filename:
            # Guess show by filename
            self.msg.debug(self.name, "Guessing by filename.")

            aie = AnimeInfoExtractor(filename)
            (show_title, ep) = aie.getName(), aie.getEpisode()
            self.msg.debug(self.name, "Guessed {}".format(show_title))

            if show_title:
                tracker_list = self._get_tracker_list()

                show = utils.guess_show(show_title, tracker_list)
                if show:
                    return utils.redirect_show((show, ep), self.redirections, tracker_list)
                else:
                    raise utils.EngineError("Show not found.")
            else:
                raise utils.EngineError("File name not recognized.")