Last active
December 20, 2025 18:37
-
-
Save xim/645216 to your computer and use it in GitHub Desktop.
mplayer wrapper for making playlists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -f | |
| SORT="sort -n" | |
| filter="-type f" | |
| DENIED_EXTS="txt m3u pls jpg jpeg gif nfo srt sub torrent zip rar cbz cbr part" | |
| if [[ "$1" =~ ^- && "$1" != "--help" ]] ;then | |
| SORT_ARG="$1" | |
| if [[ "$1" = "--cat" ]] ; then | |
| SORT() { tr '\0' '\n' ; } | |
| elif [[ "$1" = "-t" || "$1" = "-rt" || "$1" = "-tr" ]] ; then | |
| SORT() { xargs -0 ls "$SORT_ARG" ; } | |
| else | |
| SORT() { sort "$SORT_ARG" -z | tr '\0' '\n' ; } | |
| fi | |
| shift | |
| fi | |
| # Ensures correct handling of paths with spaces and makes playlist independent | |
| # of $PWD... This is ugly, patches accepted :p | |
| hit_dashdash=0 | |
| for arg in "$@" ; do | |
| if [[ $hit_dashdash -eq 0 && "$arg" =~ ^- ]] ;then | |
| if [[ "$arg" = "--" ]] ; then | |
| hit_dashdash=1 | |
| elif [[ "$arg" =~ ^--?(\?|help)?$ ]] ;then | |
| echo -e "Usage: | |
| `basename $0` [sort argument | --cat] [--filter=FILTER] [mpv_args | paths] [--] [paths]" >&2 | |
| exit 1 | |
| elif [[ "$arg" =~ ^--filter= ]] ;then | |
| filter+=" -a ( ${arg#--filter=} )" | |
| else | |
| ARGS+=("$arg") | |
| fi | |
| else | |
| PATHS+=("`readlink -f -- \"$arg\"`") | |
| fi | |
| done | |
| if [[ ${#PATHS[@]} -eq 0 ]] ;then | |
| PATHS+=("$PWD") | |
| fi | |
| blacklist=(`for ext in $DENIED_EXTS ; do echo -a '!' -name "*.$ext" ;done`) | |
| set -x | |
| exec mpv "${ARGS[@]}" --playlist=<( find "${PATHS[@]}" $filter "${blacklist[@]}" -print0 | SORT ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment