forked from RandomNinjaAtk/arr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeetsTagger.bash
More file actions
127 lines (107 loc) · 3.7 KB
/
Copy pathBeetsTagger.bash
File metadata and controls
127 lines (107 loc) · 3.7 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
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
#!/usr/bin/env bash
scriptVersion="1.8"
scriptName="BeetsTagger"
#### Import Settings
source /config/extended.conf
#### Import Functions
source /config/extended/functions
#### Create Log File
logfileSetup
SECONDS=0
if [ "$lidarr_eventtype" == "Test" ]; then
log "Tested Successfully"
exit 0
fi
getArrAppInfo
verifyApiAccess
if [ -z "$lidarr_album_id" ]; then
lidarr_album_id="$1"
fi
if [ "$enableBeetsTagging" != "true" ]; then
log "Beets tagging is disabled, please enable by setting \"enableBeetsTagging=true\" in \"/config/extended.conf\""
exit 0
fi
getAlbumArtist="$(curl -s "$arrUrl/api/v1/album/$lidarr_album_id" -H "X-Api-Key: ${arrApiKey}" | jq -r .artist.artistName)"
getAlbumArtistPath="$(curl -s "$arrUrl/api/v1/album/$lidarr_album_id" -H "X-Api-Key: ${arrApiKey}" | jq -r .artist.path)"
getTrackPath="$(curl -s "$arrUrl/api/v1/trackFile?albumId=$lidarr_album_id" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].path | head -n1)"
getFolderPath="$(dirname "$getTrackPath")"
getAlbumFolderName="$(basename "$getFolderPath")"
log "Processing :: $getAlbumFolderName :: Processing Files..."
if echo "$getFolderPath" | grep "$getAlbumArtistPath" | read; then
if [ ! -d "$getFolderPath" ]; then
log "ERROR :: \"$getFolderPath\" Folder is missing :: Exiting..."
fi
else
log "ERROR :: $getAlbumArtistPath not found within \"$getFolderPath\" :: Exiting..."
exit
fi
ProcessWithBeets () {
log "$1 :: Start Processing..."
if find "$1" -type f -iname "*.flac" | read; then
sleep 0.01
else
log "$1 :: ERROR :: Only supports flac files, exiting..."
return
fi
SECONDS=0
# Input
# $1 Download Folder to process
if [ -f /config/extended/library-lidarr.blb ]; then
rm /config/extended/library-lidarr.blb
sleep 0.5
fi
if [ -f /config/extended/extended/beets-lidarr.log ]; then
rm /config/extended/extended/beets-lidarr.log
sleep 0.5
fi
if [ -f "/config/extended/beets-lidarr-match" ]; then
rm "/config/extended/beets-lidarr-match"
sleep 0.5
fi
touch "/config/extended/beets-lidarr-match"
sleep 0.5
log "$1 :: Begin matching with beets!"
beet -c /config/extended/beets-config-lidarr.yaml -l /config/extended/library-lidarr.blb -d "$1" import -qC "$1" 2>&1 | tee -a "/config/logs/$logFileName"
# Fix tags
log "$1 :: Fixing Tags..."
# Fix flac tags
fixed=0
find "$1" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' file; do
if [ $fixed == 0 ]; then
fixed=$(( $fixed + 1 ))
log "$1 :: Fixing Flac Tags..."
fi
getArtistCredit="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".format.tags.ARTIST_CREDIT" | sed "s/null//g" | sed "/^$/d")"
metaflac --remove-tag=ARTIST "$file"
metaflac --remove-tag=ALBUMARTIST "$file"
metaflac --remove-tag=ALBUMARTIST_CREDIT "$file"
metaflac --remove-tag=ALBUMARTISTSORT "$file"
metaflac --remove-tag=ALBUM_ARTIST "$file"
metaflac --remove-tag="ALBUM ARTIST" "$file"
metaflac --remove-tag=ARTISTSORT "$file"
metaflac --remove-tag=COMPOSERSORT "$file"
metaflac --set-tag=ALBUMARTIST="$getAlbumArtist" "$file"
if [ ! -z "$getArtistCredit" ]; then
metaflac --set-tag=ARTIST="$getArtistCredit" "$file"
else
metaflac --set-tag=ARTIST="$getAlbumArtist" "$file"
fi
done
log "$1 :: Fixing Tags Complete!"
if [ -f "/config/extended/beets-lidarr-match" ]; then
rm "/config/extended/beets-lidarr-match"
sleep 0.5
fi
if [ -f /config/extended/library-lidarr.blb ]; then
rm /config/extended/library-lidarr.blb
sleep 0.5
fi
if [ -f /config/extended/logs/beets.log ]; then
rm /config/extended/logs/beets.log
sleep 0.5
fi
duration=$SECONDS
log "$1 :: Finished in $(($duration / 60 )) minutes and $(($duration % 60 )) seconds!"
}
ProcessWithBeets "$getFolderPath"
exit