aboutsummaryrefslogtreecommitdiff
path: root/src/tag-based-on-dir.py
diff options
context:
space:
mode:
authorChristian Segundo2024-07-23 21:43:05 +0200
committerChristian Segundo2024-07-23 21:43:05 +0200
commit362af4e16d7cdfa1512a6f2f154f055907b4d900 (patch)
treef0e8817df1cad49bd466c60016cdd8b70913690c /src/tag-based-on-dir.py
parent076b6aefd5b17cccc34cc403b7b4f2ba4f093a57 (diff)
downloadtransmission-hacks-362af4e16d7cdfa1512a6f2f154f055907b4d900.tar.gz
add ci
Diffstat (limited to 'src/tag-based-on-dir.py')
-rwxr-xr-xsrc/tag-based-on-dir.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/tag-based-on-dir.py b/src/tag-based-on-dir.py
new file mode 100755
index 0000000..8cec41b
--- /dev/null
+++ b/src/tag-based-on-dir.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+import click
+from transmission_rpc import Client
+
+
+@click.command()
+@click.option('--port', default=9091)
+@click.option('--root-dir', default="/downloads/complete")
+@click.option('--host', default="localhost")
+def main(host, port, root_dir):
+ """Adds tags to torrents based on their download directory."""
+
+ c = Client(host=host, port=port)
+ torrents = c.get_torrents()
+ for torrent in torrents:
+ dir = torrent.download_dir.replace(root_dir, '')
+ label = 'none'
+ if dir != '':
+ label = dir.split('/')[1]
+
+ labels = list([label])
+ labels.extend(x for x in torrent.labels if x not in labels)
+
+ if set(labels) != set(torrent.labels):
+ print(f"Tagging {torrent.name}")
+ c.change_torrent(torrent.id, labels=labels)
+
+
+if __name__ == '__main__':
+ main()