1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
#!/bin/bash
# Wrapper for make_playlist into Fvwm-Crystal
# Dominique Michel <dominique_libre@users.sourceforge.net> 2008-2013
#
# This script scan each directories and subdirectories for media file
# and write the corresponding playlist files.
#
# Where the playlists are created. Must be writable by the user.
# AudioPlaylists="/home/$(id -un)/PlaylistsAudio"
# VideoPlaylists="/home/$(id -un)/PlaylistsVideo"
# Temporary files, must be into a writable directory.
#
# Syntax:
# PipeRead $[FVWM_SYSTEMDIR]/scripts/make_all_playlists \
# $[infostore.AudioPlaylists] $[infostore.VideoPlaylists]
DirList="/tmp/mkpl_dirlist"
MediaList="/tmp/mkpl_medialist"
# Create the playlists dir if it doesn't exist
writedir() {
if [[ ! -e "$1" ]]; then
mkdir -p "$1"
echo "Creating $1"
fi
}
mediatype() {
case "$1" in
audio)
writedir ${AudioPlaylists}
;;
video)
writedir ${VideoPlaylists}
;;
cdrom)
echo "This is a CDROM, skipping it."
;;
dvd)
echo "This is a DVD, skipping it."
;;
*)
echo "$1 is not a valid media type for ${FVWM_USERDIR}/preferences/MediaDirectories."
echo "Please adjust your setting."
;;
esac
}
# scan for dir and subdir
scandir() {
find -type d |sort| sed -e 's\.\\' >${DirList}
echo "Scanning $1 for subdirectories."
}
# scan for audio files
# added ac3,
scanaudiomedia() {
find -maxdepth 1 -regex ".*.[aA][cC][3]\|.*.[aA][pP][eE]\|.*.[fF][lL][aA][cC]\|.*.[mM][pP][3]\|.*.[mM][pP][cC]\|.*.[nN][rR][gG]\|.*.[oO][gG][gG]\|.*.[tT][sS]\|.*.[tT][tT][aA]\|.*.[wW][aA][vV]\|.*.[wW][mM][aA]\|.*.[wW][vV]"|sort
}
# scan for video files
# added flv, ts
scanvideomedia() {
find -maxdepth 1 -regex ".*.[aA][sS][fF]\|.*.[aA][vV][iI]\|.*.[dD][iI][vV][xX]\|.*.[fF][lL][vV]\|.*.[iI][mM][gG]\|.*.[mM][2][tT]\|.*.[mM][kK][vV]\|.*.[mM][oO][vV]\|.*.[mM][pP][4]\|.*.[mM][pP][eE][gG]\|.*.[mM][pP][gG]\|.*.[nN][rR][gG]\|.*.[oO][gG][mM]\|.*.[rR][aA][mM]\|.*.[rR][mM]\|.*.[rR][mM][vV][bB]\|.*.[tT][sS]\|.*.[vV][oO][bB]\|.*.[wW][mM][vV]"|sort
}
# write the audio files into the playlist
writeaudio() {
if [[ `scanaudiomedia` != "" ]]; then
scanaudiomedia| sed -e 's\.\\' > ${MediaList}
## Create the playlist, overwrite the file if it exist
# variable with the first character of the sub-path
subdir="${AudioPlaylists}/`pwd| sed -e "s,$1,,"| sed -e 's,/,,'|sed -e 's,/,_,g'|sed -e 's,\(.\).*,\1,'`"
# Check for main path. Needed because mplayer need a name before ".m3u". And also for this script when multiple calls.
# We also filter out some non wanted characters from the playlist names.
if [[ "$1" == `pwd` ]]; then
echo -n "" >> "${AudioPlaylists}/`echo \"$1\"| sed -e 's,/,,'| sed -e \"s,',_,g\"| sed -e 's,[/"\*\^?\$],_,g'`.m3u"
else
# make sub-dirs
mkdir -p ${subdir}
echo -n "" >> "${subdir}/`pwd| sed -e \"s,$1,,\"| sed -e 's,/,,'| sed -e \"s,',_,g\"|sed -e 's,[/"\*\^?\$],_,g'`".m3u
fi
# Append the audio files into the playlist
while read line; do
if [[ "$1" == `pwd` ]]; then
echo "$(pwd)${line}" >> "${AudioPlaylists}/`echo \"$1\"| sed -e 's,/,,'| sed -e \"s,',_,g\"| sed -e 's,[/"\*\^?\$],_,g'`.m3u"
else
echo "$(pwd)${line}" >> "${subdir}/`pwd| sed -e \"s,$1,,\"|sed -e 's,/,,'| sed -e \"s,',_,g\"| sed -e 's,[/"\*\^?\$],_,g'`".m3u
fi
done <${MediaList}
rm ${MediaList}
fi
}
# write the video files into the playlist
writevideo() {
if [[ `scanvideomedia` != "" ]]; then
scanvideomedia| sed -e 's\.\\' > ${MediaList}
# Create the playlist, overwrite the file if it exist
if [[ "$1" == `pwd` ]]; then
echo -n "" >> "${VideoPlaylists}/`echo \"$1\"| sed -e 's,/,,'| sed -e \"s,',_,g\"| sed -e 's,[/"\*\^?\$],_,g'`.m3u"
else
echo -n "" >> "${VideoPlaylists}/`pwd| sed -e \"s,$1,,\"| sed -e 's,/,,'| sed -e \"s,',_,g\"| sed -e 's,[/"\*\^?\$],_,g'`".m3u
fi
# Append the video files into the playlist
while read line; do
if [[ "$1" == `pwd` ]]; then
echo "$(pwd)${line}" >> "${VideoPlaylists}/`echo \"$1\"| sed -e 's,/,,'| sed -e \"s,',_,g\"| sed -e 's,[/"\*\^?\$],_,g'`.m3u"
else
echo "$(pwd)${line}" >> "${VideoPlaylists}/`pwd| sed -e \"s,$1,,\"| sed -e 's,/,,'| sed -e \"s,',_,g\"| sed -e 's,[/"\*\^?\$],_,g'`".m3u
fi
done <${MediaList}
rm ${MediaList}
fi
}
# write the m3u files
writem3u() {
echo -n "Writing the $1 playlists for $2 "
p=0
while read line; do
if [[ "$p" == 4 ]]; then
p=0
fi
if [[ "$p" == 0 ]]; then
echo -en "\b|"
fi
if [[ "$p" == 1 ]]; then
echo -en "\b/"
fi
if [[ "$p" == 2 ]]; then
echo -en "\b-"
fi
if [[ "$p" == 3 ]]; then
echo -en "\b\\"
fi
let "p += 1"
basedir=$(pwd)
# echo "${line}"
cd "${basedir}${line}"
case "$1" in
audio)
writeaudio "$2"
;;
video)
writevideo "$2"
;;
*)
echo "something wrong"
exit 67
;;
esac
cd "${basedir}"
done <${DirList}
rm ${DirList}
echo -en "\b\b...\n"
echo "Done."
}
usage() {
echo ""
echo "Usage:"
echo " `basename $0` <>audio_playlist_path> <video_playlists_path>"
echo ""
echo "Copyright: This software, `basename $0`, is copyrighted software that is licensed under the GPLv3 or later."
exit 65
}
# Do something now
make_playlist() {
mediatype "$3"
if [[ -d "$4" ]]; then
cd "$4"
case "$3" in
audio)
scandir "$4"
writem3u "$3" "$4"
;;
video)
scandir "$4"
writem3u "$3" "$4"
;;
cdrom)
echo "Nothing to do."
;;
dvd)
echo "Nothing to do."
;;
*)
echo "$1 is not a valid media type for ${FVWM_USERDIR}/preferences/MediaDirectories."
echo "Please adjust your setting."
;;
esac
else
echo "$4 is not a directory"
fi
}
# The main program
if [[ $# -ne 4 ]]
then
usage
else
echo "Deleting the old audio play-lists in $1"
rm -fr "$1"/*
echo "Deleting the old video play-lists in $2"
rm -f "$2"/*
echo "Making the user playlist directories when needed."
mkdir -p "$3"
mkdir -p "$4"
echo "Done."
AudioPlaylists="$1"
VideoPlaylists="$2"
while read line; do
make_playlist "$1" "$2" ${line}
done <"${FVWM_USERDIR}"/preferences/MediaDirectories
fi
|