dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

commit 6f70efd0511f47960360eb7855a721ff4c5cd2a4
parent d48c11fc0c9c79d5adaad6c12fe5e19863824f39
Author: regexghost <dev@regexghost.com>
Date:   Thu, 28 May 2026 20:27:00 +0100

added/updated newsraft scripts

Diffstat:
Adotfiles/.config/newsraft/article.sh | 5+++++
Adotfiles/.config/newsraft/bbc-news.sh | 35+++++++++++++++++++++++++++++++++++
Mdotfiles/.config/newsraft/config | 7++++---
Mdotfiles/.config/newsraft/queue-vid.sh | 9+++++++--
Adotfiles/.config/newsraft/reddit-gallery.sh | 33+++++++++++++++++++++++++++++++++
Mdotfiles/.config/newsraft/show-image.sh | 4+++-
6 files changed, 87 insertions(+), 6 deletions(-)

diff --git a/dotfiles/.config/newsraft/article.sh b/dotfiles/.config/newsraft/article.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if echo "$1" | grep -q "bbc"; then + ~/.config/newsraft/bbc-news.sh "$1" +fi diff --git a/dotfiles/.config/newsraft/bbc-news.sh b/dotfiles/.config/newsraft/bbc-news.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +TEMP_FILE="/tmp/bbc_article.html" +OUTPUT_FILE="/tmp/bbc_article.md" + +curl -s "$1" > "$TEMP_FILE" + +title="$(cat "$TEMP_FILE" | pup 'meta[property="og:title"] attr{content}')" +description="$(cat "$TEMP_FILE" | pup 'meta[property="og:description"] attr{content}' | xmlstarlet unesc)" +picture="$(cat "$TEMP_FILE" | pup 'img attr{src}' | head -n 1 | xmlstarlet unesc)" +picture_desc_json="$(cat "$TEMP_FILE" | pup 'figcaption json{}' | jq -r .[0])" +picture_desc="$(echo "$picture_desc_json" | jq -r .children[1].children[0].text | xmlstarlet unesc)" +if [ "$picture_desc" = "null" ]; then + picture_desc="$(echo "$picture_desc_json" | jq -r .text | xmlstarlet unesc)" +fi + +echo "# $title" > "$OUTPUT_FILE" +echo "" >> "$OUTPUT_FILE" +echo "> $description" >> "$OUTPUT_FILE" +echo "" >> "$OUTPUT_FILE" +echo "![${picture_desc}](${picture})" >> "$OUTPUT_FILE" +echo "" >> "$OUTPUT_FILE" +echo "## Article" >> "$OUTPUT_FILE" +echo "" >> "$OUTPUT_FILE" + +cat "$TEMP_FILE" | pup -i 0 'p[class*="Paragraph"],p[class*="HooNV"]' | tr -d "\n" | \ +sed 's/<b[^>]*>[^<]*<\/b>//g' |\ +sed 's/<!-- -->external//g' |\ +sed 's/<span[^>]*>[^<]*<\/span>//g' |\ +sed 's/<a[^>]*>/ /g' | \ +sed 's/<\/a>//g' |\ +sed 's/<p class="[^"]*">/PPSTART/g; s/<\/p>/PPEND/g; s/PPEND/\n/g; s/PPSTART/\n/g' |\ +xmlstarlet unesc | grep -v "$picture_desc" >> "$OUTPUT_FILE" + +${PAGER:-less} "$OUTPUT_FILE" diff --git a/dotfiles/.config/newsraft/config b/dotfiles/.config/newsraft/config @@ -1,3 +1,4 @@ -bind g exec-silent '~/.config/newsraft/show-image.sh "%l"' -bind f exec-silent '~/.config/newsraft/queue-vid.sh "%l"' -bind t exec 'w3m "%l"' +bind g exec-quiet '~/.config/newsraft/show-image.sh "%l"' +bind f exec-quiet '~/.config/newsraft/queue-vid.sh "%l"' +bind t exec '~/.config/newsraft/article.sh "%l"' +global-section-hide true diff --git a/dotfiles/.config/newsraft/queue-vid.sh b/dotfiles/.config/newsraft/queue-vid.sh @@ -7,8 +7,13 @@ LOC="${HOME}/Videos/YouTube/toDownload" if echo "$1" | grep -q "youtube.com/watch"; then id="$(echo "$1" | sed -nE 's/.*=(.*)/\1/p')" - yt-data "$1" > "${LOC}/Videos/${id}.txt" + yt-data "$1" > "${LOC}/Videos/${id}.txt" & disown elif echo "$1" | grep -q "youtube.com/shorts"; then id="$(echo "$1" | sed -nE 's/.*\/(.*)/\1/p')" - yt-data "$1" > "${LOC}/Shorts/${id}.txt" + yt-data "$1" > "${LOC}/Shorts/${id}.txt" & disown +else + notify-send "Not a video" + exit fi + +notify-send "Video Queued" diff --git a/dotfiles/.config/newsraft/reddit-gallery.sh b/dotfiles/.config/newsraft/reddit-gallery.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# Reddit gallery link to actual, full size image links + +USER_AGENT="NetSurf/3.10 (Linux)" +OUTPUT_FOLDER="/tmp/reddit_images" + +[ -d "$OUTPUT_FOLDER" ] && rm -rf "/tmp/reddit_images" +mkdir -p "$OUTPUT_FOLDER" + +notify-send "Extracting" + +url="$1" +id="$(echo "$url" | cut -d "/" -f 5)" + +curl -s -L --user-agent "$USER_AGENT" "https://old.reddit.com/${id}" > /tmp/reddit_gallery.html + +links="$(cat /tmp/reddit_gallery.html | grep -oP ".{0,20}preview.redd.it.{0,200}" | sed -nE 's/.*href=&quot;(https.*)&quot; .*/\1/p' | xmlstarlet unesc | cut -d "\"" -f 1 | xmlstarlet unesc)" + +if [ "$links" = "" ]; then + links="$(cat /tmp/reddit_gallery.html | grep -oP ".{0,20}preview.redd.it.{0,200}" | sed -nE 's/.*href="(https[^"]*)".*/\1/p' | xmlstarlet unesc)" +fi + +notify-send "Downloading" + +for link in $links; do + wget -P "$OUTPUT_FOLDER" "$link" & +done +wait + +notify-send "Displaying" +notify-send "$IMAGE_VIEWER" +$IMAGE_VIEWER "$OUTPUT_FOLDER"/* diff --git a/dotfiles/.config/newsraft/show-image.sh b/dotfiles/.config/newsraft/show-image.sh @@ -8,6 +8,8 @@ if echo "$1" | grep -q "youtube"; then elif echo "$1" | grep -q "redd.it"; then filename="$(echo "$1" | sed 's/.*\///g')" wget -P /tmp "$1" - feh "/tmp/${filename}" + $IMAGE_VIEWER "/tmp/${filename}" rm -rf "/tmp/${filename}" +elif echo "$1" | grep -q "reddit.com/gallery"; then + ~/.config/newsraft/reddit-gallery.sh "$1" fi