Newest feature in PyRadio is the logging of currently playing radio stations and music titles/broadcasts (toggle on/off with ‘W’. Additionally you can tag a playing title as “liked” by pressing ‘w’ in PyRadio.
To extract these likes automatically and store them in a chronological list so you can review them later, I wrote this script. It creates an individual list-file in ~.config/pyradio/.
As gimmick there’s a second step where the titles are converted into a searchlink for DuckDuckGo and added to a second alphabetical list. That should make it more uncomplicated to start a websearch for a band/title you liked (just open with a pager in a terminal or a text-editor with hyperlink-support, hold CTRL pressed and click a link).
I hope you may draw some benefit from this script. I’m also always happy about feedback or suggestions for improvement regarding my bash-scripting, since I’m still a bloody noob .
Have fun and wish you all a nice evening!
#!/bin/bash
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
#::: Bash script to extract your LIKES from 'pyradio-titles.log'::::#
#:::¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯:::#
# # Faehnchen, Apr. 20, 2022 # # # # # # # # # # # # # # # # # # # #
# https://forum.maboxlinux.org/c/userland/scripts-tutorials-tips/17
LOGFILE="$HOME/.config/pyradio/pyradio-titles.log"
# default filepath for favourites list
LISTFILE="$HOME/.config/pyradio/$USER_pyradio_favs.list"
# temporary files
EXTRFILE="$HOME/.config/pyradio/usr_favs.tmp"
SORTFILE="$HOME/.config/pyradio/sorted_favs.tmp"
echo -e "\n \033[1;4;32m Extracting your LIKES from 'pyradio-titles.log' \033[0m"
sleep 0.5
echo -e "\n\033[1;34m Create or update file in\033[0m $LISTFILE\033[1;34m ? \033[0m\n"
echo -e " Yes, resume \033[1m [r] | \033[0m No, please cancel! \033[1m [ANY KEY] \n"
echo -n " > "; read resume
if [[ $resume != [r] ]]; then
exit 0
fi
# creating/updating chronological list
touch "$EXTRFILE"
touch "$SORTFILE"
grep -E '(LIKED)|Station' "$LOGFILE" | sed 's/ (LIKED)//' | sort > "$EXTRFILE"
uniq "$EXTRFILE" >> "$LISTFILE"
sort "$LISTFILE" > "$EXTRFILE"
uniq "$EXTRFILE" > "$LISTFILE"
cat /dev/null > "$EXTRFILE"
sleep 1
echo -e "\n\033[1;32m Done! \033[0m"
sleep 1
# Sort, erase duplicates and update alphabetical list
echo -e "\n\033[0m Sorting $LISTFILE.alphabetically... \033[1m\n "
awk -F'[|]' '{print $2}' "$LISTFILE" | sed 's/ //;s/ >>> Station: //' > "$EXTRFILE"
sort "$EXTRFILE" | uniq > "$SORTFILE"
sleep 1
# Adding DuckDuckGo websearch
echo -e "\n\033[1;32m Ready. Adding websearch-links. Please wait! \033[0m\n"
sed 's/ /+/g' "$SORTFILE" > "$EXTRFILE"
sleep 1
# write list with searchlinks line by line
lncount=`wc -l < "$SORTFILE"`
count=1
URLFILE="$HOME/.config/pyradio/$USER_favs-searchlinks_$lncount.list"
until (( $count > $lncount )); do
title=$(awk 'NR=='$count'{print $0}' "$SORTFILE")
url=$(awk 'NR=='$count'{print $0}' "$EXTRFILE")
printf "%-s \n »»» https://duckduckgo.com/?q=%s&t=ffab&ia=web \n\n" "$title" "$url" >> "$URLFILE"
printf "\r\033[1;34m »%d / %-d« \033[0m" $count $lncount
let count++
sleep 0.1 # "speed"
done
sleep 1
echo -e "\n\n\033[1;32m Done! Updated/created your lists in: \033[0m"
echo -e " $LISTFILE \n $URLFILE"
echo -e '\n\033[1;34m View in terminal with pager less or bat "/filepath"! \033[0m'
rm "$EXTRFILE"
rm "$SORTFILE"
exit 0