Guest User

audio bookmark manager 5

a guest
Mar 31st, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 25.37 KB | None | 0 0
  1. ::::::::::::::
  2. brightness_down.bash
  3. ::::::::::::::
  4. #!/bin/bash
  5.  
  6. killall xbindkeys
  7. # keycode 163, XF86Mail
  8. xdotool key XF86MonBrightnessDown
  9. xbindkeys::::::::::::::
  10. brightness_up.bash
  11. ::::::::::::::
  12. #!/bin/bash
  13.  
  14. killall xbindkeys
  15. # keycode 180, XF86HomePage
  16. xdotool key XF86MonBrightnessUp
  17. xbindkeys::::::::::::::
  18. escape.bash
  19. ::::::::::::::
  20. #!/bin/bash
  21.  
  22.  
  23. player_title="LosslessCut"
  24.  
  25.  
  26. function block_double_run () {
  27.   pids=($(pidof -x $(basename $0)))
  28.   if [[ ${#pids[@]} -gt 1 ]] ; then
  29.     echo "double run blocked"
  30.     spd-say -t female2 "double run"
  31.     exit
  32.   fi
  33. }
  34.  
  35. function wait_for_window_to_activate() {
  36.   # first parameter  - window title or part of the window title
  37.   window_title="$1"
  38.   time_sec=900
  39.   while [[ 0 -ne $time_sec ]]; do
  40.     echo "$time_sec, waiting... to activate"
  41.     time_sec=$[$time_sec-1]
  42.     xdotool search --onlyvisible --name "$window_title" windowactivate
  43.     window_name=$(xdotool getwindowfocus getwindowname)
  44.     if echo $window_name | grep -q "$window_title" ; then
  45.       echo "window active "$window_name
  46.       break
  47.     fi
  48.     sleep 0.5
  49.   done
  50. }
  51.  
  52. block_double_run
  53. wait_for_window_to_activate "$player_title"
  54. xdotool key Escape
  55. spd-say -t female2 "escape"::::::::::::::
  56. fforward.bash
  57. ::::::::::::::
  58. #!/bin/bash
  59.  
  60.  
  61. player_title="LosslessCut"
  62.  
  63.  
  64. function block_double_run () {
  65.     pids=($(pidof -x $(basename $0)))
  66.     if [[ ${#pids[@]} -gt 1 ]] ; then
  67.         echo "double run blocked"
  68.         spd-say -t female2 "double run"
  69.         exit
  70.     fi
  71. }
  72.  
  73. function wait_for_window_to_activate() {
  74.   # first parameter  - window title or part of the window title
  75.   window_title="$1"
  76.   time_sec=900
  77.   while [[ 0 -ne $time_sec ]]; do
  78.     echo "$time_sec, waiting... to activate"
  79.     time_sec=$[$time_sec-1]
  80.     xdotool search --onlyvisible --name "$window_title" windowactivate
  81.     window_name=$(xdotool getwindowfocus getwindowname)
  82.     if echo $window_name | grep -q "$window_title" ; then
  83.       echo "window active "$window_name
  84.       break
  85.     fi
  86.     sleep 0.5
  87.   done
  88. }
  89.  
  90. function time_add_seconds() {
  91.     # time format 00:58:12.749
  92.     IFS=':' read -ra my_array1 <<< "$1"
  93.     sec_input=$2
  94.     hr=${my_array1[0]}
  95.     min=${my_array1[1]}
  96.     sec=${my_array1[2]%.*}
  97.     msec=${my_array1[2]##*.}
  98.     secs=$(date +%s --date="1970-03-24 $hr:$min:$sec")
  99.     d=$(date '+%d.%b.%Y %T' --date="@$((secs + sec_input))")
  100.     t="${d##* }"".$msec"
  101.     echo $t
  102. }
  103.  
  104. function enter_timecode() {
  105.     seconds=$1
  106.     wait_for_window_to_activate "$player_title"
  107.     echo -n "" | xclip -selection clipboard
  108.     xdotool key Right
  109.     sleep 0.1
  110.     xdotool key g
  111.     sleep 0.5
  112.     xdotool key Ctrl+a
  113.     sleep 0.1
  114.     xdotool key Ctrl+c
  115.     sleep 0.1
  116.     clip_read=$(xsel -b)
  117.     mod_t=$(time_add_seconds "$clip_read" $seconds)
  118.     echo -n "$mod_t" | xclip -selection clipboard
  119.     xdotool key Ctrl+v
  120.     xdotool key Return
  121.     echo $clip_read
  122. }
  123.  
  124. block_double_run
  125. enter_timecode 60
  126. spd-say -t female2 n::::::::::::::
  127. fforward_s.bash
  128. ::::::::::::::
  129. #!/bin/bash
  130.  
  131.  
  132. player_title="LosslessCut"
  133.  
  134.  
  135. function block_double_run () {
  136.     pids=($(pidof -x $(basename $0)))
  137.     if [[ ${#pids[@]} -gt 1 ]] ; then
  138.         echo "double run blocked"
  139.         spd-say -t female2 "double run"
  140.         exit
  141.     fi
  142. }
  143.  
  144. function wait_for_window_to_activate() {
  145.   # first parameter  - window title or part of the window title
  146.   window_title="$1"
  147.   time_sec=900
  148.   while [[ 0 -ne $time_sec ]]; do
  149.     echo "$time_sec, waiting... to activate"
  150.     time_sec=$[$time_sec-1]
  151.     xdotool search --onlyvisible --name "$window_title" windowactivate
  152.     window_name=$(xdotool getwindowfocus getwindowname)
  153.     if echo $window_name | grep -q "$window_title" ; then
  154.       echo "window active "$window_name
  155.       break
  156.     fi
  157.     sleep 0.5
  158.   done
  159. }
  160.  
  161. function time_add_seconds() {
  162.     # time format 00:58:12.749
  163.     IFS=':' read -ra my_array1 <<< "$1"
  164.     sec_input=$2
  165.     hr=${my_array1[0]}
  166.     min=${my_array1[1]}
  167.     sec=${my_array1[2]%.*}
  168.     msec=${my_array1[2]##*.}
  169.     secs=$(date +%s --date="1970-03-24 $hr:$min:$sec")
  170.     d=$(date '+%d.%b.%Y %T' --date="@$((secs + sec_input))")
  171.     t="${d##* }"".$msec"
  172.     echo $t
  173. }
  174.  
  175. function enter_timecode() {
  176.     seconds=$1
  177.     wait_for_window_to_activate "$player_title"
  178.     echo -n "" | xclip -selection clipboard
  179.     xdotool key Right
  180.     sleep 0.1
  181.     xdotool key g
  182.     sleep 0.5
  183.     xdotool key Ctrl+a
  184.     sleep 0.1
  185.     xdotool key Ctrl+c
  186.     clip_read=$(xsel -b)
  187.     mod_t=$(time_add_seconds "$clip_read" $seconds)
  188.     echo -n "$mod_t" | xclip -selection clipboard
  189.     xdotool key Ctrl+v
  190.     xdotool key Return
  191.     echo $clip_read
  192. }
  193.  
  194. block_double_run
  195. enter_timecode 3
  196. spd-say -t female2 n::::::::::::::
  197. load_file.bash
  198. ::::::::::::::
  199. #!/bin/bash
  200.  
  201.  
  202. recordings_dir="/media/$(whoami)/extsd/recordings/"
  203. music_dir="/media/$(whoami)/extsd/Music/"
  204. clips_dir="$music_dir"clips/""
  205. player_full_path="$music_dir"LosslessCut-linux-x86_64.AppImage""
  206. player_title="LosslessCut"
  207.  
  208.  
  209. function block_double_run () {
  210.     pids=($(pidof -x $(basename $0)))
  211.     if [[ ${#pids[@]} -gt 1 ]] ; then
  212.         echo "double run blocked"
  213.         spd-say -t female2 "double run"
  214.         exit
  215.     fi
  216. }
  217.  
  218. function wait_for_window() {
  219.   # first parameter  - window title or part of the window title
  220.   window_title="$1"
  221.   time_sec=900
  222.   while [[ 0 -ne $time_sec ]]; do
  223.     echo "$time_sec, waiting... to appear"
  224.     sleep 1
  225.     time_sec=$[$time_sec-1]
  226.     xdotool search --onlyvisible --name "$window_title" windowactivate
  227.     if [[ $? == 0 ]]; then
  228.         xdotool getactivewindow windowmove 1 30
  229.       echo "window found"
  230.       break
  231.     fi
  232.   done
  233. }
  234.  
  235. function repeat_send_key() {
  236.   window_title="$1"
  237.   key="$2"
  238.   repeat="${3:-1}"
  239.   xdotool search --onlyvisible --name "$window_title" windowactivate
  240.   if [[ $? == 0 ]]; then
  241.       for (( i=1; i <= repeat; i++ ))
  242.       do
  243.        xdotool key $key
  244.        sleep 0.1
  245.       done
  246.     fi
  247. }
  248.  
  249. function make_it_exec() {
  250.     file_full_path="$1"
  251.     if [[ -x "$file_full_path" ]]; then
  252.         echo "File is executable"
  253.     else
  254.         chmod +x "$file_full_path"
  255.         echo "File is executable now"
  256.     fi
  257. }
  258.  
  259. function check_out_loc() {
  260.   w_dir="$1"
  261.   if [ -d "$w_dir" ]; then
  262.     echo direcotry exists
  263.   else
  264.     mkdir "$w_dir"
  265.     echo direcotry created
  266.   fi
  267. }
  268.  
  269. function check_audio_playback() {
  270.   time_sec=60
  271.   while [[ 0 -ne $time_sec ]]; do
  272.     repeat_send_key "$player_title" space
  273.     echo "$time_sec, waiting... to play"
  274.     sleep 1
  275.     time_sec=$[$time_sec-1]
  276.     status=$(pacmd list-sink-inputs | grep -c 'state: RUNNING')
  277.     if [[ $status -gt 0 ]]; then
  278.       echo "sound is playing"
  279.       break
  280.     fi
  281.   done
  282. }
  283.  
  284. function load_file() {
  285.     check_out_loc "$clips_dir"
  286.     cd $recordings_dir
  287.     readarray -t files < <(find ./ -maxdepth 1 -type f -regex '.*\.\(mp3\|flac\)$' | sed "s/.*\///" | sort)
  288.     if [ ${#files[@]} -gt 0 ]; then
  289.         file_name=$(basename "${files[0]}" | cut -d. -f1)
  290.         file_extension=$(basename "${files[0]}" | cut -d. -f2)
  291.         out_dir="$music_dir"
  292.         mv "$file_name.$file_extension" "$out_dir"
  293.         make_it_exec "$player_full_path"
  294.         echo "$out_dir$file_name.$file_extension"
  295.         killall losslesscut
  296.         "$player_full_path" --settings-json '{customOutDir:"'"${clips_dir::-1}"'", "autoMerge":"true"}' "$out_dir$file_name.$file_extension" &
  297.         wait_for_window "$player_title"
  298.         check_audio_playback
  299.     fi
  300. }
  301.  
  302. function move_previous() {
  303.     cd $music_dir
  304.     readarray -t files < <(find ./ -maxdepth 1 -type f -regex '.*\.\(mp3\|flac\)$' | sed "s/.*\///" | sort)
  305.     if [ ${#files[@]} -gt 0 ]; then
  306.         file_name=$(basename "${files[0]}" | cut -d. -f1)
  307.         file_extension=$(basename "${files[0]}" | cut -d. -f2)
  308.         date_str=$(date +%s)
  309.         check_out_loc "$clips_dir"
  310.         out_dir="$clips_dir"
  311.         echo "file to move: ""$file_name.$file_extension"
  312.         mv "$file_name.$file_extension" "$out_dir"$date_str"_$file_name.$file_extension"
  313.     fi
  314. }
  315.  
  316. block_double_run
  317. move_previous
  318. load_file
  319. spd-say -t female2 "file loaded"::::::::::::::
  320. mark_in.bash
  321. ::::::::::::::
  322. #!/bin/bash
  323.  
  324.  
  325. recordings_dir="/media/$(whoami)/extsd/recordings/"
  326. player_title="LosslessCut"
  327. markin_loc="$recordings_dir"markin.txt""
  328.  
  329.  
  330. function block_double_run () {
  331.   pids=($(pidof -x $(basename $0)))
  332.   if [[ ${#pids[@]} -gt 1 ]] ; then
  333.     echo "double run blocked"
  334.     spd-say -t female2 "double run"
  335.     exit
  336.   fi
  337. }
  338.  
  339. function wait_for_window_to_activate() {
  340.   # first parameter  - window title or part of the window title
  341.   window_title="$1"
  342.   time_sec=900
  343.   while [[ 0 -ne $time_sec ]]; do
  344.     echo "$time_sec, waiting... to activate"
  345.     time_sec=$[$time_sec-1]
  346.     xdotool search --onlyvisible --name "$window_title" windowactivate
  347.     window_name=$(xdotool getwindowfocus getwindowname)
  348.     if echo $window_name | grep -q "$window_title" ; then
  349.       echo "window active "$window_name
  350.       break
  351.     fi
  352.     sleep 0.5
  353.   done
  354. }
  355.  
  356. function repeat_send_key() {
  357.   window_title="$1"
  358.   key="$2"
  359.   repeat="${3:-1}"
  360.   xdotool search --onlyvisible --name "$window_title" windowactivate
  361.   if [[ $? == 0 ]]; then
  362.       for (( i=1; i <= repeat; i++ ))
  363.       do
  364.         xdotool key $key
  365.         sleep 0.1
  366.       done
  367.     fi
  368. }
  369.  
  370. function mark_in() {
  371.   repeat_send_key "$player_title" "i"
  372.   sleep 0.5
  373.   spd-say -t female2 "mark in"
  374. }
  375.  
  376. block_double_run
  377. wait_for_window_to_activate "$player_title"
  378. mark_in::::::::::::::
  379. mark_out.bash
  380. ::::::::::::::
  381. #!/bin/bash
  382.  
  383.  
  384. recordings_dir="/media/$(whoami)/extsd/recordings/"
  385. player_title="LosslessCut"
  386. markin_loc="$recordings_dir"markin.txt""
  387.  
  388.  
  389. function block_double_run () {
  390.   pids=($(pidof -x $(basename $0)))
  391.   if [[ ${#pids[@]} -gt 1 ]] ; then
  392.     echo "double run blocked"
  393.     spd-say -t female2 "double run"
  394.     exit
  395.   fi
  396. }
  397.  
  398. function wait_for_window_to_activate() {
  399.   # first parameter  - window title or part of the window title
  400.   window_title="$1"
  401.   time_sec=900
  402.   while [[ 0 -ne $time_sec ]]; do
  403.     echo "$time_sec, waiting... to activate"
  404.     time_sec=$[$time_sec-1]
  405.     xdotool search --onlyvisible --name "$window_title" windowactivate
  406.     window_name=$(xdotool getwindowfocus getwindowname)
  407.     if echo $window_name | grep -q "$window_title" ; then
  408.       echo "window active "$window_name
  409.       break
  410.     fi
  411.     sleep 0.5
  412.   done
  413. }
  414.  
  415. function repeat_send_key() {
  416.   window_title="$1"
  417.   key="$2"
  418.   repeat="${3:-1}"
  419.   xdotool search --onlyvisible --name "$window_title" windowactivate
  420.   if [[ $? == 0 ]]; then
  421.       for (( i=1; i <= repeat; i++ ))
  422.       do
  423.         xdotool key $key
  424.         sleep 0.1
  425.       done
  426.     fi
  427. }
  428.  
  429. function mark_out() {
  430.   repeat_send_key "$player_title" "o"
  431.   sleep 0.5
  432.   spd-say -t female2 "mark out"
  433. }
  434.  
  435. block_double_run
  436. wait_for_window_to_activate "$player_title"
  437. mark_out::::::::::::::
  438. move_files.bash
  439. ::::::::::::::
  440. #!/bin/bash
  441.  
  442.  
  443. # GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
  444.  
  445.  
  446. overwrite_files="yes"
  447. copying_mode="move"
  448. eject_usb_drive="yes"
  449. check_period_in_seconds=60
  450. # server PC:
  451. folder_to_monitor="/media/ramdisk/"
  452. # client PC, label of external sd card:
  453. monitor_skip_strings=(extsd)
  454. # my computer location:
  455. backup_root_folder="/media/$(whoami)/"
  456. search_for_folder_to_backup_to="recordings"
  457. file_extensions_to_include="mp3\|flac\|mp4"
  458. file_extensions_to_exclude="aria2"
  459.  
  460.  
  461. function countdown_timer() {
  462.     time_sec=$1
  463.     while [[ 0 -ne $time_sec ]]; do
  464.         echo "$time_sec, waiting... to start"
  465.         time_sec=$[$time_sec-1]
  466.         sleep 1
  467.     done
  468. }
  469.  
  470. function download_wait_to_finish() {
  471.     src_dir="$1"
  472.     search_dext="$2"
  473.     readarray -t arr_fd < <(find "$src_dir" -maxdepth 1 -type f -regex '.*\.\('$search_dext'\)$' | sed "s/.*\///" | sort)
  474.     if [[ ${#arr_fd[@]} > 0 ]]; then
  475.         echo "waiting for download to finish..."
  476.         while [[ ${#arr_fd[@]} > 0 ]]; do
  477.             sleep 1
  478.             readarray -t arr_fd < <(find "$src_dir" -maxdepth 1 -type f -regex '.*\.\('$search_dext'\)$' | sed "s/.*\///" | sort)
  479.         done
  480.         echo "download finished at: "$(date +"%H:%M:%S")
  481.     fi
  482. }
  483.  
  484. function find_copy_files() {
  485.     src_dir="$1"
  486.     out_dir_root="$2"
  487.     backup_dir="$3"
  488.     search_ext="$4"
  489.     copy_detection=0
  490.     client_detection=0
  491.     out_dir=""
  492.     mount_loc=""
  493.     readarray -t arr_d < <(find "$out_dir_root" -mindepth 1 -maxdepth 1 -type d | sed "s/.*\///" | sort)
  494.     # detect server or client
  495.     for i in "${arr_d[@]}"
  496.     do
  497.         out_dir_loc="$out_dir_root$i/$backup_dir/"
  498.         if [[ -d "$out_dir_loc" ]]; then
  499.             mount_loc="$out_dir_root$i"
  500.             # client detection:
  501.             if [[ $client_detection -eq 0 ]]; then
  502.                 for j in "${monitor_skip_strings[@]}"
  503.                 do
  504.                     if echo $out_dir_loc | grep -q "$j" ; then
  505.                         client_detection=1
  506.                         break
  507.                     fi
  508.                 done
  509.             fi
  510.             if [[ $client_detection -eq 1 ]]; then
  511.                 # only one input:
  512.                 for j in "${monitor_skip_strings[@]}"
  513.                 do
  514.                     if echo $out_dir_loc | grep -q "$j" ; then
  515.                         echo "skipping" > /dev/null
  516.                     else
  517.                         src_dir=$out_dir_loc
  518.                         break
  519.                     fi
  520.                 done
  521.                 # only one output:
  522.                 for j in "${monitor_skip_strings[@]}"
  523.                 do
  524.                     if echo $out_dir_loc | grep -q "$j" ; then
  525.                         out_dir=$out_dir_loc
  526.                         break
  527.                     fi
  528.                 done
  529.             elif [[ $client_detection -eq 0 ]]; then
  530.                 # only one output, first one found:
  531.                 for j in "${monitor_skip_strings[@]}"
  532.                 do
  533.                     if echo $out_dir_loc | grep -q "$j" ; then
  534.                         echo "skipping" > /dev/null
  535.                     else
  536.                         out_dir=$out_dir_loc
  537.                         break
  538.                     fi
  539.                 done
  540.                 # input is original, unchanged
  541.             fi
  542.         fi
  543.     done
  544.     echo "source directory: $src_dir"
  545.     echo "backup directory: $out_dir"
  546.     download_wait_to_finish "$src_dir" "$file_extensions_to_exclude"
  547.     if [[ ! $out_dir == "" ]]; then
  548.         readarray -t arr_f < <(find "$src_dir" -maxdepth 1 -type f -regex '.*\.\('$search_ext'\)$' | sed "s/.*\///" | sort)
  549.         for i in "${arr_f[@]}"
  550.         do
  551.             file_src_loc=$src_dir$i
  552.             file_out_loc=$out_dir$i
  553.             if [[ "$copying_mode" == "copy" ]]; then
  554.                 if [[ ! -f "$file_out_loc" ]]; then
  555.                     echo "coping file: $file_src_loc"
  556.                     cp "$file_src_loc" "$out_dir"
  557.                     copy_detection=1
  558.                 elif [[ "$overwrite_files" == "yes" && $file_src_loc -nt $file_out_loc ]]; then
  559.                     echo "overwriting file: $file_src_loc"
  560.                     cp "$file_src_loc" "$out_dir"
  561.                     copy_detection=1
  562.                 else
  563.                     echo "file exists, skipping: $file_out_loc"
  564.                 fi
  565.             elif [[ "$copying_mode" == "move" ]]; then
  566.                 if [[ ! -f "$file_out_loc" ]]; then
  567.                     echo "moving file: $file_src_loc"
  568.                     mv -n "$file_src_loc" "$file_out_loc"
  569.                     copy_detection=1
  570.                 elif [[ "$overwrite_files" == "yes" && $file_src_loc -nt $file_out_loc ]]; then
  571.                     echo "moving and overwriting file: $file_src_loc"
  572.                     mv -f "$file_src_loc" "$file_out_loc"
  573.                     copy_detection=1
  574.                 else
  575.                     echo "file exists, skipping: $file_out_loc"
  576.                 fi
  577.             fi
  578.         done
  579.     fi
  580. }
  581.  
  582. while :
  583. do
  584.     countdown_timer $check_period_in_seconds
  585.     find_copy_files "$folder_to_monitor" "$backup_root_folder" "$search_for_folder_to_backup_to" "$file_extensions_to_include"
  586.     if [[ copy_detection -eq 1 ]]; then
  587.         if [[ "$eject_usb_drive" == "yes" ]]; then
  588.             # eject backup/source location
  589.             gio mount -e "$mount_loc"
  590.             spd-say -t female2 "usb drive ejected"
  591.             sleep 3
  592.         fi
  593.         # sudo apt install speech-dispatcher
  594.         spd-say -t female2 "your grace, backup is done, please praise me..."
  595.     fi
  596. done::::::::::::::
  597. play_pause.bash
  598. ::::::::::::::
  599. #!/bin/bash
  600.  
  601.  
  602. player_title="LosslessCut"
  603.  
  604.  
  605. function block_double_run () {
  606.   pids=($(pidof -x $(basename $0)))
  607.   if [[ ${#pids[@]} -gt 1 ]] ; then
  608.     echo "double run blocked"
  609.     spd-say -t female2 "double run"
  610.     exit
  611.   fi
  612. }
  613.  
  614. function wait_for_window_to_activate() {
  615.   # first parameter  - window title or part of the window title
  616.   window_title="$1"
  617.   time_sec=900
  618.   while [[ 0 -ne $time_sec ]]; do
  619.     echo "$time_sec, waiting... to close"
  620.     time_sec=$[$time_sec-1]
  621.     xdotool search --onlyvisible --name "$window_title" windowactivate
  622.     window_name=$(xdotool getwindowfocus getwindowname)
  623.     if echo $window_name | grep -q "$window_title" ; then
  624.       echo "window active "$window_name
  625.       break
  626.     fi
  627.     sleep 0.5
  628.   done
  629. }
  630.  
  631. function repeat_send_key() {
  632.   window_title="$1"
  633.   key="$2"
  634.   repeat="${3:-1}"
  635.   xdotool search --onlyvisible --name "$window_title" windowactivate
  636.   if [[ $? == 0 ]]; then
  637.       for (( i=1; i <= repeat; i++ ))
  638.       do
  639.         xdotool key $key
  640.         sleep 0.1
  641.       done
  642.     fi
  643. }
  644.  
  645. block_double_run
  646. spd-say -t female2 s
  647. wait_for_window_to_activate "$player_title"
  648. repeat_send_key "$player_title" space::::::::::::::
  649. poweroff_screen.bash
  650. ::::::::::::::
  651. #!/bin/bash
  652.  
  653. # sudo apt install xprintidle
  654.  
  655. function poweroff_screen() {
  656.     # in seconds:
  657.     time_in_seconds=$1
  658.     threshold=$(( $time_in_seconds * 1000 ))
  659.     while :
  660.     do
  661.         sleep 1
  662.         idletime=$(xprintidle)
  663.         if [[ $idletime -gt $threshold ]]; then
  664.             # reduce brightness
  665.             xrandr --output DSI-1 --brightness 0.10
  666.             sleep 1
  667.             # poweroff screen
  668.             xset dpms force off
  669.             sleep $time_in_seconds
  670.         fi
  671.     done
  672. }
  673.  
  674. poweroff_screen 9::::::::::::::
  675. redshift.bash
  676. ::::::::::::::
  677. #!/bin/bash
  678.  
  679. redshift -O 3700
  680. spd-say -t female2 "redshift"::::::::::::::
  681. resume_playback.bash
  682. ::::::::::::::
  683. #!/bin/bash
  684.  
  685. music_dir="/media/$(whoami)/extsd/Music/"
  686. clips_dir="$music_dir"clips/""
  687. player_full_path="$music_dir"LosslessCut-linux-x86_64.AppImage""
  688. player_title="LosslessCut"
  689.  
  690.  
  691. function block_double_run () {
  692.     pids=($(pidof -x $(basename $0)))
  693.     if [[ ${#pids[@]} -gt 1 ]] ; then
  694.         echo "double run blocked"
  695.         spd-say -t female2 "double run"
  696.         exit
  697.     fi
  698. }
  699.  
  700. function wait_for_window() {
  701.   # first parameter  - window title or part of the window title
  702.   window_title="$1"
  703.   time_sec=900
  704.   while [[ 0 -ne $time_sec ]]; do
  705.     echo "$time_sec, waiting... to appear"
  706.     sleep 1
  707.     time_sec=$[$time_sec-1]
  708.     xdotool search --onlyvisible --name "$window_title" windowactivate
  709.     if [[ $? == 0 ]]; then
  710.         xdotool getactivewindow windowmove 1 30
  711.       echo "window found"
  712.       break
  713.     fi
  714.   done
  715. }
  716.  
  717. function repeat_send_key() {
  718.   window_title="$1"
  719.   key="$2"
  720.   repeat="${3:-1}"
  721.   xdotool search --onlyvisible --name "$window_title" windowactivate
  722.   if [[ $? == 0 ]]; then
  723.       for (( i=1; i <= repeat; i++ ))
  724.       do
  725.        xdotool key $key
  726.        sleep 0.1
  727.       done
  728.     fi
  729. }
  730.  
  731. function make_it_exec() {
  732.     file_full_path="$1"
  733.     if [[ -x "$file_full_path" ]]; then
  734.         echo "File is executable"
  735.     else
  736.         chmod +x "$file_full_path"
  737.         echo "File is executable now"
  738.     fi
  739. }
  740.  
  741. function check_audio_playback() {
  742.   time_sec=60
  743.   while [[ 0 -ne $time_sec ]]; do
  744.     repeat_send_key "$player_title" space
  745.     echo "$time_sec, waiting... to play"
  746.     sleep 1
  747.     time_sec=$[$time_sec-1]
  748.     status=$(pacmd list-sink-inputs | grep -c 'state: RUNNING')
  749.     if [[ $status -gt 0 ]]; then
  750.       echo "sound is playing"
  751.       break
  752.     fi
  753.   done
  754. }
  755.  
  756. function load_file() {
  757.     cd $music_dir
  758.     readarray -t files < <(find ./ -maxdepth 1 -type f -regex '.*\.\(mp3\|flac\)$' | sed "s/.*\///" | sort)
  759.     if [ ${#files[@]} -gt 0 ]; then
  760.         file_name=$(basename "${files[0]}" | cut -d. -f1)
  761.         file_extension=$(basename "${files[0]}" | cut -d. -f2)
  762.         out_dir="$music_dir"
  763.         mv "$file_name.$file_extension" "$out_dir"
  764.         make_it_exec "$player_full_path"
  765.         echo "$out_dir$file_name.$file_extension"
  766.         killall losslesscut
  767.         "$player_full_path" --settings-json '{customOutDir:"'"${clips_dir::-1}"'", "autoMerge":"true"}' "$out_dir$file_name.$file_extension" &
  768.         wait_for_window "$player_title"
  769.         check_audio_playback
  770.         # jump to current segment's start time, mark in used to make paper place, one segment
  771.         xdotool key Shift+Left
  772.     fi
  773. }
  774.  
  775. block_double_run
  776. load_file
  777. sleep 2
  778. spd-say -t female2 "resume playing"::::::::::::::
  779. rewind.bash
  780. ::::::::::::::
  781. #!/bin/bash
  782.  
  783.  
  784. player_title="LosslessCut"
  785.  
  786.  
  787. function block_double_run () {
  788.   pids=($(pidof -x $(basename $0)))
  789.   if [[ ${#pids[@]} -gt 1 ]] ; then
  790.     echo "double run blocked"
  791.     spd-say -t female2 "double run"
  792.     exit
  793.   fi
  794. }
  795.  
  796. function wait_for_window_to_activate() {
  797.   # first parameter  - window title or part of the window title
  798.   window_title="$1"
  799.   time_sec=900
  800.   while [[ 0 -ne $time_sec ]]; do
  801.     echo "$time_sec, waiting... to activate"
  802.     time_sec=$[$time_sec-1]
  803.     xdotool search --onlyvisible --name "$window_title" windowactivate
  804.     window_name=$(xdotool getwindowfocus getwindowname)
  805.     if echo $window_name | grep -q "$window_title" ; then
  806.       echo "window active "$window_name
  807.       break
  808.     fi
  809.     sleep 0.5
  810.   done
  811. }
  812.  
  813. function time_minus_seconds() {
  814.   # time format 00:58:12.749
  815.   IFS=':' read -ra my_array1 <<< "$1"
  816.   sec_input=$2
  817.   hr=${my_array1[0]}
  818.   min=${my_array1[1]}
  819.   sec=${my_array1[2]%.*}
  820.   msec=${my_array1[2]##*.}
  821.   secs=$(date +%s --date="1970-03-24 $hr:$min:$sec")
  822.   d=$(date '+%d.%b.%Y %T' --date="@$((secs - sec_input))")
  823.   t="${d##* }"".$msec"
  824.   echo $t
  825. }
  826.  
  827. function enter_timecode() {
  828.   seconds=$1
  829.   wait_for_window_to_activate "$player_title"
  830.   echo -n "" | xclip -selection clipboard
  831.   xdotool key Left
  832.   sleep 0.1
  833.   xdotool key g
  834.   sleep 0.5
  835.   xdotool key Ctrl+a
  836.   sleep 0.1
  837.   xdotool key Ctrl+c
  838.   clip_read=$(xsel -b)
  839.   mod_t=$(time_minus_seconds "$clip_read" $seconds)
  840.   echo -n "$mod_t" | xclip -selection clipboard
  841.   xdotool key Ctrl+v
  842.   xdotool key Return
  843.   echo $clip_read
  844. }
  845.  
  846. block_double_run
  847. enter_timecode 15
  848. spd-say -t female2 p::::::::::::::
  849. rewind_s.bash
  850. ::::::::::::::
  851. #!/bin/bash
  852.  
  853.  
  854. player_title="LosslessCut"
  855.  
  856.  
  857. function block_double_run () {
  858.   pids=($(pidof -x $(basename $0)))
  859.   if [[ ${#pids[@]} -gt 1 ]] ; then
  860.     echo "double run blocked"
  861.     spd-say -t female2 "double run"
  862.     exit
  863.   fi
  864. }
  865.  
  866. function wait_for_window_to_activate() {
  867.   # first parameter  - window title or part of the window title
  868.   window_title="$1"
  869.   time_sec=900
  870.   while [[ 0 -ne $time_sec ]]; do
  871.     echo "$time_sec, waiting... to activate"
  872.     time_sec=$[$time_sec-1]
  873.     xdotool search --onlyvisible --name "$window_title" windowactivate
  874.     window_name=$(xdotool getwindowfocus getwindowname)
  875.     if echo $window_name | grep -q "$window_title" ; then
  876.       echo "window active "$window_name
  877.       break
  878.     fi
  879.     sleep 0.5
  880.   done
  881. }
  882.  
  883. function time_minus_seconds() {
  884.   # time format 00:58:12.749
  885.   IFS=':' read -ra my_array1 <<< "$1"
  886.   sec_input=$2
  887.   hr=${my_array1[0]}
  888.   min=${my_array1[1]}
  889.   sec=${my_array1[2]%.*}
  890.   msec=${my_array1[2]##*.}
  891.   secs=$(date +%s --date="1970-03-24 $hr:$min:$sec")
  892.   d=$(date '+%d.%b.%Y %T' --date="@$((secs - sec_input))")
  893.   t="${d##* }"".$msec"
  894.   echo $t
  895. }
  896.  
  897. function enter_timecode() {
  898.   seconds=$1
  899.   wait_for_window_to_activate "$player_title"
  900.   echo -n "" | xclip -selection clipboard
  901.   xdotool key Left
  902.   sleep 0.1
  903.   xdotool key g
  904.   sleep 0.5
  905.   xdotool key Ctrl+a
  906.   sleep 0.1
  907.   xdotool key Ctrl+c
  908.   clip_read=$(xsel -b)
  909.   mod_t=$(time_minus_seconds "$clip_read" $seconds)
  910.   echo -n "$mod_t" | xclip -selection clipboard
  911.   xdotool key Ctrl+v
  912.   xdotool key Return
  913.   echo $clip_read
  914. }
  915.  
  916. block_double_run
  917. enter_timecode 3
  918. spd-say -t female2 p::::::::::::::
  919. screen_off.bash
  920. ::::::::::::::
  921. #!/bin/bash
  922.  
  923. spd-say -t female2 "screen off"
  924. xrandr --output DSI-1 --brightness 0.10
  925. sleep 1
  926. xset dpms force off::::::::::::::
  927. shutdown.bash
  928. ::::::::::::::
  929. #!/bin/bash
  930.  
  931. # sudo apt install speech-dispatcher wmctrl
  932.  
  933. spd-say -t female2 "shutdown started"
  934. visible_window_ids=$(wmctrl -l | egrep -v "AllTray| -1 " | cut -d" " -f 1)
  935. read -ra arr -d ' ' <<< "$visible_window_ids"
  936. for i in "${arr[@]}"
  937. do
  938.     xdotool windowactivate --sync $i
  939.     sleep 0.5
  940.     xdotool keydown alt && sleep 0.5 && xdotool key F4 && sleep 0.5 && xdotool keyup alt
  941.     sleep 5
  942. done
  943. spd-say -t female2 "powering off"
  944. sleep 3
  945. systemctl poweroff::::::::::::::
  946. split_audio.bash
  947. ::::::::::::::
  948. #!/bin/bash
  949.  
  950.  
  951. player_title="LosslessCut"
  952.  
  953.  
  954. function block_double_run () {
  955.   pids=($(pidof -x $(basename $0)))
  956.   if [[ ${#pids[@]} -gt 1 ]] ; then
  957.     echo "double run blocked"
  958.     spd-say -t female2 "double run"
  959.     exit
  960.   fi
  961. }
  962.  
  963. function wait_for_window_to_activate() {
  964.   # first parameter  - window title or part of the window title
  965.   window_title="$1"
  966.   time_sec=900
  967.   while [[ 0 -ne $time_sec ]]; do
  968.     echo "$time_sec, waiting... to activate"
  969.     time_sec=$[$time_sec-1]
  970.     xdotool search --onlyvisible --name "$window_title" windowactivate
  971.     window_name=$(xdotool getwindowfocus getwindowname)
  972.     if echo $window_name | grep -q "$window_title" ; then
  973.       echo "window active "$window_name
  974.       break
  975.     fi
  976.     sleep 0.5
  977.   done
  978. }
  979.  
  980. function cut_audio() {
  981.   xdotool key e
  982.   sleep 0.5
  983.   xdotool key e
  984.   sleep 0.5
  985. }
  986.  
  987. block_double_run
  988. wait_for_window_to_activate "$player_title"
  989. cut_audio
  990. spd-say -t female2 "split audio"::::::::::::::
  991. volume_down.bash
  992. ::::::::::::::
  993. #!/bin/bash
  994.  
  995. pactl -- set-sink-volume 0 -1%::::::::::::::
  996. volume_up.bash
  997. ::::::::::::::
  998. #!/bin/bash
  999.  
  1000. pactl -- set-sink-volume 0 +1%::::::::::::::
  1001. .xbindkeysrc
  1002. ::::::::::::::
  1003. "/media/$(whoami)/extsd/Music/rewind.bash"
  1004. c:87
  1005.  
  1006. "/media/$(whoami)/extsd/Music/fforward.bash"
  1007. c:88
  1008.  
  1009. "/media/$(whoami)/extsd/Music/play_pause.bash"
  1010. c:89
  1011.  
  1012. "/media/$(whoami)/extsd/Music/mark_in.bash"
  1013. c:84
  1014.  
  1015. "/media/$(whoami)/extsd/Music/mark_out.bash"
  1016. c:85
  1017.  
  1018. "/media/$(whoami)/extsd/Music/split_audio.bash"
  1019. c:83
  1020.  
  1021. "/media/$(whoami)/extsd/Music/volume_up.bash"
  1022. c:86
  1023.  
  1024. "/media/$(whoami)/extsd/Music/volume_down.bash"
  1025. c:82
  1026.  
  1027. "/media/$(whoami)/extsd/Music/load_file.bash"
  1028. c:90
  1029.  
  1030. "/media/$(whoami)/extsd/Music/screen_off.bash"
  1031. c:91
  1032.  
  1033. "/media/$(whoami)/extsd/Music/redshift.bash"
  1034. c:104
  1035.  
  1036. "/media/$(whoami)/extsd/Music/rewind_s.bash"
  1037. c:79
  1038.  
  1039. "/media/$(whoami)/extsd/Music/fforward_s.bash"
  1040. c:80
  1041.  
  1042. "/media/$(whoami)/extsd/Music/escape.bash"
  1043. c:106
  1044.  
  1045. "/media/$(whoami)/extsd/Music/resume_playback.bash"
  1046. c:81
  1047.  
  1048. "/media/$(whoami)/extsd/Music/shutdown.bash"
  1049. c:63
  1050.  
  1051. "/media/$(whoami)/extsd/Music/brightness_down.bash"
  1052. c:163
  1053.  
  1054. "/media/$(whoami)/extsd/Music/brightness_up.bash"
  1055. c:180
Advertisement
Add Comment
Please, Sign In to add comment