diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-01-16 02:36:38 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-01-16 02:36:38 +0100 |
commit | e3fbf4fc77c3688eea0528a2d04fac0728cdfe8c (patch) | |
tree | a1094c8c6a14217f5f11d28ecaa317930b62b54c | |
parent | 4906898393698525b7662d974cbd80dc71c40957 (diff) |
Add list-unwatched.py script to list episodes/chapters that you have downloaded but not seen (when using open_media.py)
-rwxr-xr-x | list-unwatched.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/list-unwatched.py b/list-unwatched.py new file mode 100755 index 0000000..ba56876 --- /dev/null +++ b/list-unwatched.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import os +import subprocess + +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(): + downloaded = get_downloaded() + if not downloaded: + show_notification("list-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] + + for u in unwatched: + print(u) + +if __name__ == "__main__": + main() |