41 lines
1.4 KiB
Bash
Executable File
41 lines
1.4 KiB
Bash
Executable File
|
|
|
|
EXEC_SHELL_PATH=$(command -v bash)
|
|
|
|
send_most_recent_video_via_telegram() {
|
|
# Specify the correct folder path
|
|
folder_path="$HOME/Videos"
|
|
|
|
# Check if the folder exists
|
|
if [ ! -d "$folder_path" ]; then
|
|
echo "Error: Folder does not exist."
|
|
return 1
|
|
fi
|
|
|
|
# Check if the folder is empty
|
|
if [ -z "$(find "$folder_path" -maxdepth 1 \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.avi" -o -iname "*.mov" -o -iname "*.flv" -o -iname "*.wmv" -o -iname "*.mpg" -o -iname "*.mpeg" -o -iname "*.webm" \) -print -quit)" ]; then
|
|
echo "Error: Folder does not contain any video files."
|
|
return 1
|
|
fi
|
|
|
|
# Get the most recent video file
|
|
most_recent_video=$(find "$folder_path" -maxdepth 1 \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.avi" -o -iname "*.mov" -o -iname "*.flv" -o -iname "*.wmv" -o -iname "*.mpg" -o -iname "*.mpeg" -o -iname "*.webm" \) -exec stat --format='%Y %n' {} + | sort -nr | head -n 1 | cut -d ' ' -f 2-)
|
|
file_path="$most_recent_video"
|
|
|
|
# Check if telegram-desktop is installed
|
|
if ! command -v telegram-desktop &> /dev/null; then
|
|
echo "Error: telegram-desktop is not installed."
|
|
return 1
|
|
fi
|
|
|
|
# Activate telegram-desktop window
|
|
wmctrl -x -a telegram-desktop
|
|
|
|
# Send the most recent video file via telegram-desktop
|
|
telegram-desktop -sendpath "$file_path"
|
|
echo "Sent most recent video file via telegram-desktop: $file_path"
|
|
}
|
|
|
|
# Execute the function
|
|
send_most_recent_video_via_telegram
|