Advertisement
mosaid

Untitled

Apr 6th, 2017
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.91 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # get the song being played by lsof utility "list open files"
  4. # look for similar file names of lyrics txt file names in a local directory
  5. # print the lyrics of the best matching lyrics file name
  6. # another version would would be to fetch the lyrics from some website like azlyrics
  7. # curl or wget with some string manipulation would be easy to use
  8. #
  9. cd "/media/$USER/My_Data/Audio/My music/Lyrics/"
  10. files=$(ls -p -1R | grep -v /)
  11. str0=$(lsof -w -c mpv -c clementine -c smplayer -c vlc |grep -iE ".wma$|.mp3$|.mp4$|.mkv$|.flv$|.webm$"| awk -F"/" '{print $NF}')
  12. #str=${str%-*}
  13. if (( ${#str0} < 1 ))
  14.        then
  15.             echo "not playing anything !"
  16.             exit
  17. fi
  18. str=$(echo "$str0" | sed 's/[^a-zA-Z0-9]/ /g')
  19. printf "\033[01;36mplaying    : \033[01;00m$str0\n"
  20. aaa=$(echo "$1"|awk 'END{print index($0,"p")}')
  21. if (($aaa > 0))  
  22.     then
  23.         exit
  24. fi
  25. IFS=', ' read -r -a array <<< $str
  26. patterns=$(
  27.     for element in ${array[@]}
  28.     do
  29.      if (( ${#element} > 2 ))
  30.        then
  31.             echo -n "$element|"
  32.      fi
  33.     done
  34. )
  35. patterns=${patterns::-1}
  36. f=$(echo "$files" | awk '{ print NF,$0 }' IGNORECASE=1 FS="$patterns" | sort -nr )
  37. f=$(echo "$f" |head -10 )
  38. nbrOFmatches=$( echo "$f" | awk ' NR==1 { print $1 }')
  39. bmatch=$(echo "$f"|awk 'NR==1 {for(i=2;i<=NF;i++) printf $i" "}')
  40. printf "\033[01;36mbest match : \033[01;00m$bmatch\n"
  41. #echo "number of occurences : $nbrOFmatches"
  42. nn=$(echo "$f"|awk 'NR==1 {a=$1} NR==2 {b=$1} END {if( a ~ b )print "1"}')
  43. if [[  "$nn" == 1 ]]
  44.  then
  45.    echo "========================================="
  46.    echo "$f"|cat -n
  47.    read -p " : " answer
  48.    if [[ -z "$answer" ]] ;
  49.     then
  50.         exit
  51.    fi
  52.   else
  53.       answer=1
  54. fi  
  55. ff=$(echo -e "$f"|sed -n "$answer"p |awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}')
  56. fff=$(find -name "$ff" )
  57. rr=$(echo "$ff" ; cat "$fff")
  58. #printf "\033[01;36m"
  59. aaa=$(echo "$1"|awk 'END{print index($0,"s")}')
  60. if (($aaa > 0))
  61.     then
  62.         exit
  63. fi
  64. echo "$rr"|less
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement