From bfaf019987c47406335b61c5825cabe21cafa107 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Wed, 21 Aug 2019 01:02:12 +1000 Subject: [PATCH] autograbber: implement .excludes.txt (fixes #75) --- README.md | 7 +++++++ autograbber.py | 25 ++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8768a42..ac6de82 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,13 @@ ABC iView/By Channel/ABC4Kids/*/* SBS/Channel/SBS1/Insight* ``` +You may optionally created a `.excludes.txt` file with shell-style globs. This is matched against the episode title and can be used to filter out things you don't want. For example: + +``` +*(Mandarin)* +*(Chinese)* +``` + Whenever an episode is downloaded it is recorded into `.downloaded_auto.txt`. Even if you move the files somewhere else they will not be redownloaded. diff --git a/autograbber.py b/autograbber.py index c1e3fa2..1927a26 100755 --- a/autograbber.py +++ b/autograbber.py @@ -9,13 +9,26 @@ import sys HISTORY_FILENAME = ".history.txt" PATTERN_FILENAME = ".patterns.txt" +EXCLUDE_FILENAME = ".excludes.txt" class DownloadList(object): def __init__(self): + self.exclude_list = set() + self._load_exclude_list() + self.seen_list = set() self._load_history_file() + self.f = open(HISTORY_FILENAME, "a") + def _load_exclude_list(self): + try: + with open(EXCLUDE_FILENAME, "r") as f: + for line in f: + self.exclude_list.add(line.strip()) + except Exception as e: + pass + def _load_history_file(self): self._move_old_file("downloaded_auto.txt") self._move_old_file(".downloaded_auto.txt") @@ -32,8 +45,14 @@ class DownloadList(object): logging.info("Migrating download history from %s to %s", old_filename, HISTORY_FILENAME) shutil.move(old_filename, HISTORY_FILENAME) - def has_seen(self, node): - return node.title.strip() in self.seen_list + def wants(self, node): + title = node.title.strip() + if title in self.seen_list: + return False + for exclude in self.exclude_list: + if fnmatch.fnmatch(title, exclude): + return False + return True def mark_seen(self, node): self.seen_list.add(node.title.strip()) @@ -43,7 +62,7 @@ class DownloadList(object): def match(download_list, node, pattern, count=0): if node.can_download: - if not download_list.has_seen(node): + if download_list.wants(node): if node.download(): download_list.mark_seen(node) else: -- 2.39.2