diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-01-22 00:36:50 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-01-22 00:36:50 +0100 |
commit | 5988e4062c6b0c80a8d44f1ce6adbc9c99837d92 (patch) | |
tree | c1c1a782906064c6cbb9654480197d7827525de8 /list-missing-unwatched.py | |
parent | c0e9dacb776acf5ca992f0753bc716ef761489ae (diff) |
Add script to automatically track anime from dmenu list, add another script to list tracked but locally missing episodes
Diffstat (limited to 'list-missing-unwatched.py')
-rwxr-xr-x | list-missing-unwatched.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/list-missing-unwatched.py b/list-missing-unwatched.py new file mode 100755 index 0000000..4dab88c --- /dev/null +++ b/list-missing-unwatched.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys + +def show_notification(title, description, urgency): + print("Notification: title: %s, description: %s" % (title, description)) + process = subprocess.Popen(["notify-send", "-t", "10000", "-u", urgency, "--", title, description]) + stdout, stderr = process.communicate() + return process.returncode == 0 + +def get_downloaded(): + process = subprocess.Popen(["automedia", "downloaded"], stdout=subprocess.PIPE) + stdout, stderr = process.communicate() + if process.returncode != 0: + return None + return stdout.decode("utf-8").splitlines(False) + +def get_seen(): + try: + with open(os.path.expanduser("~/.config/automedia/seen")) as file: + return file.read().splitlines() + except IOError as err: + return [] + +def main(): + if len(sys.argv) != 2: + print("usage: list-missing-unwatched.py <automedia-download-dir>") + sys.exit(1) + + automedia_dir = sys.argv[1] + if not os.path.exists(automedia_dir): + show_notification("list-missing-unwatched", "No such file or directory: " % automedia_dir, "critical") + sys.exit(2) + + downloaded = get_downloaded() + if not downloaded: + show_notification("list-missing-unwatched", "Failed to get downloaded episodes/chapters", "critical") + sys.exit(2) + + downloaded = dict.fromkeys(downloaded) + seen = dict.fromkeys(get_seen()) + unwatched = [t for t in downloaded if t not in seen] + missing = [u for u in unwatched if not os.path.exists(os.path.join(automedia_dir, u))] + for u in missing: + print(u) + +if __name__ == "__main__": + main() |