1
0

backlog of changes from the uconsole

This commit is contained in:
dtb
2025-03-07 05:36:27 -07:00
parent 55bb27a1de
commit 9846c7ad27
50 changed files with 1207 additions and 726 deletions

8
Wip/rss/Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "rss"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@@ -1,37 +0,0 @@
# pig\_birth
Initializes the pig.
# pig\_feed
Refreshes all the feed in the pigpen.
# pig\_fetch
Fetches the feed for the pigpen.
Not intended to be called on its own.
# pig\_latin
Prints internal pig details for a given feed file.
# pig\_name
Prints the file name for a given pig feed.
# pig\_pen
Prints the location of the pigpen, which houses all stowed pig feed.
A given feed will be stored as `"$(pig_pen)/$(pig_name)`.
# pig\_recall
Prints the contents of a given feed URL.
If the URL isn't already stowed, stows it before printing.
# pig\_stow
Stows fetched feed in the pigpen.

View File

@@ -1,19 +0,0 @@
#!/bin/sh
set -e
argv0="$0"
depend(){
if ! command -v "$1" >/dev/null 2>&1; then
printf "%s: %s: Could not find dependency.\n" "$argv0" "$1" \
1>&2
exit 69 # sysexits(3) EX_UNAVAILABLE
fi
return 0
}
depend curl
depend jq
depend xq
mkdir "$(pig_pen)"

View File

@@ -1,7 +0,0 @@
#!/bin/sh
for file in "$(pig_pen)"/*; do
pig_latin "$file" \
| jq '.feed_url' \
| xargs pig_stow &
done

View File

@@ -1,3 +0,0 @@
#!/bin/sh
curl -so - -- "$1"

View File

@@ -1,10 +0,0 @@
#!/bin/sh
while str isvalue "$1"; do
case "$1" in
*xml)
xq '.feed.pig' <"$1" ;;
*json)
jq '.feed.pig' <"$1" ;;
esac
done

View File

@@ -1,4 +0,0 @@
#!/bin/sh
printf "%s\n" "$1" \
| tr -cd '[:alnum:]'

View File

@@ -1,15 +0,0 @@
#!/bin/sh
set -e
str isvalue "$1" \
&& printf "Usage: %s\n" "$0" 1>&2 \
&& exit 64 \
|| str isvalue "$PIGPEN" \
&& printf "%s\n" "$PIGPEN" \
&& exit 0 \
|| str isvalue "$XDG_CONFIG_HOME" \
&& printf "%s\n" "$XDG_CONFIG_HOME" \
&& exit 0 \
|| printf "%s/.pigpen\n" "$HOME" \
&& exit 0 \
|| exit 1

View File

@@ -1,7 +0,0 @@
#!/bin/sh
set -e
filename="$(pig_pen)/$(pig_name "$1")"
test -e "$filename" || pig_stow "$1"
cat "$filename"

View File

@@ -1,18 +0,0 @@
#!/bin/sh
set -e
while str isvalue "$1"; do
pig_fetch "$1" | xq -x "$(
printf '.
* { feed: { pig: {
feed_url: "%b",
pet_sound: "oink",
stow_date: "%b",
version: "0"
} } }' "$1" "$(date '+%Y-%m-%dT%T')"\
| tr -d '[:space:]' \
)" >"$(pig_pen)/$(pig_name "$1")"
shift
done

9
Wip/rss/src/main.rs Normal file
View File

@@ -0,0 +1,9 @@
use json;
fn feed() {
}
fn stow(title: String) {
}
fn main() {
}

View File

@@ -1,182 +0,0 @@
#!/bin/sh
set -e
argv0="$0"
PIGPEN="$(pig_pen)"
latin(){
case "$1" in
*json) jq '.feed.pig' <"$1" ;;
*xml) xq '.feed.pig' <"$1" ;;
esac
}
list_channels(){
pscat \
[ sh -c "for file in \"$PIGPEN\"/*.xml; \
do xq '{(.feed.link[0].\"@href\"): .feed.title}' \"\$file\"; \
done 2>/dev/null" ] \
[ sh -c "for file in \"$PIGPEN\"/*.json; \
do jq '{(.feed.link[0].\"@href\"): .feed.title}' \"\$file\"; \
done 2>/dev/null" ] \
[ printf "\n" ] \
| sed \
-e '/{/d' \
-e '/}/d' \
-e 's/^ \"//g' \
-e 's/\": \"/ /g' \
-e 's/\,$//g' \
-e 's/\"$//g'
}
list_videos(){
file="$(printf "$PIGPEN"/$( \
list_channels \
| sed "/$1/q" \
| tail -n 1 \
| cut -f 1 \
| xargs pig_name \
)*)"
case "$file" in
*json)
jq \
'reduce .feed.entry[] as $item (
{};
. + { ($item.link."@href"): $item.title }
)' "$file"
;;
*xml)
xq \
'reduce .feed.entry[] as $item (
{};
. + { ($item.link."@href"): $item.title }
)' "$file"
;;
*)
printf "No file found!\n" 1>&2
true
;;
esac | sed \
-e '1d' \
-e '$d' \
-e 's/\": \"/ /g' \
-e 's/^ \"//g' \
-e 's/\,$//g' \
-e 's/\"$//g' # this is really hacky
}
stow(){
name="$PIGPEN/$(pig_name "$1")"
pig_fetch "$1" | xq "$(
date '+%Y-%m-%dT%T' \
| xargs printf '
. * { feed: { pig: {
feed_url: "%b",
pet_sound: "choo",
stow_date: "%b",
version: "0"
} } }' "$1" \
)" >"$name.json"
rm -f "$name.xml"
}
watch(){
youtube-dl -F "$1"
printf "Pick a format [22]: "
input="$(head -n 1 | tr -d '\n')"
str isalnum "$input" \
&& str isdigit $input \
|| input=22 \
&& youtube-dl -f $input "$1" -o - \
| mpv -
}
usage(){
printf "\
Usage: %s
list_channels
list_videos [channel name]
listen [video URL]
refresh (channel name...)
subscribe [channel URL...]
watch [video URL]
watch_latest [channel name]
" "$argv0" 1>&2
}
case "$1" in
list_channels)
! str isvalue "$2" \
|| usage
list_channels
;;
list_videos) # do something with youtube-dl?
list_videos "$2"
;;
listen)
str isvalue "$2" \
|| usage
while str isvalue "$2"
do youtube-dl "$2" -f bestaudio -o - \
| mpv -
shift
done
;;
refresh)
if ! str isvalue "$2"
then for file in "$PIGPEN"/*
do stow "$( \
latin "$file" \
| jq -r '.feed_url' \
)"
done
else
while str isvalue "$2"
do stow "$( \
latin "$( \
list_channels \
| grep "$2" \
| cut -f 2 \
)" | jq '.feed_url' \
)"
shift
done
fi
;;
subscribe)
str isvalue "$2" \
|| usage
while str isvalue "$2"
do stow "http://www.youtube.com/feeds/videos.xml?channel_id=$(
youtube-dl \
--get-filename \
--playlist-items 1 \
-o '%(channel_id)s' \
"$2" \
)"
shift
done
;;
watch) # needs work
str isvalue "$2" \
|| usage
while str isvalue "$2"
do watch "$2"
done
;;
watch_latest)
str isvalue "$2" \
|| usage
watch "$( \
list_videos "$2" \
| head -n 1 \
| cut -f 1 \
)"
;;
*) usage ;;
esac
exit 0