aboutsummaryrefslogtreecommitdiff
path: root/local/bin/tag-music
blob: 826a83a24666eaa4024fd157070f6e1ee9af5a8e (plain)
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
#!/bin/sh

music_dir="$HOME/Music"

for artist_dir in "$music_dir"/*
do
    [ ! -d "$artist_dir" ] && continue
    artist="$(basename "$artist_dir")"
    [ "$artist" = backup ] && continue

    for album_dir in "$artist_dir"/*
    do
        album="$(basename "$album_dir")"
        [ ! -d "$album_dir" ] && continue

        for song_file in "$album_dir"/*
        do
            [ ! -f "$song_file" ] && continue
            song="$(basename "$song_file" | rev | cut -d '.' -f 2- | rev)"
            # echo $song_file
            track=0
            if expr "$song" : "[0-9][0-9]*\-.*" > /dev/null
            then
                track="$(echo "$song" | cut -d '-' -f 1)"
                song="$(echo "$song" | cut -d '-' -f 2-)"
            fi
            # echo $track $song
            # echo $song_file
            taffy --artist "$artist" --album "$album" --title "$song" --track "$track" "$song_file"
        done
    done
done