You are not logged in.
Like many people these days, I've got a lot of music stored away, and maybe like some people, starting to forget what there is, and where.
So I wrote this little script:
Enter a search term in the yad window and click something from the menu that comes up - it will play in whatever app you've got set as bl-media-player.
(Just today it ocurred to me that Catfish file search will do pretty much the same thing, but this is a bit faster and goes away once the player opens.)
Give the file a name, make it executable and put it in a launcher or menu.
Edit the settings at the top to suit your needs.
By default it looks for your search term somewhere in the file or directory name.
There is an alternative line you can uncomment to do regex searches.
#!/bin/bash
# searches filenames and directory names
# uses jgmenu menu
# Set the directories you want to search:
search_folders=("$HOME/Music" "$HOME/Downloads/youtube")
# what app to play music with
open_file=bl-media-player
# what app to open directories with
open_dir=bl-media-player # might need testing with other players than vlc or bl-mpv
# how many menu items
max_results=30 # probably best to set some limit
# set to 1 to use ffprobe (comes with ffmpeg)
# this will find a few more files
use_ffprobe=0
########################################################################
BL_COMMON_LIBDIR='/usr/lib/bunsen/common'
if ! . "$BL_COMMON_LIBDIR/bl-include.cfg" 2> /dev/null; then
echo $"Error: Failed to locate bl-include.cfg in $BL_COMMON_LIBDIR" >&2
exit 1
fi
if [[ "$use_ffprobe" = 0 ]]
then
# "application/octet-stream" files will be missed
isPlayable() {
case $(file --brief --mime-type "$1")
in
audio/*|video/*)
return 0
;;
*)
return 1
;;
esac
}
else
# this test is slower but catches more files (needs ffmpeg)
isPlayable() {
[[ $( ffprobe -loglevel error -select_streams a -show_entries stream=codec_type -of csv=p=0 "$1" ) = audio ]] && return 0
return 1
}
fi
search="$(yad --center --entry --title "Music Search" --text "Please enter your search terms:")" || exit 0
[[ -n $search ]] || exit 0
# does a text search by default:
mapfile -t -d '' results < <( find -L "${search_folders[@]}" -iname "*${search}*" -print0 )
# this version allows regular expressions for filename:
#mapfile -t -d '' results < <( find -L "${search_folders[@]}" -iregex ".*/[^/]*${search}[^/]*$" -print0 )
if [[ ${#results[@]} = 0 ]]
then
jgmenuItem root "No results"
else
n=0
for item in "${results[@]}"
do
name=${item##*/}
if [[ -d $item ]]
then
jgmenuItem root "${name} >>" "${open_dir} ${item@Q}"
else
isPlayable "$item" || continue
jgmenuItem root "${name}" "${open_file} ${item@Q}"
fi
(( ++n >= max_results )) && break
done
fi
# redirect stdout from this point
exec > >( jgmenu --simple --config-file=<( sed '/menu_padding_top/ { s/^/#/ }; $ a tabs = 0 \nposition_mode = center' ~/.config/jgmenu/jgmenurc ) )
jgmenuEnd
exit
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline