From e89408bbdb62fb7edd7e6572259aee4eeba22275 Mon Sep 17 00:00:00 2001 From: Q Date: Fri, 11 Oct 2024 22:01:36 +0300 Subject: [PATCH] mpv scripts --- av/mpvmontage | 53 +++++++++++++++++++++++++++++ av/mpvmusic | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ av/mpvsub | 67 +++++++++++++++++++++++++++++++++++++ bin/mpvmontage | 1 + bin/mpvmusic | 1 + bin/mpvsub | 1 + 6 files changed, 213 insertions(+) create mode 100755 av/mpvmontage create mode 100755 av/mpvmusic create mode 100755 av/mpvsub create mode 120000 bin/mpvmontage create mode 120000 bin/mpvmusic create mode 120000 bin/mpvsub diff --git a/av/mpvmontage b/av/mpvmontage new file mode 100755 index 0000000..59dbee7 --- /dev/null +++ b/av/mpvmontage @@ -0,0 +1,53 @@ +#!/bin/bash + +if [[ "$1" = "-h" ]]; then + echo "View multiple videos together. Maximum three files." + exit +fi + + +. qolop &> /dev/null +_qCol export &> /dev/null + +echo -e "${_cW}${_cU}# MPV shortcuts +${_cZ}${_cG} +Modifiers: c = CTRL + +| Key | Playback | | Key | Audio | +|:-------|:---------------------------| |:-------|:----------------------| +| p | Pause | | m | Mute | +| s | Screenshot | | 9/0 | Modify volume | +| S | Screenshot without subs | | c-+/- | Change audio delay | +| Q | Quit saving position | | # | Change audio track | +| ,/. | Seek frame | +| <-/-> | Seek 5 seconds | | Key | Subtitles | +| up/dn | Seek 60 seconds | |:-------|:----------------------| +| < / > | Prev/Next file | | v | Subtitle toggle | +| [/] | Change speed | | j/J | Change subtitle | +| o | Show progress | | z/x | Change subtitle delay | +| O | Progress toggle | | r/t | Subtitles up / down | + +| Key | Video | +|:-------|:---------------------------| +| f | Fullscreen | +| T | Toggle video on top | +| A | Cycle aspect ratio | +| 1/2 | Modify contrast | +| 3/4 | Modify brightness | +| 5/6 | Modify gamma | +| 7/8 | Modify saturation | +| w/e | Zoom in / out (fullscreen) | + +${_cZ}" + +if [[ -z "$3" ]]; then + mpv \ + --lavfi-complex="[vid1][vid2]hstack[vo]" \ + "$1" --external-file="$2" +else + + mpv \ + --lavfi-complex="[vid1][vid2][vid3]hstack=inputs=3[vo]" \ + "$1" --external-files="$2:$3" + +fi diff --git a/av/mpvmusic b/av/mpvmusic new file mode 100755 index 0000000..336591f --- /dev/null +++ b/av/mpvmusic @@ -0,0 +1,90 @@ +#!/bin/bash + +_list_audio_files() { + if [[ $recursive -eq 0 ]]; then + files=$( ls -p | grep -v /$ ) + else + files=$( find . -type f ) + fi + echo "$files" | \ + grep -i -e \.mp3$ -e \.ogg$ -e \.flac$ | \ + sort -V | \ + awk '{print "'"$PWD"'/"$0}' +} + +_print_audio_files() { + n=$( wc -l "$1" | awk '{print $1}' ) + i=0 + while read line; do + i=$(( i + 1 )) + printf "%s/%s %s\n" \ + $i $n "$( basename "$line" )" + done < "$1" +} + +_play() { + mpv \ + --keep-open=no \ + --audio-display=no \ + --term-osd-bar \ + --msg-level=ffmpeg/audio=fatal,ad=fatal \ + --playlist="$1" $MPV_ARGS +} + +echo ' -r recursive +MPV_ARGS=.. to pass them.. + +# MPV audio shortcuts' +qolop c Y +echo ' +| Key | Command | +|:-------|:---------------------------| +| p | Pause | +| Q | Quit saving position | +| <-/-> | Seek 5 seconds | +| up/dn | Seek 60 seconds | +| < / > | Prev/Next file | +| [/] | Change speed | +| m | Mute | +| 9/0 | Modify volume | +| * / | Modify volume | +' +qolop c Z + +recursive=0 +for (( i=1; i<=$#; i++ )); do + [[ "${!i}" = "-r" ]] && { + recursive=1; + continue + } +done + +if [[ -e "$1" ]]; then + if [[ "$1" = *".m3u8" ]]; then + _play "$1" + exit $? + fi +fi + + +playlistfile=$( mktemp ) +if [[ $recursive -eq 1 ]]; then + _list_audio_files > "$playlistfile" +else + if [[ -n "$1" ]]; then + for (( i=1; i<=$#; i++ )); do + readlink -f "${!i}" >> "$playlistfile" + done + else + _list_audio_files > "$playlistfile" + fi +fi + +_print_audio_files "$playlistfile" +if [[ -s "$playlistfile" ]]; then + _play "$playlistfile" +else + echo Playlist empty +fi + +rm -f "$playlistfile" diff --git a/av/mpvsub b/av/mpvsub new file mode 100755 index 0000000..23d277e --- /dev/null +++ b/av/mpvsub @@ -0,0 +1,67 @@ +#!/bin/bash + +if [[ "$1" = "-h" ]]; then + echo "View video with subs with mpv. Arguments: video-file subs-file" + echo "if subs omitted, tries to search for the file" + exit +fi + + +. qolop &> /dev/null +_qCol export &> /dev/null + +echo -e "${_cW}${_cU}# MPV shortcuts +${_cZ}${_cG} +Modifiers: c = CTRL + +| Key | Playback | | Key | Audio | +|:-------|:---------------------------| |:-------|:----------------------| +| p | Pause | | m | Mute | +| s | Screenshot | | 9/0 | Modify volume | +| S | Screenshot without subs | | c-+/- | Change audio delay | +| Q | Quit saving position | | # | Change audio track | +| ,/. | Seek frame | +| <-/-> | Seek 5 seconds | | Key | Subtitles | +| up/dn | Seek 60 seconds | |:-------|:----------------------| +| < / > | Prev/Next file | | v | Subtitle toggle | +| [/] | Change speed | | j/J | Change subtitle | +| o | Show progress | | z/x | Change subtitle delay | +| O | Progress toggle | | r/t | Subtitles up / down | + +| Key | Video | +|:-------|:---------------------------| +| f | Fullscreen | +| T | Toggle video on top | +| A | Cycle aspect ratio | +| 1/2 | Modify contrast | +| 3/4 | Modify brightness | +| 5/6 | Modify gamma | +| 7/8 | Modify saturation | +| w/e | Zoom in / out (fullscreen) | + +${_cZ}" + + +if [[ -f "$1" ]]; then + vid="$1" +else + vid=$( ls -S | head -n 1 ) +fi +if [[ -f "$2" ]]; then + sub="$2" +else + sub=$( ls | grep -i srt$ | head -n 1 ) + if [[ ! -f "$sub" ]]; then + sub=$( find . -maxdepth 2 -type f | grep -i srt$ | head -n 1 ) + fi +fi +echo Video: $vid +echo Subs: $sub + +read -t4 -n1 foo + +if [[ -f "$sub" ]]; then + mpv --really-quiet --sub-file="$sub" "$vid" +else + mpv --really-quiet "$vid" +fi diff --git a/bin/mpvmontage b/bin/mpvmontage new file mode 120000 index 0000000..4ae8e66 --- /dev/null +++ b/bin/mpvmontage @@ -0,0 +1 @@ +../av/mpvmontage \ No newline at end of file diff --git a/bin/mpvmusic b/bin/mpvmusic new file mode 120000 index 0000000..3611e15 --- /dev/null +++ b/bin/mpvmusic @@ -0,0 +1 @@ +../av/mpvmusic \ No newline at end of file diff --git a/bin/mpvsub b/bin/mpvsub new file mode 120000 index 0000000..4ff8a3e --- /dev/null +++ b/bin/mpvsub @@ -0,0 +1 @@ +../av/mpvsub \ No newline at end of file