aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rwxr-xr-xlater27
-rw-r--r--later.114
2 files changed, 38 insertions, 3 deletions
diff --git a/later b/later
index 3eb9ea0..3ffc645 100755
--- a/later
+++ b/later
@@ -2,6 +2,7 @@
import datetime
import getopt
+import hashlib
import json
import os
import re
@@ -33,6 +34,7 @@ def usage(message=""):
lines.append("")
lines.append("usage: later [options] [list]")
+ lines.append(" [options] [add] item ...")
lines.append("options: [-u | --update-titles]")
sys.exit("\n".join(lines))
@@ -171,7 +173,7 @@ class Arguments:
rest: list[str] = field(default_factory=list)
-def parse_args(argv, commands, default):
+def parse_args(argv, commands, default, default_args):
try:
options, args = getopt.gnu_getopt(argv, "u", "update-titles")
except getopt.GetoptError as e:
@@ -187,6 +189,8 @@ def parse_args(argv, commands, default):
if args:
if args[0] in commands:
parsed_args.command = commands[args.pop(0)]
+ else:
+ parsed_args.command = commands[default_args]
parsed_args.rest = args
@@ -229,9 +233,26 @@ def list_entries(args, title_map):
print(entry.format(title_map))
-commands = {"list": Command("list", list_entries, implies_list=False, args=False)}
+def add_entries(args, title_map):
+ for entry in args.rest:
+ filename = hashlib.md5(entry.encode("utf-8")).hexdigest().upper()
+ path = os.path.join(watch_later_dir, filename)
-args = parse_args(sys.argv[1:], commands, "list")
+ try:
+ with open(path, "x") as handle:
+ handle.write(f"# {entry}\n")
+ except FileExistsError:
+ pass
+ except OSError as e:
+ exit(e)
+
+
+commands = {
+ "add": Command("add", add_entries),
+ "list": Command("list", list_entries, implies_list=False, args=False),
+}
+
+args = parse_args(sys.argv[1:], commands, "list", "add")
title_map = TitleMap(title_map_file, update=args.update_titles)
diff --git a/later.1 b/later.1
index a4be6b0..b9f38b4 100644
--- a/later.1
+++ b/later.1
@@ -8,6 +8,10 @@
.Nm
.Op options
.Op Ic list
+.Nm
+.Op options
+.Op Ic add
+.Ar item ...
.Sh DESCRIPTION
.Nm
is a program to manage watch_later entries as created by
@@ -26,10 +30,20 @@ update titles of videos using yt-dlp
.Pp
The commands are as follows:
.Bl -tag -width Ds
+.It Sy add Em item ...
+Creates watch_later entries for the given items.
+This command is implied if it wasn't explicitly given but there are
+remaining arguments.
.It Sy list
Lists all watch_later entries.
This command is implied if there are no remaining arguments.
.El
+.Pp
+An item may be a URL or a path to a file on the file system.
+Any command that modifies watch_later entries will subsequently print
+all entries just as if
+.Ic list
+was invoked.
.Sh FILES
.Bl -tag -width "1"
.It Pa $XDG_CACHE_HOME/later/titles.json