vid: Limit to 100 videos if stdin = tty.

This commit is contained in:
Ole Tange 2024-08-06 01:36:02 +02:00
parent b97d025ee7
commit f0dd01f79a
2 changed files with 45 additions and 7 deletions

View file

@ -27,7 +27,7 @@ Go to next revision
=head1 AUTHOR =head1 AUTHOR
Copyright (C) 2017 Ole Tange, Copyright (C) 2017-2024 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc. http://ole.tange.dk and Free Software Foundation, Inc.
@ -51,7 +51,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 DEPENDENCIES =head1 DEPENDENCIES
B<gitnext> uses B<git>. B<gitnext> uses B<git> and B<field>.
=head1 SEE ALSO =head1 SEE ALSO

48
vid/vid
View file

@ -5,7 +5,7 @@
=head1 NAME =head1 NAME
vid - Play videos matching strings in descending order of size vid - Play videos matching strings
=head1 SYNOPSIS =head1 SYNOPSIS
@ -23,17 +23,49 @@ There can be multiple B<grep> expressions.
The searching is cached in B<.vidlist> in a parent dir or in the The searching is cached in B<.vidlist> in a parent dir or in the
current dir if no parents contain B<.vidlist>. current dir if no parents contain B<.vidlist>.
If stdin (standard input) is a tty: Match videos from B<.vidlist>
ordered by decreasing size.
If stdin (standard input) is not a tty: Match videos from standard
input.
If stdout (standard output) is a tty: Play 100 randomly chosen of the
matching videos.
If stdout (standard output) is not a tty: List all matching videos.
Videos in the dir B<.waste> are ignored.
=head1 EXAMPLE =head1 EXAMPLE
Play videos matching B<Documentary> but not B<BBC>: Play 100 videos in random order matching B<Documentary> but not B<BBC>:
vid Documentary -v BBC vid Documentary -v BBC
List all videos matching B<Documentary> but not B<BBC> ordered by
decreasing size:
vid Documentary -v BBC | cat
Play all videos ending in B<.mp4>:
ls *.mp4 | vid
=head1 ENVIRONMENT VARIABLES
=over 9
=item $VIDEOPLAYER
Use this as video player. Default: vlc
=back
=head1 AUTHOR =head1 AUTHOR
Copyright (C) 2018-2019 Ole Tange, Copyright (C) 2018-2024 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc. http://ole.tange.dk and Free Software Foundation, Inc.
@ -118,6 +150,7 @@ cat_list() {
full_path_vidlist_dir="$(dirname $(readlink -f "$vidlist") )" full_path_vidlist_dir="$(dirname $(readlink -f "$vidlist") )"
full_path_thisdir="$(readlink -f .)" full_path_thisdir="$(readlink -f .)"
if [ -f "$vidlist" ] ; then if [ -f "$vidlist" ] ; then
# vidlist exists: Do the update in the background
# find background (>/dev/null to detach from tty) # find background (>/dev/null to detach from tty)
update_list "$vidlist" "$full_path_vidlist_dir" >/dev/null & update_list "$vidlist" "$full_path_vidlist_dir" >/dev/null &
else else
@ -128,7 +161,7 @@ cat_list() {
perl -pe 's|\Q'"$full_path_vidlist_dir"'\E|.|')/" perl -pe 's|\Q'"$full_path_vidlist_dir"'\E|.|')/"
# cat "$vidlist" | grep matching this dir + remove dirs # cat "$vidlist" | grep matching this dir + remove dirs
# echo "$vidlist" "$full_path_thisdir" "$full_path_vidlist_dir" = "$subdir" >&2 # echo "$vidlist" "$full_path_thisdir" "$full_path_vidlist_dir" = "$subdir" >&2
cat "$vidlist" | grep -v '/.waste/' "$vidlist" |
perl -ne 's|^(\./)?\Q'"$subdir"'\E|| and print' perl -ne 's|^(\./)?\Q'"$subdir"'\E|| and print'
} }
@ -147,7 +180,12 @@ stdout() {
# STDOUT = terminal # STDOUT = terminal
# start $VIDEOPLAYER # start $VIDEOPLAYER
VIDEOPLAYER=${VIDEOPLAYER:-vlc --} VIDEOPLAYER=${VIDEOPLAYER:-vlc --}
shuf | parallel --halt now,done=1 --lb -n100 -Xj1 $VIDEOPLAYER if tty -s ; then
# STDIN is terminal => limit to 100
shuf | parallel --halt now,done=1 --lb -n100 -Xj1 $VIDEOPLAYER
else
parallel --halt now,done=1 --lb -Xj1 $VIDEOPLAYER
fi
else else
cat cat
fi fi