Created
December 27, 2019 05:29
-
-
Save canabady/71b90876aa1990fe6aaadd9fb6d3ed59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# DIR SETTINGS | |
_KURAL_DIR='/home/USERNAME/Music/Thirukkural/Kural-Song-Audio' | |
_PAADAL_DIR='/home/USERNAME/Music/01-Thevaram/00-thevaram-classified-by-artist' | |
# Scroll mail message based on isThevaram or isKural is true ( for auto scroll with xdotool ) | |
typeset -g isThevaram=false | |
typeset -g isKural=false | |
if [ -z "$1" ]; then | |
message=$(cat) | |
echo "$message" > /tmp/neomutt-message.html | |
mailMessage=/tmp/neomutt-message.html | |
else | |
mailMessage=$1 | |
fi | |
######################################################################### | |
# Code for playing thevaram song, if the mail contains thevara-padal info | |
######################################################################### | |
playThevaram() | |
{ | |
# Associative array of key:artist_prefix and value:artist_name(dir) | |
declare -A _ARTIST_ARRAY=( ['art']=artist-01 ['dps']=dharmapuram-p-swaminathan ['dvr']=dv-ramani ['irj']=ilaiyaraja ['mpm']=madurai-muthukkumaran ['msg']=mayilai-pa-sargurunathan ['ppi']=pasupathy ['sjj']=sj-janani ['spb']=sp-balasubramaniam ['tss']=thiruvidaimarudur-s-sambadam ['tms']=tm-soundararajan ['vjr']=vani-jayaram ['vmk']=veeramani-kannan ) | |
# To get artist in the order we want, instead of dict-hash | |
declare -a _ARTIST_ORDER_ARRAY=( vjr spb tms vmk irj ppi sjj dvr msg mpm tss art dps ) | |
# _PAADAL_NUMBER=$(cat $1 | grep -Po '(?<=/)\d{7}(?=\.mp3)') | |
_PAADAL_ARRAY=($(grep -Po '(?<=\>)\d{1,3}(?=\<)' "$mailMessage")) | |
# Thirumurai in text form with space trimmed | |
_THIRUMURAI_TEXT=`echo $(grep -Po '(?<=\</b\>)(.*)\s(?=திருமுறை \<)' "$mailMessage")` | |
# _THIRUMURAI_TEXT=$(echo $(grep -Po '(?<=\</b\>)(.*)\s(?=திருமுறை \<)' "$mail{Message}")) | |
# Thirumurai text to number associative array | |
declare -A _THIRUMURAI_ARRAY=( ["முதலாம்"]=1 ["இரண்டாம்"]=2 ["மூன்றாம்"]=3 ["நான்காம்"]=4 ["ஐந்தாம்"]=5 ["ஆறாம்"]=6 ["ஏழாம்"]=7 ["எட்டாம்"]=8 ["ஒன்பதாம்"]=9 ["பத்தாம்"]=10 ["பதினொன்றாம்"]=11 ["பனிரெண்டாம்"]=12 ) | |
# If Pathigam and Paadal details are available, then | |
if [ ${#_PAADAL_ARRAY[@]} -eq 2 ]; then | |
_PAADAL_NUMBER=$(printf '%d%03d%03d' "${_THIRUMURAI_ARRAY[${_THIRUMURAI_TEXT}]}" "${_PAADAL_ARRAY[0]}" "${_PAADAL_ARRAY[1]}" ) | |
else | |
_PAADAL_NUMBER=0 | |
fi | |
if [ ${#_PAADAL_NUMBER} -eq 7 ]; then | |
# echo "Song: ${_PAADAL_NUMBER}" | |
for oIndex in "${!_ARTIST_ORDER_ARRAY[@]}"; do | |
# No prefix and '-' if the artist is dharmapuram-p-swaminathan ['dps'] | |
#1001001.mp3 | |
if [ "${_ARTIST_ORDER_ARRAY[$oIndex]}" = "dps" ]; then | |
thevaraSong="${_PAADAL_DIR}/${_ARTIST_ARRAY[${_ARTIST_ORDER_ARRAY[$oIndex]}]}/0${_PAADAL_NUMBER:0:1}/${_PAADAL_NUMBER:1:3}/${_PAADAL_NUMBER}.mp3" | |
else | |
#vmk-01001001.mp3 | |
thevaraSong="${_PAADAL_DIR}/${_ARTIST_ARRAY[${_ARTIST_ORDER_ARRAY[$oIndex]}]}/0${_PAADAL_NUMBER:0:1}/${_PAADAL_NUMBER:1:3}/${_ARTIST_ORDER_ARRAY[$oIndex]}-0${_PAADAL_NUMBER}.mp3" | |
fi | |
if [ -f "$thevaraSong" ]; then | |
isThevaram=true | |
tmux splitw -v -p 20 -t basic:8 "mplayer -loop 0 ${thevaraSong}" & | |
break | |
fi | |
done | |
fi | |
} | |
############################################################################## | |
# END: Code for playing thevaram song, if the mail contains thevara-padal info | |
############################################################################## | |
######################################################################### | |
# Code for playing kural song, if the mail contains kural-padal info | |
######################################################################### | |
playKural() | |
{ | |
# _KURAL_NUMBER=$(cat $1 | grep -Po '(?<=</b>)\d{1,4}(?=<br)') | |
_KURAL_NUMBER=$(grep -Po '(?<=</b>)\d{1,4}(?=<br)' "$1") | |
_KURAL_INTEGER=$(( "$_KURAL_NUMBER" + 0)) | |
# if [ ${#_KURAL_NUMBER} -ge 1 -a ${#_KURAL_NUMBER} -le 4 ]; then | |
if [ ${#_KURAL_NUMBER} -eq 4 ]; then | |
if [ "${_KURAL_INTEGER}" -ge 1 ] && [ "${_KURAL_INTEGER}" -le 1330 ]; then | |
# zeroos="0000" | |
# zeroPadedKuralNumber=$(echo ${zeroos:${#_KURAL_NUMBER}:${#zeroos}}${_KURAL_NUMBER}) | |
# echo "Song: ${_KURAL_NUMBER}" | |
# kuralSong="${_KURAL_DIR}/${zeroPadedKuralNumber}.mp3" | |
kuralSong="${_KURAL_DIR}/${_KURAL_NUMBER}.mp3" | |
if [ -f "$kuralSong" ]; then | |
isKural=true | |
tmux splitw -v -p 20 "mplayer -loop 0 -ss 12 ${kuralSong}" & | |
fi | |
fi | |
fi | |
} | |
############################################################################## | |
# END: Code for playing kural song, if the mail contains kural-padal info | |
############################################################################## | |
# Play Thevaram if the message contains thevaram data | |
playThevaram "$mailMessage" | |
# Play Kural if the message contains kural data | |
playKural "$mailMessage" | |
# Convert html page to pdf | |
wkhtmltopdf --encoding utf-8 "$mailMessage" "$mailMessage".pdf >/dev/null 2>&1 | |
# Open the convert pdf in xpdf | |
xpdf -fullscreen "$mailMessage".pdf & | |
# Wait for the xpdf to load | |
sleep 1 | |
# wmctrl to detect if a window is present | |
if [ "$(wmctrl -l | grep -c 'Xpdf: /tmp/neomutt.html.pdf')" -gt 0 ]; then | |
wmctrl -xa "Xpdf: /tmp/neomutt.html.pdf" | |
xdotool key w | |
if [ "${isThevaram}" = true ] || [ "${isKural}" = true ]; then | |
# To scroll down 650 px for viewing thevaram/kural | |
xdotool key y | |
# # repeat 'j' for 'n' times | |
# for i in {1..40}; do | |
# xdotool key j | |
# # sleep 1 | |
# done | |
fi | |
fi | |
# Zoom pdf to fullscreen | |
# pdfWndId=$(xdotool search --name "neomutt.html.pdf") | |
# if [ "${pdfWndId}" ]; then | |
# sleep 1 | |
# pdfWndId=$(xdotool search --name "neomutt.html.pdf") | |
# echo "inside-xpdf-wndId=${pdfWndId}" | |
# xdotool windowfocus --sync "${pdfWndId}" && xdotool key w | |
# fi | |
# xdotool windowfocus $(xdotool search --name neomutt.html.pdf) && xdotool key w | |
# Clean-up any neomutt file in /tmp | |
# rm -f /tmp/neomutt* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment