Created
July 10, 2018 21:16
-
-
Save dlight/34a0ffa9ddd37582dc823a8ac98cb700 to your computer and use it in GitHub Desktop.
the command name is actually ,
This file contains 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/sh | |
#export DRI_PRIME=1 | |
cmd=mpv | |
param='-fs --msg-level=all=no,cplayer=info' | |
filter='/Playing/!d; s/^Playing: //' | |
order='%C@' # by default, order by ctime | |
sort=-n # (which is a numeric sort) | |
reverse=-r # ... show newer videos first | |
depth= # ... and do it recursively | |
loop= # ... without looping | |
[[ -n $MYT_MUTE ]] && set -- -u "$@" | |
[[ -n $MYT_1 ]] && set -- -1 "$@" | |
[[ -n $MYT_REC ]] && set -- -r "$@" | |
while getopts 1rcmsaRnolugh o; do | |
case "$o" in | |
1) depth='-maxdepth 1';; # just the current directory | |
r) depth=;; # recursively | |
# a video uploaded in 2009 but downloaded in 2015 will have | |
# mtime in 2009 and ctime in 2015 | |
# | |
# (note: moving the video to another directory actually bumps | |
# the ctime) | |
c) order='%C@'; sort=-n;; # order by ctime (download time) | |
m) order='%T@'; sort=-n;; # order by mtime (upload time) | |
s) order='%s'; sort=-n;; # order by size | |
a) order='alpha'; sort=;; # order lexicographically | |
R) order='random'; sort=-n;; # order at random | |
n) reverse=-r;; # newer first | |
o) reverse=;; # older first | |
l) loop=--loop=inf;; # infinite loop | |
u) mute=--mute=yes;; # no sound | |
g) filter=; param=;; # debug | |
h) ${PAGER-less} "$0"; exit;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
find -L "$@" $depth -mindepth 0 \ | |
-not -path '*/\.*' \ | |
-type f \ | |
-name '*.*' \ | |
-printf "$order %p\0" \ | |
| awk 'BEGIN { RS="\0"; srand() } { | |
if ($1 == "random") | |
sub ($1, int(rand()*100000)); | |
printf "%s\0", $0 | |
}' \ | |
| sort -z $sort $reverse \ | |
| sed -zr 's/^[^ ]+ //' \ | |
| xargs -0 $cmd $loop $mute $param 2>&1 \ | |
| sed "$filter" | |
# -exec $cmd {} + | sed "$sed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment