diff --git a/config/scripts/.local/scripts/playlive b/config/scripts/.local/scripts/playlive new file mode 100755 index 0000000..4473600 --- /dev/null +++ b/config/scripts/.local/scripts/playlive @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [ -z "${1:-}" ]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +play_cmd=() +if command -v mpv >/dev/null 2>&1; then + play_cmd=(mpv --title="Live Photo View" --keep-open=no --loop-file=no --loop-playlist=no --idle=no) +elif command -v vlc >/dev/null 2>&1; then + play_cmd=(vlc --play-and-exit) +else + echo "Error: No suitable media player found." >&2 + exit 1 +fi + +file="$1" + +if [ ! -f "$file" ]; then + echo "Error: File '$file' not found." >&2 + exit 1 +fi + +tmp_video=$(mktemp --suffix=.mp4) +trap 'rm -f "$tmp_video"' EXIT + +offset=$(grep -aobP "ftyp(mp42|isom)" "$file" | tail -n 1 | cut -d: -f1 || true) + +if [ -z "$offset" ]; then + echo "Error: No valid video stream found in '$file'." >&2 + exit 1 +fi + +mp4_offset=$((offset - 3)) + +tail -c "+$mp4_offset" "$file" > "$tmp_video" + +"${play_cmd[@]}" "$tmp_video" \ No newline at end of file diff --git a/config/scripts/.local/share/applications/playlive.desktop b/config/scripts/.local/share/applications/playlive.desktop new file mode 100644 index 0000000..ea4ef85 --- /dev/null +++ b/config/scripts/.local/share/applications/playlive.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Name=Play Live Photo +Comment=Play embedded video from Live Photos +Exec=/home/kolkas/.local/scripts/playlive %f +Icon=multimedia-video-player +Terminal=false +Categories=AudioVideo;Video;Utility; +MimeType=image/jpeg;image/heic;image/heif; \ No newline at end of file