@ -1,8 +1,6 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bash
lidarrApiKey = " $( grep "<ApiKey>" /config/config.xml | sed "s/\ <ApiKey>//;s/<\/ApiKey>//" ) "
lidarrApiKey = " $( grep "<ApiKey>" /config/config.xml | sed "s/\ <ApiKey>//;s/<\/ApiKey>//" ) "
lidarrUrl = "http://127.0.0.1:8686"
lidarrUrl = "http://127.0.0.1:8686"
XDG_CONFIG_HOME = "/config/deemix/xdg"
export XDG_CONFIG_HOME = "/config/deemix/xdg"
CountryCode = US
CountryCode = US
log ( ) {
log ( ) {
@ -10,9 +8,53 @@ log () {
echo $m_time " " $1
echo $m_time " " $1
}
}
mkdir -p /config/xdg
touch /config/xdg.tidal-dl.log
if [ ! -f /config/xdg/.tidal-dl.json ] ; then
log "TIDAL :: No default config found, importing default config \"tidal.json\""
if [ -f /scripts/tidal-dl.json ] ; then
cp /scripts/tidal-dl.json /config/xdg/.tidal-dl.json
chmod 777 -R /config/xdg/
fi
tidal-dl -o /downloads/lidarr/incomplete
tidal-dl -r P1080
tidal-dl -q HiFi
fi
# check for backup token and use it if exists
if [ ! -f /root/.tidal-dl.token.json ] ; then
if [ -f /config/backup/tidal-dl.token.json ] ; then
cp -p /config/backup/tidal-dl.token.json /root/.tidal-dl.token.json
# remove backup token
rm /config/backup/tidal-dl.token.json
fi
fi
if [ -f /root/.tidal-dl.token.json ] ; then
if [ [ $( find "/config/xdg/.tidal-dl.token.json" -mtime +6 -print) ] ] ; then
log "TIDAL :: ERROR :: Token expired, removing..."
rm /config/xdg/.tidal-dl.token.json
else
# create backup of token to allow for container updates
if [ ! -d /config/backup ] ; then
mkdir -p /config/backup
fi
cp -p /config/xdg/.tidal-dl.token.json /config/backup/tidal-dl.token.json
fi
fi
if [ ! -f /config/xdg/.tidal-dl.token.json ] ; then
log "TIDAL :: ERROR :: Loading client for required authentication, please authenticate, then exit the client..."
tidal-dl
fi
DownloadProcess ( ) {
DownloadProcess ( ) {
downloadedAlbumTitleClean = " $( echo " $downloadedAlbumTitle " | sed -e "s%[^[:alpha:][:digit:]._' ]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' ) "
downloadedAlbumTitleClean = " $( echo " $downloadedAlbumTitle " | sed -e "s%[^[:alpha:][:digit:]._' ]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' ) "
if [ ! -d "/downloads/lidarr" ] ; then
if [ ! -d "/downloads/lidarr" ] ; then
mkdir -p /downloads/lidarr
mkdir -p /downloads/lidarr
chmod 777 /downloads/lidarr
chmod 777 /downloads/lidarr
@ -24,34 +66,50 @@ DownloadProcess () {
chown abc:abc /downloads/lidarr/incomplete
chown abc:abc /downloads/lidarr/incomplete
fi
fi
if [ " $2 " = "DEEZER" ] ; then
deemix -b flac -p /downloads/lidarr/incomplete " https://www.deezer.com/us/album/ $1 "
if [ ! -d "/config/logs" ] ; then
if [ ! -d "/config/logs" ] ; then
mkdir -p /config/logs
mkdir -p /config/logs
chmod 777 /config/logs
chmod 777 /config/logs
chown abc:abc /config/logs
chown abc:abc /config/logs
fi
fi
if [ ! -d "/config/logs/downloaded" ] ; then
if [ ! -d "/config/logs/downloaded" ] ; then
mkdir -p /config/logs/downloaded
mkdir -p /config/logs/downloaded
chmod 777 /config/logs/downloaded
chmod 777 /config/logs/downloaded
chown abc:abc /config/logs/downloaded
chown abc:abc /config/logs/downloaded
fi
fi
if [ ! -d "/config/logs/downloaded/deezer" ] ; then
if [ ! -d "/config/logs/downloaded/deezer" ] ; then
mkdir -p /config/logs/downloaded/deezer
mkdir -p /config/logs/downloaded/deezer
chmod 777 /config/logs/downloaded/deezer
chmod 777 /config/logs/downloaded/deezer
chown abc:abc /config/logs/downloaded/deezer
chown abc:abc /config/logs/downloaded/deezer
fi
fi
if [ ! -d "/config/logs/downloaded/tidal" ] ; then
mkdir -p /config/logs/downloaded/tidal
chmod 777 /config/logs/downloaded/tidal
chown abc:abc /config/logs/downloaded/tidal
fi
if [ " $2 " = "DEEZER" ] ; then
deemix -b flac -p /downloads/lidarr/incomplete " https://www.deezer.com/us/album/ $1 "
touch /config/logs/downloaded/deezer/$1
touch /config/logs/downloaded/deezer/$1
downloadCount = $( find /downloads/lidarr/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
downloadCount = $( find /downloads/lidarr/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ $downloadCount -le 0 ] ; then
if [ $downloadCount -le 0 ] ; then
echo "download failed"
echo "download failed"
return
return
fi
fi
elif [ " $2 " = "TIDAL" ] ; then
tidal-dl -l " https://tidal.com/browse/album/ $1 "
touch /config/logs/downloaded/tidal/$1
downloadCount = $( find /downloads/lidarr/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ $downloadCount -le 0 ] ; then
echo "download failed"
return
fi
else
else
return
return
fi
fi
albumquality = " $( find /downloads/lidarr/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n 1 | egrep -i -E -o " \.{1}\w* $" | sed 's/\.//g' ) "
albumquality = " $( find /downloads/lidarr/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n 1 | egrep -i -E -o " \.{1}\w* $" | sed 's/\.//g' ) "
downloadedAlbumFolder = " $lidarrArtistNameSanitized - $downloadedAlbumTitleClean ( $3 )- ${ albumquality ^^ } - $2 "
downloadedAlbumFolder = " $lidarrArtistNameSanitized - $downloadedAlbumTitleClean ( $3 )- ${ albumquality ^^ } - $2 "
@ -91,12 +149,12 @@ NotifyLidarrForImport () {
if [ ! -z " $arlToken " ] ; then
if [ ! -z " $arlToken " ] ; then
# Create directories
# Create directories
mkdir -p /config/{ cache,logs,deemix/xdg/deemix }
mkdir -p /config/{ cache,logs}
if [ -f " $XDG_CONFIG_HOME /deemix/.arl " ] ; then
if [ -f " /config/xdg/deemix/.arl " ] ; then
rm " $XDG_CONFIG_HOME /deemix/.arl "
rm " /config/xdg/deemix/.arl "
fi
fi
if [ ! -f " $XDG_CONFIG_HOME /deemix/.arl " ] ; then
if [ ! -f " /config/xdg/deemix/.arl " ] ; then
echo -n " $arlToken " > " $XDG_CONFIG_HOME /deemix/.arl "
echo -n " $arlToken " > " /config/xdg/deemix/.arl "
fi
fi
log "ARL Token: Configured"
log "ARL Token: Configured"
else
else
@ -210,6 +268,9 @@ SearchProcess () {
fi
fi
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
echo "Tidal Explicit MATCH"
echo "Tidal Explicit MATCH"
if [ -f /config/logs/downloaded/tidal/$tidalArtistAlbumId ] ; then
continue
fi
DownloadProcess " $tidalArtistAlbumId " "TIDAL" " $downloadedReleaseYear "
DownloadProcess " $tidalArtistAlbumId " "TIDAL" " $downloadedReleaseYear "
fi
fi
done
done
@ -257,6 +318,9 @@ SearchProcess () {
fi
fi
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
echo "CLEAN Tidal MATCH"
echo "CLEAN Tidal MATCH"
if [ -f /config/logs/downloaded/tidal/$tidalArtistAlbumId ] ; then
continue
fi
DownloadProcess " $tidalArtistAlbumId " "TIDAL" " $downloadedReleaseYear "
DownloadProcess " $tidalArtistAlbumId " "TIDAL" " $downloadedReleaseYear "
fi
fi
done
done
@ -309,7 +373,7 @@ ProcessWithBeets () {
rm -rf " $1 "
rm -rf " $1 "
return
return
else
else
log ": BEETS MATCH FOUND!"
log ": : BEETS MATCH FOUND!"
fi
fi
GetFile = $( find " $1 " -type f -iname "*.flac" | head -n1)
GetFile = $( find " $1 " -type f -iname "*.flac" | head -n1)
@ -324,6 +388,19 @@ ProcessWithBeets () {
matchedLidarrAlbumArtistId = " $( echo " $matchedLidarrAlbumData " | jq -r ".artist.foreignArtistId" ) "
matchedLidarrAlbumArtistId = " $( echo " $matchedLidarrAlbumData " | jq -r ".artist.foreignArtistId" ) "
matchedLidarrAlbumArtistName = " $( echo " $matchedLidarrAlbumData " | jq -r ".artist.artistName" ) "
matchedLidarrAlbumArtistName = " $( echo " $matchedLidarrAlbumData " | jq -r ".artist.artistName" ) "
matchedLidarrAlbumArtistCleanName = " $( echo " $matchedLidarrAlbumData " | jq -r ".artist.cleanName" ) "
matchedLidarrAlbumArtistCleanName = " $( echo " $matchedLidarrAlbumData " | jq -r ".artist.cleanName" ) "
lidarrAlbumData = $( curl -s --header "X-Api-Key:" ${ lidarrApiKey } --request GET " $lidarrUrl /api/v1/album/ " | jq -r ".[]" )
lidarrPercentOfTracks = $( echo " $lidarrAlbumData " | jq -r " select(.foreignAlbumId==\" $matchedTagsAlbumReleaseGroupId \") | .statistics.percentOfTracks " )
if [ " $lidarrPercentOfTracks " = "null" ] ; then
lidarrPercentOfTracks = 0
fi
if [ $lidarrPercentOfTracks -gt 0 ] ; then
log ":: ERROR :: Already Imported"
rm -rf " $1 "
return
fi
if [ " ${ matchedLidarrAlbumArtistCleanName } " != "null" ] ; then
if [ " ${ matchedLidarrAlbumArtistCleanName } " != "null" ] ; then
log " $position :: $idNumber of $idListCount :: $tidalId :: $matchedLidarrAlbumArtistName ( $matchedLidarrAlbumArtistId ) found in Lidarr "
log " $position :: $idNumber of $idListCount :: $tidalId :: $matchedLidarrAlbumArtistName ( $matchedLidarrAlbumArtistId ) found in Lidarr "
else
else