diff options
-rw-r--r-- | hm/soispha/pkgs/default.nix | 1 | ||||
-rw-r--r-- | hm/soispha/pkgs/scripts.nix | 15 | ||||
-rw-r--r-- | hm/soispha/pkgs/scripts/specific/ytcc/filter_comments.jq | 20 | ||||
-rwxr-xr-x | hm/soispha/pkgs/scripts/specific/ytcc/filter_comments.sh | 13 | ||||
-rwxr-xr-x | hm/soispha/pkgs/scripts/specific/ytcc/nest_comments.py | 98 |
5 files changed, 1 insertions, 146 deletions
diff --git a/hm/soispha/pkgs/default.nix b/hm/soispha/pkgs/default.nix index c43ec7a7..2a99fc7c 100644 --- a/hm/soispha/pkgs/default.nix +++ b/hm/soispha/pkgs/default.nix @@ -87,6 +87,7 @@ with pkgs; let ytc # My tool to download the videos (used in conjunction with the entry above) yts # My tool to select the videos (used in conjunction with the entry above) yt # My tool to both select and then download the videos (a merged version of the two entries above) + comments # My tool to display comments ]; Listen = [ diff --git a/hm/soispha/pkgs/scripts.nix b/hm/soispha/pkgs/scripts.nix index f263ff5e..ae0ee827 100644 --- a/hm/soispha/pkgs/scripts.nix +++ b/hm/soispha/pkgs/scripts.nix @@ -73,14 +73,6 @@ inherit (pkgs) jq fmt less locale; }; }; - filter-comments-scr = sysLib.writeShellScript { - name = "comments"; - src = ./scripts/specific/ytcc/filter_comments.sh; - dependencies = with pkgs; [jq fmt less locale wl-clipboard] ++ [nest_comments-scr]; - replacementStrings = { - JQ_PREPROCCESSOR_SCRIPT = ./scripts/specific/ytcc/filter_comments.jq; - }; - }; screenshot_persistent-scr = write_shell { name = "screenshot_persistent"; path = "small_functions"; @@ -159,11 +151,6 @@ TASK_PROJECT_FILE = "/home/soispha/repos/nix/nixos-config/hm/soispha/conf/taskwarrior/projects/default.nix"; }; }; - nest_comments-scr = write_python { - name = "nest_comments.py"; - path = "specific/ytcc"; - dependencies_python = ps: []; - }; update-sys-scr = write_shell { name = "update-sys"; path = "small_functions"; @@ -267,7 +254,6 @@ in [ aumo-scr con2pdf-scr description-scr - filter-comments-scr fupdate-scr hibernate-scr ll-scr @@ -276,7 +262,6 @@ in [ mpc-rm-scr nato-scr neorg-scr - nest_comments-scr screenshot_persistent-scr screenshot_temporary-scr show-scr diff --git a/hm/soispha/pkgs/scripts/specific/ytcc/filter_comments.jq b/hm/soispha/pkgs/scripts/specific/ytcc/filter_comments.jq deleted file mode 100644 index 78bde7b8..00000000 --- a/hm/soispha/pkgs/scripts/specific/ytcc/filter_comments.jq +++ /dev/null @@ -1,20 +0,0 @@ -def relative_time: - "\(((now - ("\(.timestamp)T00:00:00Z" | fromdate)) / (60 * 60 * 24)) * 10 | round / 10)d"; - -def spaces($ident): - "\([range($ident)] | map(" ") | join(""))"; - -def c($colour): - "\u001B[\($colour)m"; - -def if_states($char): - "\(if .edited or .is_favorited then $char else "" end)"; - -def status: - "\(if_states("["))\(if .edited then "" else "" end)\(if .is_favorited and .edited then " " else "" end)\(if .is_favorited then "" else "" end)\(if_states("]"))"; - -def fmt_cmt($ident): - "\(spaces($ident))\(if .author_is_uploader then c("91;1") else c("35") - end)\(.author)\(c("0"))\(status) \(c("36;1"))(\(. | relative_time))\(c("0")):\n\(spaces($ident))\(.text | gsub("\n"; "\n\(spaces($ident))"))\n\(spaces($ident))\(if .replies? then (.replies | map(fmt_cmt($ident + 4)) | join("\n\(spaces($ident))")) else "" end)"; - -. | map(fmt_cmt(0)) | join("\n") diff --git a/hm/soispha/pkgs/scripts/specific/ytcc/filter_comments.sh b/hm/soispha/pkgs/scripts/specific/ytcc/filter_comments.sh deleted file mode 100755 index 967236b8..00000000 --- a/hm/soispha/pkgs/scripts/specific/ytcc/filter_comments.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -# This is the symlink to the active info.json -file="$XDG_RUNTIME_DIR/ytcc/running"; - -[ -e "$file" ] || die "No currently running instance found!" - -nest_comments.py "$file" | jq --raw-output -f %JQ_PREPROCCESSOR_SCRIPT | fmt -u -s --width=90 | less -r - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/specific/ytcc/nest_comments.py b/hm/soispha/pkgs/scripts/specific/ytcc/nest_comments.py deleted file mode 100755 index af6bb36a..00000000 --- a/hm/soispha/pkgs/scripts/specific/ytcc/nest_comments.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python3 - -""" -SPDX-License-Identifier: MIT https://opensource.org/licenses/MIT -Copyright © 2021 pukkandan.ytdlp@gmail.com -Copyright © 2024 soispha@vhack.eu - - -* Input file is an info.json (with comments) that yt-dlp (https://github.com/yt-dlp/yt-dlp) wrote -* Change FIELDS according to your needs - -The output file will be in the format: -[{ - 'text': 'comment 1', - ... - 'replies': [{ - 'text': 'reply 1', - ... - 'replies': [...], - }, ...], -}, ...] -""" - -import json -import sys -import argparse -from datetime import datetime - -def eprint(*args, **kwargs): - print(*args, file=sys.stderr, **kwargs) - -def get_fields(dct): - for name, fn in FIELDS.items(): - val = fn(dct, name) - if val is not None: - yield name, val - - -def filter_func(comments): - return [dict(get_fields(c)) for c in comments] - - -FIELDS = { - "text": dict.get, - "author": dict.get, - "timestamp": lambda dct, name: dct.get(name) - and datetime.strftime(datetime.utcfromtimestamp(dct.get(name)), "%Y-%m-%d"), - "edited": lambda dct, name: "(edited)" in dct.get("_time_text"), - "author_is_uploader": dict.get, - "is_favorited": dict.get, - # Add more fields here - "replies": lambda dct, name: filter_func(dct.get(name, [])) or None, -} - - -parser = argparse.ArgumentParser() -parser.add_argument( - "inputfile", - metavar="FILE", - help="File to read video metadata from (info.json)", -) -args = parser.parse_args() - - -eprint("Reading file") -with open(args.inputfile, encoding="utf-8") as f: - info_dict = json.load(f) - -comment_data = { - c["id"]: c - for c in sorted(info_dict["comments"], key=lambda c: c.get("timestamp") or 0) -} -count = len(info_dict["comments"]) -del info_dict -nested_comments = [] -for i, (cid, c) in enumerate(comment_data.items(), 1): - eprint(f"Processing comment {i}/{count}", end="\r") - parent = ( - nested_comments - if c["parent"] == "root" - else comment_data[c["parent"]].setdefault("replies", []) - ) - parent.append(c) -del parent - - -eprint("") -nested_comments = filter_func(nested_comments) - - -eprint("Converting to json") -out = json.dumps(nested_comments, indent=4, ensure_ascii=False) - - -del nested_comments -eprint("Writing file") -print(out) -eprint("Done") |