summaryrefslogtreecommitdiffstats
path: root/clerk_updater
blob: 4ac32614c6e2eeea26f1749a4910c73d001e75bf (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
33
#!/bin/bash

# create cached album list
source $HOME/.config/clerk/config

new_db="$(mpc stats | grep Updated | sed 's/ //g')"
if [[ "$change_db" == "$new_db" ]]; then
    if [[ -f $HOME/.config/clerk/album.cache && -f $HOME/.config/clerk/tracks.cache && -f $HOME/.config/clerk/last.cache ]]; then
        :
    else
        notify-send "clerk" "Creating caches"
        album_temp_cur=$(mppc listall --format "{$mpd_artist} $seperator {album} $seperator {date}" | sort | uniq &)
        tracks_temp_cur=$(mppc listall --format "{artist} $seperator {track} $seperator {title} $seperator {album}" &)
        last_temp_cur=$(export seperator="$seperator"; mppc listall --format "{last-modified}$seperator{date}$seperator{$mpd_artist}$seperator{album}" | sort -r | awk -F "$seperator" '{ print $2,ENVIRON["seperator"],$3,ENVIRON["seperator"],$4 }' | awk '!x[$0]++' &)
        echo "$album_temp_cur" > $HOME/.config/clerk/album.cache
        echo "$tracks_temp_cur" > $HOME/.config/clerk/tracks.cache
        echo "$last_temp_cur" > $HOME/.config/clerk/last.cache
    fi
else
    notify-send "clerk" "Updating caches"
    sed -i "s/change_db=".*"/change_db=""$new_db""/" $HOME/.config/clerk/config
    album_temp_cur=$(mppc listall --format "{$mpd_artist} $seperator {album} $seperator {date}" | sort | uniq &)
    tracks_temp_cur=$(mppc listall --format "{artist} $seperator {track} $seperator {title} $seperator {album}" &)
    last_temp_cur=$(export seperator="$seperator"; mppc listall --format "{last-modified}$seperator{date}$seperator{$mpd_artist}$seperator{album}" | sort -r | awk -F "$seperator" '{ print $2,ENVIRON["seperator"],$3,ENVIRON["seperator"],$4 }' | awk '!x[$0]++' &)
    rm -f $HOME/.config/clerk/album_cache
    rm -f $HOME/.config/clerk/tracks.cache
    rm -f $HOME/.config/clerk/last.cache
    echo "$album_temp_cur" > $HOME/.config/clerk/album.cache
    echo "$tracks_temp_cur" > $HOME/.config/clerk/tracks.cache
    echo "$last_temp_cur" > $HOME/.config/clerk/last.cache

fi