Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change "Adavanced search" and add "info radio" #9

Merged
merged 3 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions lib/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,44 @@ _show_favlist() {
echo "$LIST"
}

_info_select_radio() {
NAMEINFO=$(cat $SEARCH_RESULTS 2>/dev/null | jq -r ".[$ANS-1]" | grep "name\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
TAGSINFO=$(cat $SEARCH_RESULTS 2>/dev/null | jq -r ".[$ANS-1]" | grep "tags\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
COUNTRYINFO=$(cat $SEARCH_RESULTS 2>/dev/null | jq -r ".[$ANS-1]" | grep "country\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
VOTESINFO=$(cat $SEARCH_RESULTS 2>/dev/null | jq -r ".[$ANS-1]" | grep "votes\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
CODECINFO=$(cat $SEARCH_RESULTS 2>/dev/null | jq -r ".[$ANS-1]" | grep "codec\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
BITRATEINFO=$(cat $SEARCH_RESULTS 2>/dev/null | jq -r ".[$ANS-1]" | grep "bitrate\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
echo
echo "--------- Info Radio: ------------"
echo "NAME: $NAMEINFO"
echo "TAGS: $TAGSINFO"
echo "COUNTRY: $COUNTRYINFO"
echo "VOTES: $VOTESINFO"
echo "CODEC: $CODECINFO"
echo "BITRATE: $BITRATEINFO"
echo "---------------------------------- "
echo
}

_info_select_radio_play() {
NAMEINFO=$(cat $LIST_PATH 2>/dev/null | jq -r ".[$ANS-1]" | grep "name\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
TAGSINFO=$(cat $LIST_PATH 2>/dev/null | jq -r ".[$ANS-1]" | grep "tags\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
COUNTRYINFO=$(cat $LIST_PATH 2>/dev/null | jq -r ".[$ANS-1]" | grep "country\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
VOTESINFO=$(cat $LIST_PATH 2>/dev/null | jq -r ".[$ANS-1]" | grep "votes\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
CODECINFO=$(cat $LIST_PATH 2>/dev/null | jq -r ".[$ANS-1]" | grep "codec\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
BITRATEINFO=$(cat $LIST_PATH 2>/dev/null | jq -r ".[$ANS-1]" | grep "bitrate\":" | awk -F': ' '{print $2}' | sed 's/"//g' | sed 's/+/ /g' | sed 's/,//g')
echo
echo "--------- Info Radio: ------------"
echo "NAME: $NAMEINFO"
echo "TAGS: $TAGSINFO"
echo "COUNTRY: $COUNTRYINFO"
echo "VOTES: $VOTESINFO"
echo "CODEC: $CODECINFO"
echo "BITRATE: $BITRATEINFO"
echo "---------------------------------- "
echo
}

_wget_simple_search() {
REPLY="$1"
KEY="$2"
Expand All @@ -132,17 +170,11 @@ _wget_simple_search() {
}

_wget_search() {
REPLY=("$1")
read -rp 'Write your query ' -a REPLY
echo "${REPLY[@]}"
SEARCH_RESULTS="${TMP_PATH}/radio_searches.json"
OPTS=
for TAG in "${REPLY[@]}"; do
OPTS+="$KEY=$TAG&"
done
OPTS="${OPTS%?}"
greenprint "Searching ..."
echo "$OPTS"
wget --post-data "$OPTS" "$SEARCH_URL" -O "$SEARCH_RESULTS" 2>/tmp/tera_error || {
curl -X POST "${REPLY[@]}" "$SEARCH_URL" > "$SEARCH_RESULTS" 2>/tmp/tera_error || {
redprint "Something went wrong. Please see /tmp/tera_error"
exit
}
Expand Down
1 change: 1 addition & 0 deletions lib/play.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fn_play() {
URL_RESOLVED=$(jq -r ".[$ANS-1] |.url_resolved" <"${LIST_PATH}")
# echo "url_resolved: $URL_RESOLVED"
if [[ -n $URL_RESOLVED ]]; then
_info_select_radio_play "$ANS" "${LIST_PATH}"
_play "$URL_RESOLVED" || menu
else
echo "url_resolved can't be found. Exiting ..."
Expand Down
13 changes: 7 additions & 6 deletions lib/search.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ _search_play() {
jq -r ".[$ANS-1]" <"$SEARCH_RESULTS" >"$TEMP_FILE"
URL_RESOLVED=$(jq -r ".[$ANS-1] |.url_resolved" <"$SEARCH_RESULTS")
if [ -n "$URL_RESOLVED" ]; then
_info_select_radio "$ANS"
mpv "$URL_RESOLVED" || {
echo "Not able to play your station."
search_menu
Expand Down Expand Up @@ -87,6 +88,7 @@ search_by() {
search_menu
fi
# URL_RESOLVED=$(jq -r ".[$ANS-1] |.url_resolved" <"$SEARCH_RESULTS")
_info_select_radio "$ANS"
search_submenu "$ANS"
# rm "$SEARCH_RESULTS"
}
Expand All @@ -97,11 +99,9 @@ advanced_search() {
magentaprint "The query format is -d field=word."
magentaprint "Field can be one of tag, name, language, country code and state."
magentaprint "Fields can be combined, for example: -d tag=jazz -d state=queensland"
magentaprint "Or tag=rock language=spanish countrycode=us"
magentaprint "Or tag=country state=IL"
printf "Write your quiry: "
read -ra REPLY
_wget_search "${REPLY[@]}"
magentaprint "Or -d tag=rock -d language=spanish -d countrycode=us"
magentaprint "Or -d tag=jazz -d codec=ogg -d bitrateMin=128000"
_wget_search

LENGTH=$(jq length "$SEARCH_RESULTS")

Expand All @@ -118,6 +118,7 @@ advanced_search() {
if [[ "$ANS" == 0 ]]; then
search_menu
fi
_info_select_radio "$ANS"
search_submenu "$ANS"
}

Expand Down Expand Up @@ -165,7 +166,7 @@ search_menu() {
$APP_NAME SEARCH MENU:
$(greenprint '1)') Tag
$(greenprint '2)') Name
$(greenprint '3)') Language
$(greenprint '3)') Language
$(greenprint '4)') Country code
$(greenprint '5)') State
$(greenprint '6)') Advanced search
Expand Down