summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon GECOS <u@adam>2024-07-29 16:59:35 -0400
committerGordon GECOS <u@adam>2024-07-29 16:59:35 -0400
commit35b233aa6473b83e1385f247a79bb71b5ff08ef0 (patch)
tree39c53c0789f96b1a3eadc2311020a640c5c2d8ac
parentbad38013c1c52ec3238c4dfcf87d2ff1ddfc2eb1 (diff)
search
-rwxr-xr-xsearch100
-rwxr-xr-xupdate-repo (renamed from update-fdroids.bash)0
2 files changed, 100 insertions, 0 deletions
diff --git a/search b/search
new file mode 100755
index 0000000..191882e
--- /dev/null
+++ b/search
@@ -0,0 +1,100 @@
1#!/bin/bash
2set -e
3set -o pipefail
4shopt -s lastpipe
5
6encode_query()
7{
8 perl -e '
9$_ = join " ", map { m/ / ? qq<"$_"> : $_ } @ARGV;
10s/([^a-zA-Z0-9])/sprintf "%%%x", ord $1/ge;
11print "$_\n"
12' "$@"
13}
14
15search_url()
16{
17 if [ "$1" -gt 1 ]
18 then
19 p=$1
20 else
21 p=
22 fi
23 q=$(encode_query "${@:2}")
24 echo https://search.f-droid.org/'?q='"$q"${p:+'&page='$p}'&lang='${lang:-en}
25}
26
27search()
28{
29 page=${page:-1}
30 url=$(search_url "$page" "$@")
31 out=$(mktemp)
32 curl -s "$url" |
33 hxclean |
34 hxselect '.package-header, div.package-info' |
35 hxnormalize -l 2147483647 > "$out"
36 trap 'rm -f "$out"' EXIT
37 hxclean < "$out" |
38 hxselect -s '\n' 'a.package-header::attr(href)' |
39 mapfile -t href
40 hxclean < "$out" |
41 hxselect -s '\n' h4.package-name |
42 mapfile -t name
43 hxclean < "$out" |
44 hxselect -s '\n' span.package-summary |
45 mapfile -t summary
46 [ ${#href[@]} = ${#name[@]} ]
47 [ ${#href[@]} = ${#summary[@]} ]
48 OPTIONS=()
49 for ((i=0; i<${#href[@]}; ++i))
50 do
51 n=${name[$i]}
52 s=${summary[$i]}
53 h=${href[$i]}
54 h=${h#href=\"}
55 h=${h%\"}
56 href[$i]=$h
57
58 n=$(w3m -T text/html <<<"$n")
59 s=$(w3m -T text/html <<<"$s")
60 OPTIONS+=("$(printf "%40s: %s" "$n" "$s")")
61 done
62 PS3='Choose <number> to install, [n]ext, [p]revious, or m<number> for [m]ore> '
63 select i in "${OPTIONS[@]}"
64 do
65 if [ "$i" ]
66 then
67 i=$((REPLY - 1))
68 (
69 set -x
70 mkdir repo/"${href[$i]##*/}"
71 )
72 continue
73 fi
74 case "${REPLY@L}" in
75 n )
76 let ++page
77 search "$@"
78 return
79 ;;
80 p )
81 let --page
82 search "$@"
83 return
84 ;;
85 m*[^0-9\ ] )
86 continue
87 ;;
88 m*[0-9]* )
89 i=${REPLY#?}
90 i=$((i - 1))
91 if [ $i -gt 0 -a $i -lt ${#OPTIONS[@]} ]
92 then
93 w3m "${href[$i]}"
94 fi
95 ;;
96 esac
97 done
98}
99
100search "${@:-music}"
diff --git a/update-fdroids.bash b/update-repo
index aa2804b..aa2804b 100755
--- a/update-fdroids.bash
+++ b/update-repo