aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2024-09-10 17:38:51 +0200
committerWolfgang Müller2024-09-10 17:38:51 +0200
commitf6ae35a596f26444122f828979936b706e57fe51 (patch)
tree2b229c5a76f9a04a8b7256ec2aaa9e268537a997
downloadlater-f6ae35a596f26444122f828979936b706e57fe51.tar.gz
Initial commit
-rw-r--r--LICENSE15
-rw-r--r--Makefile7
-rwxr-xr-xlater49
-rw-r--r--later.121
4 files changed, 92 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..36c1528
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,15 @@
+ISC License
+
+Copyright (c) 2024 Wolfgang Müller
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d9e9eba
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,7 @@
+PREFIX ?= /usr/local
+
+install: later later.1
+ install -D -m 755 -t '${DESTDIR}${PREFIX}/bin' later
+ install -D -m 644 -t '${DESTDIR}${PREFIX}/share/man/man1' later.1
+
+.PHONY: install
diff --git a/later b/later
new file mode 100755
index 0000000..2a9e955
--- /dev/null
+++ b/later
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+import datetime
+import os
+import argparse
+
+from datetime import datetime as dt
+
+xdg_config_home = os.path.expanduser("~/.local/state")
+if "XDG_STATE_HOME" in os.environ:
+ xdg_config_home = os.environ["XDG_STATE_HOME"]
+
+watch_later_dir = os.path.join(xdg_config_home, "mpv/watch_later")
+
+
+def entries():
+ def get_mtime(entry):
+ return entry.stat().st_mtime
+
+ with os.scandir(watch_later_dir) as entries:
+ for entry in sorted(entries, key=get_mtime):
+ if entry.is_file():
+ mtime = dt.fromtimestamp(get_mtime(entry))
+ yield entry.path, entry.name, mtime
+
+
+parser = argparse.ArgumentParser(
+ prog="later", description="List mpv's watch_later entries"
+)
+args = parser.parse_args()
+
+for path, basename, mtime in entries():
+ with open(path, "r") as handle:
+ first = handle.readline().rstrip()
+
+ name = basename
+ if first.startswith("# "):
+ name = first.strip("# ")
+
+ if name == "redirect entry":
+ continue
+
+ def format_time(time):
+ now = dt.now()
+ if time < now - datetime.timedelta(days=7):
+ return time.strftime("%b %d %Y")
+ return time.strftime("%b %d %H:%M")
+
+ print(f"{format_time(mtime)}\t{name}")
diff --git a/later.1 b/later.1
new file mode 100644
index 0000000..6b2bec9
--- /dev/null
+++ b/later.1
@@ -0,0 +1,21 @@
+.Dd September 10, 2024
+.Dt LATER 1
+.Os
+.Sh NAME
+.Nm later
+.Nd list mpv's watch_later entries
+.Sh SYNOPSIS
+.Nm
+.Op Fl h
+.Op Fl \-help
+.Sh DESCRIPTION
+.Nm
+lists all watch_later entries as saved by
+.Xr mpv 1 .
+.Sh SEE ALSO
+.Xr mpv 1
+.Sh AUTHORS
+.An -nosplit
+.Nm
+was written by
+.An Wolfgang Müller Aq Mt wolf@oriole.systems