aboutsummaryrefslogtreecommitdiff
path: root/src/search_command.sh
blob: 8817c97323be09602e270dbf2bbd81b87ba3ea73 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Search page HTML
search_page="$(gum spin --spinner line --show-output -- \
	curl --silent --get --data-urlencode "k=${args[title]}" \
	"https://www.honeyfeed.fm/search/novel_title")"

# Novel data
IFS=$'\n' read -r -d '\n' -a novel_locations <<<"$(echo "${search_page}" |
	pup 'div.novel-unit-type-h a.a-img-hover attr{href}')" || true
IFS=$'\n' read -r -d '\n' -a novel_names <<<"$(echo "${search_page}" |
	pup 'h3.novel-name text{}')" || true
# IFS=$'\n' read -r -d '\n' -a novel_update_dates <<<"$(echo "${search_page}" |
# 	pup 'div.information-unit-novel span:not([class]) text{}')" || true
# IFS=$'\n' read -r -d '\n' -a novel_chapter_counts <<<"$(echo "${search_page}" |
# 	pup 'div.information-unit-novel div.flex div:not([class]) text{}')" || true
# IFS=$'\n' read -r -d '\n' -a novel_statuses <<<"$(echo "${search_page}" |
# 	pup 'div.information-unit-novel div.flex div.wrap-publish-status text{}')" ||
# 	true

# Novel collection for Gum
novels=""

# Fix output format for Gum
for ((i = 0; i < "${#novel_locations[@]}"; i++)); do
	novels+="$(printf "\n%s" "${novel_names[${i}]}")"
done

# Remove leading new-line
novels="$(echo "${novels}" | sed '/./,$!d')"

# Prompt for user's novel choice
novel_choice="$(echo "${novels}" | gum filter)"

# Locate novel choice location
for ((i = 0; i < "${#novel_locations[@]}"; i++)); do
	if [[ "${novel_names[${i}]}" = "${novel_choice}" ]]; then
		novel_location="https://www.honeyfeed.fm${novel_locations[${i}]}"
	fi
done

# Obtain user's chapter choice
chapter_location="$(chapter_selection "${novel_location}")"

# Display chapter
chapter_reader "${chapter_location}"