Debian Codegraph @

fvwm/scripts/make_all_playlists

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