コード例 #1
0
ファイル: tv_shows.py プロジェクト: Bolayniuss/TomatoPy
    def get_new_episodes(self):
        """
        Returns a list of episodes ready to download
        :return: a list of episodes ready to download
        :rtype: list of Episode
        """
        # TODO: move content of first "for loop" in EpisodeProvider.getNewEpisode(trackedTvShows). Keep verification on torrent manager
        # TODO: move deleteBadChars to Tools module
        episodes = []
        for episode_provider in self.registered_episode_providers:
            try:
                episode_provided = episode_provider.get_episodes()
                for episode in episode_provided:
                    added = False
                    for e in episodes:
                        if e.tv_show == episode.tv_show and e.season == episode.season and e.episode_number == episode.episode_number:
                            added = True
                            break
                    if not added:
                        # self.logger.debug("Episode : %s (%s)", episode.title, episode.tvShow)

                        tracked_tv_show = self.get_tracked_tv_show(episode)
                        if tracked_tv_show:
                            # self.logger.debug("is in tracked tv shows")

                            if not self.directory_mapper.file_exists(episode.title):
                                # self.logger.debug("%s ,is not in source directory", episode.title)

                                torrent_search_string = "%s S%02dE%02d" % (
                                    tracked_tv_show.search_string, episode.season, episode.episode_number)
                                pattern = tools.delete_bad_chars(torrent_search_string)
                                pattern = pattern.replace(" ", ".*")
                                if not self.torrent_manager.search_in_torrents(pattern):
                                    # self.logger.debug("%s doesn't exists in torrentManager.torrents", episode.title)

                                    episodes.append(TrackedEpisode(episode, tracked_tv_show))
                                    self.logger.info("%s flagged as new.", episode.title)
                                else:
                                    self.logger.debug("%s not added, already in the downloads list.", episode.title)
                            else:
                                self.logger.debug("%s not added, already in the downloaded list.", episode.title)
                        else:
                            self.logger.debug("%s not added, not a tracked TvShow.", episode.title)
                    else:
                        self.logger.debug("%s not added, already in the added list.", episode.title)
            except Exception:
                self.logger.exception("Error while getting new episodes")
        return episodes
コード例 #2
0
ファイル: tv_shows.py プロジェクト: Bolayniuss/TomatoPy
    def execute_action(self, action_data):
        """
        Execute generic action

        :param list action_data: list
        :return: success
        :rtype bool:
        """
        data = action_data

        hash_string = data[1]
        tv_show = data[2]
        episode_name = data[3]
        try:
            torrent = self.torrent_manager.get_torrent(hash_string)
            if torrent.is_finished:
                pattern = tools.delete_bad_chars(episode_name)
                pattern = pattern.replace(" ", ".")
                filter_ = FileFilter(pattern, ["mkv", "avi", "mp4"])
                if data[0] == "move":
                    self.logger.info("move action")
                    try:
                        file_to_move = self.get_tv_show_file_from_torrent(torrent, filter_)
                        if file_to_move:
                            success = False
                            destination_path = self.get_episode_final_path(file_to_move, tv_show, episode_name)
                            source_file_path = file_to_move.get_full_path()
                            self.logger.info("try to move %s* to %s", source_file_path, destination_path)
                            if len(source_file_path) > 0:
                                success = tools.FileSystemHelper.Instance().move(source_file_path, destination_path)
                            if success:
                                self.logger.info("move succeed")
                                time.sleep(0.5)
                                XbmcLibraryManager.Instance().scan_video_library(
                                    tools.PathSubstitution.Instance().substitute(os.path.dirname(os.path.dirname(destination_path)))
                                )
                                self.logger.info("delete associated torrent")
                                self.torrent_manager.remove_torrent(hash_string, True)
                                NotificationManager.Instance().add_notification(
                                    torrent.name,
                                    "TvShowManager: Done", Expiration(weeks=4)
                                )
                                return True
                            # else
                            self.logger.warn("Failed to move %s", torrent.name)
                            NotificationManager.Instance().add_notification(
                                "Move failure in %s" % torrent.name,
                                "TvShowManager: Errors", Expiration()
                            )
                        else:
                            self.logger.warn("No valid file found in %s", torrent.name)
                            NotificationManager.Instance().add_notification(
                                "No valid file found in %s" % torrent.name,
                                "TvShowManager: Errors", Expiration()
                            )
                        return False
                    except IOError:
                        self.logger.error("error while moving file, file does not exists.")
                        NotificationManager.Instance().add_notification(
                            "File doesn't exists %s" % torrent.name,
                            "TvShowManager: Errors", Expiration()
                        )
            else:
                self.logger.info("Torrent %s isn't yet finished", torrent.name)
                prc = 0 if not torrent.size else float(torrent.downloaded) / torrent.size
                NotificationManager.Instance().add_notification(
                    "%s %s" % ('{0:.0%}'.format(prc), torrent.name),
                    "TvShowManager: Downloading", Expiration()
                )
                return False
        except:
            self.logger.exception("Error while executing action %s", action_data)
        finally:
            pass
        return False
コード例 #3
0
ファイル: tv_shows.py プロジェクト: Bolayniuss/TomatoPy
    def execute_action(self, action_data):
        """
        Execute generic action

        :param list action_data: list
        :return: success
        :rtype bool:
        """
        data = action_data

        hash_string = data[1]
        tv_show = data[2]
        episode_name = data[3]
        try:
            torrent = self.torrent_manager.get_torrent(hash_string)
            if torrent.is_finished:
                pattern = tools.delete_bad_chars(episode_name)
                pattern = pattern.replace(" ", ".")
                filter_ = FileFilter(pattern, ["mkv", "avi", "mp4"])
                if data[0] == "move":
                    self.logger.info("move action")
                    try:
                        file_to_move = self.get_tv_show_file_from_torrent(
                            torrent, filter_)
                        if file_to_move:
                            success = False
                            destination_path = self.get_episode_final_path(
                                file_to_move, tv_show, episode_name)
                            source_file_path = file_to_move.get_full_path()
                            self.logger.info("try to move %s* to %s",
                                             source_file_path,
                                             destination_path)
                            if len(source_file_path) > 0:
                                success = tools.FileSystemHelper.Instance(
                                ).move(source_file_path, destination_path)
                            if success:
                                self.logger.info("move succeed")
                                time.sleep(0.5)
                                XbmcLibraryManager.Instance(
                                ).scan_video_library(
                                    tools.PathSubstitution.Instance(
                                    ).substitute(
                                        os.path.dirname(
                                            os.path.dirname(
                                                destination_path))))
                                self.logger.info("delete associated torrent")
                                self.torrent_manager.remove_torrent(
                                    hash_string, True)
                                NotificationManager.Instance(
                                ).add_notification(torrent.name,
                                                   "TvShowManager: Done",
                                                   Expiration(weeks=4))
                                return True
                            # else
                            self.logger.warn("Failed to move %s", torrent.name)
                            NotificationManager.Instance().add_notification(
                                "Move failure in %s" % torrent.name,
                                "TvShowManager: Errors", Expiration())
                        else:
                            self.logger.warn("No valid file found in %s",
                                             torrent.name)
                            NotificationManager.Instance().add_notification(
                                "No valid file found in %s" % torrent.name,
                                "TvShowManager: Errors", Expiration())
                        return False
                    except IOError:
                        self.logger.error(
                            "error while moving file, file does not exists.")
                        NotificationManager.Instance().add_notification(
                            "File doesn't exists %s" % torrent.name,
                            "TvShowManager: Errors", Expiration())
            else:
                self.logger.info("Torrent %s isn't yet finished", torrent.name)
                prc = 0 if not torrent.size else float(
                    torrent.downloaded) / torrent.size
                NotificationManager.Instance().add_notification(
                    "%s %s" % ('{0:.0%}'.format(prc), torrent.name),
                    "TvShowManager: Downloading", Expiration())
                return False
        except:
            self.logger.exception("Error while executing action %s",
                                  action_data)
        finally:
            pass
        return False
コード例 #4
0
ファイル: tv_shows.py プロジェクト: Bolayniuss/TomatoPy
    def get_new_episodes(self):
        """
        Returns a list of episodes ready to download
        :return: a list of episodes ready to download
        :rtype: list of Episode
        """
        # TODO: move content of first "for loop" in EpisodeProvider.getNewEpisode(trackedTvShows). Keep verification on torrent manager
        # TODO: move deleteBadChars to Tools module
        episodes = []
        for episode_provider in self.registered_episode_providers:
            try:
                episode_provided = episode_provider.get_episodes()
                for episode in episode_provided:
                    added = False
                    for e in episodes:
                        if e.tv_show == episode.tv_show and e.season == episode.season and e.episode_number == episode.episode_number:
                            added = True
                            break
                    if not added:
                        # self.logger.debug("Episode : %s (%s)", episode.title, episode.tvShow)

                        tracked_tv_show = self.get_tracked_tv_show(episode)
                        if tracked_tv_show:
                            # self.logger.debug("is in tracked tv shows")

                            if not self.directory_mapper.file_exists(
                                    episode.title):
                                # self.logger.debug("%s ,is not in source directory", episode.title)

                                torrent_search_string = "%s S%02dE%02d" % (
                                    tracked_tv_show.search_string,
                                    episode.season, episode.episode_number)
                                pattern = tools.delete_bad_chars(
                                    torrent_search_string)
                                pattern = pattern.replace(" ", ".*")
                                if not self.torrent_manager.search_in_torrents(
                                        pattern):
                                    # self.logger.debug("%s doesn't exists in torrentManager.torrents", episode.title)

                                    episodes.append(
                                        TrackedEpisode(episode,
                                                       tracked_tv_show))
                                    self.logger.info("%s flagged as new.",
                                                     episode.title)
                                else:
                                    self.logger.debug(
                                        "%s not added, already in the downloads list.",
                                        episode.title)
                            else:
                                self.logger.debug(
                                    "%s not added, already in the downloaded list.",
                                    episode.title)
                        else:
                            self.logger.debug(
                                "%s not added, not a tracked TvShow.",
                                episode.title)
                    else:
                        self.logger.debug(
                            "%s not added, already in the added list.",
                            episode.title)
            except Exception:
                self.logger.exception("Error while getting new episodes")
        return episodes