Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # get the song being played by lsof utility "list open files"
- # look for similar file names of lyrics txt file names in a local directory
- # print the lyrics of the best matching lyrics file name
- # another version would would be to fetch the lyrics from some website like azlyrics
- # curl or wget with some string manipulation would be easy to use
- #
- cd "/media/$USER/My_Data/Audio/My music/Lyrics/"
- files=$(ls -p -1R | grep -v /)
- str0=$(lsof -w -c mpv -c clementine -c smplayer -c vlc |grep -iE ".wma$|.mp3$|.mp4$|.mkv$|.flv$|.webm$"| awk -F"/" '{print $NF}')
- #str=${str%-*}
- if (( ${#str0} < 1 ))
- then
- echo "not playing anything !"
- exit
- fi
- str=$(echo "$str0" | sed 's/[^a-zA-Z0-9]/ /g')
- printf "\033[01;36mplaying : \033[01;00m$str0\n"
- aaa=$(echo "$1"|awk 'END{print index($0,"p")}')
- if (($aaa > 0))
- then
- exit
- fi
- IFS=', ' read -r -a array <<< $str
- patterns=$(
- for element in ${array[@]}
- do
- if (( ${#element} > 2 ))
- then
- echo -n "$element|"
- fi
- done
- )
- patterns=${patterns::-1}
- f=$(echo "$files" | awk '{ print NF,$0 }' IGNORECASE=1 FS="$patterns" | sort -nr )
- f=$(echo "$f" |head -10 )
- nbrOFmatches=$( echo "$f" | awk ' NR==1 { print $1 }')
- bmatch=$(echo "$f"|awk 'NR==1 {for(i=2;i<=NF;i++) printf $i" "}')
- printf "\033[01;36mbest match : \033[01;00m$bmatch\n"
- #echo "number of occurences : $nbrOFmatches"
- nn=$(echo "$f"|awk 'NR==1 {a=$1} NR==2 {b=$1} END {if( a ~ b )print "1"}')
- if [[ "$nn" == 1 ]]
- then
- echo "========================================="
- echo "$f"|cat -n
- read -p " : " answer
- if [[ -z "$answer" ]] ;
- then
- exit
- fi
- else
- answer=1
- fi
- ff=$(echo -e "$f"|sed -n "$answer"p |awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}')
- fff=$(find -name "$ff" )
- rr=$(echo "$ff" ; cat "$fff")
- #printf "\033[01;36m"
- aaa=$(echo "$1"|awk 'END{print index($0,"s")}')
- if (($aaa > 0))
- then
- exit
- fi
- echo "$rr"|less
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement