aboutsummaryrefslogtreecommitdiff
path: root/scripts/delete-based-on-tag.py
diff options
context:
space:
mode:
authorChristian Segundo2023-06-10 00:11:39 +0200
committerChristian Segundo2023-06-10 00:11:39 +0200
commitbe52bd17ea01d8c302e39ba444194de282dc4728 (patch)
treeb1d69842363bce20f3b3141b529b52877dfdbbd7 /scripts/delete-based-on-tag.py
downloadtransmission-hacks-be52bd17ea01d8c302e39ba444194de282dc4728.tar.gz
First commit
Diffstat (limited to 'scripts/delete-based-on-tag.py')
-rwxr-xr-xscripts/delete-based-on-tag.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/delete-based-on-tag.py b/scripts/delete-based-on-tag.py
new file mode 100755
index 0000000..a5e2d0b
--- /dev/null
+++ b/scripts/delete-based-on-tag.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+import click
+from transmission_rpc import Client
+from datetime import timedelta, datetime
+
+
+def convert_to_seconds(s):
+ units = {"s": "seconds", "m": "minutes",
+ "h": "hours", "d": "days", "w": "weeks"}
+ count = int(s[:-1])
+ unit = units[s[-1]]
+ td = timedelta(**{unit: count})
+ return td.seconds + 60 * 60 * 24 * td.days
+
+
+@click.command()
+@click.option('--port', default=9091)
+@click.option('--host', default="localhost")
+@click.option('--tag', required=True)
+@click.option('--age', default='1w')
+def main(host, port, tag, age):
+ """ Deletes torrents older than the specified age. """
+
+ c = Client(host=host, port=port)
+ torrents = c.get_torrents()
+ for torrent in torrents:
+ if tag not in torrent.labels:
+ continue
+
+ specified_age = convert_to_seconds(age)
+ age_in_seconds = int((datetime.today().timestamp() -
+ torrent.added_date.timestamp()))
+
+ if age_in_seconds > specified_age:
+ print(f"Deleting {torrent.name}")
+ c.remove_torrent(torrent.id, delete_data=True)
+
+
+if __name__ == '__main__':
+ main()