Merge 1d1c9dd1a8877ecb424f3a3c19b9024f7e66fb1b into 1f7376c805cb57daef05713412f8e562141eead8

This commit is contained in:
TheYellowArchitect 2024-05-22 11:24:19 +03:30 committed by GitHub
commit e4049fae2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -136,6 +136,60 @@ cmd bulkrename ${{
lf -remote "send $id unselect"
}}
cmd encodetomp3 ${{
clear;
set -f;
#Variables for notify-send
converted_filenames="";
converted_files_count=0;
videos_without_audio_streams="";
videos_without_audio_streams_count=0;
for pickedFilepath in $fx; do
case $pickedFilepath in
*.mp4 | *.webm | *.mkv)
;;
*)
echo 'Skipping ${pickedFilepath}' && continue 1;;
esac
parsed_MP3=$(echo "$pickedFilepath" | sed 's/\(.mp4\|.webm\|.mkv\)/.mp3/' | sed 's|.*\/||');
parsed_MP3="~/Music/${parsed_MP3}";
#Using ffprobe because videos without audiostream result in exit code 1 which stops this entire loop of many files
#Remove (alongside its 2 variables) if you don't record videos without audio (which are admittedly rare)
if [[ $(ffprobe -loglevel error -show_entries stream=codec_type -of csv=p=0 "$pickedFilepath") != *"audio"* ]]; then
((videos_without_audio_streams_count=videos_without_audio_streams_count+1));
videos_without_audio_streams="$videos_without_audio_streams"$'\n'"$pickedFilepath";
continue 1;
fi
ffmpeg -i "$pickedFilepath" "$parsed_MP3";
((converted_files_count=converted_files_count+1));
converted_filenames="$converted_filenames"$'\n'"$pickedFilepath";
if [[ $# -eq 1 ]]; then
rm -f -- $pickedFilepath;
fi
done
#Notify the results to the user
if [[ $converted_files_count -gt 0 ]]; then
converted_filenames=$(echo "$converted_filenames" | sed 's|.*\/||');
notify-send "Converted MP3 Files($converted_files_count):" "$converted_filenames";
fi;
if [[ $videos_without_audio_streams_count -gt 0 ]]; then
videos_without_audio_streams=$(echo "$videos_without_audio_streams" | sed 's|.*\/||');
notify-send "Videos without audio stream($videos_without_audio_streams_count):" "$videos_without_audio_streams";
fi;
#Uncomment the below line if you want to automatically unselect the original converted video files
#lf -remote "send $id unselect";
}}
# Bindings
map <c-f> $lf -remote "send $id select \"$(fzf)\""
map J $lf -remote "send $id cd $(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf)"
@ -177,5 +231,8 @@ map <c-l> unselect
map b encodetomp3
map <a-b> encodetomp3 delete_after_encoding
# Source Bookmarks
source "~/.config/lf/shortcutrc"