In my .bashrc I have a function which I use to play random videos (not written below, just fyi), and another one for all media files, e.g.:
createmediafiles() {
find ~+ -type f -iregex '.*\.\(mp3\|wav\|ogg\|flac\|mp4\|mov\|avi\)' > ~/mediafiles.txt
find ~+ -type d -name VIDEO_TS >> ~+/mediafiles.txt
}
playmediafiles() {
while true; do
while read -r line; do
shuf -n 1 |
tee -a ~/played-log.txt |
xargs -d "\n" mpv
done < ~/mediafiles.txt
done
}
I want to add the VIDEO_TS line to createmediafiles
, but in the playmediafiles
function I want to add an IF statement, such that if the line shuffled to in mediafiles.txt
is a VIDEO_TS then rather than using mpv to play a file, it will do:
tee -a ~/played-log.txt | xargs -d "\n" vlc --fullscreen
Piping in mediafiles.txt
read the same way as it does with mpv.
How do I throw that in an IF statement with the condition being that the line ends in VIDEO_TS?
playmediafiles
is trying to generate a randomised/shuffled list of items to play. Which it sort of does but desperately inefficiently – Chris Davies Mar 26 '24 at 11:17~+
? Is it a typo or a construct I've just never seen before? – Chris Davies Mar 26 '24 at 11:24$PWD
, and~-
is$OLDPWD
. I believe it's not standard (it can also be used with a digit to access the other elements of the directory stack in both bash and zsh). – Kusalananda Mar 26 '24 at 11:36"$PWD"
or.
depending on whether the full path is needed or not, just to avoid confusing readers, it this was my script. – Kusalananda Mar 26 '24 at 11:43~/
since that's what the OP uses everywhere else, including to access that file later. – Ed Morton Mar 26 '24 at 11:45createmediafiles
function was always run from the user's home directory, but it would probably be creating mayhem (or at least unwanted files) if it wasn't. – Kusalananda Mar 26 '24 at 11:48