-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript_playlist_make.sh
More file actions
executable file
·72 lines (64 loc) · 1.52 KB
/
script_playlist_make.sh
File metadata and controls
executable file
·72 lines (64 loc) · 1.52 KB
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
#!/bin/bash
# Script to create a playlist from a directory containing songs and
# converting, if found, flac files to ogg for easier use on music players
# Directory where to put ogg from flac files
DIR='/media/private/canzoni_cellulare/'
function usage ()
{
echo "Usage:"
echo "script_playlist_make.sh DIRECTORY"
echo "-f convert flacs to ogg"
echo "-h for this help"
}
function flactogg ()
{
if [ -z "$1" ]; then
echo "You should tell me the desired directory...."
usage
exit 1
fi
ORIG_DIR="${1}"
NEW_DIR="${DIR}$(basename ${1})"
if [ ! -d "$NEW_DIR" ]; then
mkdir "${NEW_DIR}"
fi
cd "${NEW_DIR}"
# convert each flac files from the original directory to this one
# under $DIR
for f in "${ORIG_DIR}"*.[fF][lL][aA][cC] ; do
oggfile=$(basename "${f%%flac}"ogg)
oggenc -q 2 -o "${oggfile}" "${f}" ;
done
# make the playlist
ls *.ogg > $(basename $PWD).m3u
}
function playlister ()
{
# changedir into the first parameter and generate a m3u playlist
# named after the parent directory (which should be the name of the
# album)
PLAYLIST="$(basename $1)".m3u
if [ -z "$1" ]; then
echo "You should tell me the desired directory...."
usage
exit 1
fi
cd "${1}"
ls *.[MmOo][pPgG][3gG] > $PLAYLIST
# Check if the playlist is empty (meaning that aren't any songs in
# it). If it is, remove it
if [ ! -s "$PLAYLIST" ]; then
echo ""
echo "Perhaps are you trying to make a playlist from flac files?"
rm "$PLAYLIST"
fi
}
case "${1}" in
-h) usage
;;
-f) flactogg "${2}"
;;
*) playlister "${1}"
;;
esac
exit 0