]> code.delx.au - webdl/commitdiff
autograbber: implement .excludes.txt (fixes #75)
authorJames Bunton <jamesbunton@delx.net.au>
Tue, 20 Aug 2019 15:02:12 +0000 (01:02 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Tue, 20 Aug 2019 15:02:12 +0000 (01:02 +1000)
README.md
autograbber.py

index 8768a420508040a0eb79d3188d39bbec2753e9fd..ac6de8224e8f0f6e33ee7d66200e4a3e1f5f12b4 100644 (file)
--- 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.
 
 
index c1e3fa279db313ee21a18544119f943a8278b9f5..1927a261554f4675ab9380890dbbcdf868f36a60 100755 (executable)
@@ -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: