Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 43 additions & 35 deletions lidarr/Audio.service.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/with-contenv bash
scriptVersion="2.48"
scriptVersion="2.5"
scriptName="Audio"

### Import Settings
Expand Down Expand Up @@ -71,7 +71,10 @@ verifyConfig () {
preferSpecialEditions="true"
fi

audioPath="$downloadPath/audio"
audioPath="$downloadPath/audio"
tidalDlNgConfigDir="/config/extended/tidal_dl_ng"
tidalDlNgConfigFile="${tidalDlNgConfigDir}/config.json"
tidalDlNgConfigTemplate="/config/extended/tidal-dl.json"


}
Expand Down Expand Up @@ -101,8 +104,11 @@ Configuration () {



if [ ! -d /config/xdg ]; then
mkdir -p /config/xdg
if [ ! -d /config/extended ]; then
mkdir -p /config/extended
fi
if [ ! -d "$tidalDlNgConfigDir" ]; then
mkdir -p "$tidalDlNgConfigDir"
fi

if [ -z $topLimit ]; then
Expand Down Expand Up @@ -206,16 +212,16 @@ DownloadFormat () {

if [ "$audioFormat" == "native" ]; then
if [ "$audioBitrate" == "master" ]; then
tidalQuality=Master
tidalQuality=HI_RES_LOSSLESS
deemixQuality=flac
elif [ "$audioBitrate" == "lossless" ]; then
tidalQuality=HiFi
tidalQuality=LOSSLESS
deemixQuality=flac
elif [ "$audioBitrate" == "high" ]; then
tidalQuality=High
tidalQuality=HIGH
deemixQuality=320
elif [ "$audioBitrate" == "low" ]; then
tidalQuality=128
tidalQuality=LOW
deemixQuality=128
else
log "ERROR :: Invalid audioFormat and audioBitrate options set..."
Expand All @@ -229,7 +235,7 @@ DownloadFormat () {
else
bitrateError="false"
audioFormatError="false"
tidalQuality=HiFi
tidalQuality=LOSSLESS
deemixQuality=flac

case "$audioBitrate" in
Expand Down Expand Up @@ -269,7 +275,7 @@ DownloadFormat () {
exit
fi

tidal-dl -q HiFi
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg quality_audio LOSSLESS 2>&1 | tee -a "/config/logs/$logFileName"
deemixQuality=flac
bitrateError=""
audioFormatError=""
Expand Down Expand Up @@ -301,32 +307,36 @@ NotFoundFolderCleaner () {
}

TidalClientSetup () {
log "TIDAL :: Verifying tidal-dl configuration"
touch /config/xdg/.tidal-dl.log
if [ -f /config/xdg/.tidal-dl.json ]; then
rm /config/xdg/.tidal-dl.json
fi
if [ ! -f /config/xdg/.tidal-dl.json ]; then
log "TIDAL :: No default config found, importing default config \"tidal.json\""
if [ -f /config/extended/tidal-dl.json ]; then
cp /config/extended/tidal-dl.json /config/xdg/.tidal-dl.json
chmod 777 -R /config/xdg/
log "TIDAL :: Verifying tidal-dl-ng configuration"
touch "${tidalDlNgConfigDir}/tidal-dl-ng.log"
if [ -f "$tidalDlNgConfigFile" ]; then
rm "$tidalDlNgConfigFile"
fi
if [ ! -f "$tidalDlNgConfigFile" ]; then
log "TIDAL :: No default config found, importing default config \"tidal-dl.json\""
if [ -f "$tidalDlNgConfigTemplate" ]; then
cp "$tidalDlNgConfigTemplate" "$tidalDlNgConfigFile"
chmod 777 -R "$tidalDlNgConfigDir"
fi

fi

TidaldlStatusCheck
tidal-dl -o "$audioPath"/incomplete 2>&1 | tee -a "/config/logs/$logFileName"
DownloadFormat
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg download_base_path "$audioPath/incomplete" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg quality_audio "$tidalQuality" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg path_binary_ffmpeg "/usr/bin/ffmpeg" 2>&1 | tee -a "/config/logs/$logFileName"

if [ ! -f /config/xdg/.tidal-dl.token.json ]; then
if ! ls "${tidalDlNgConfigDir}"/*auth*.json "${tidalDlNgConfigDir}"/*token*.json 1>/dev/null 2>&1; then
TidaldlStatusCheck
#log "TIDAL :: ERROR :: Downgrade tidal-dl for workaround..."
#pip3 install tidal-dl==2022.3.4.2 --no-cache-dir &>/dev/null
log "TIDAL :: ERROR :: Loading client for required authentication, please authenticate, then exit the client..."
NotifyWebhook "FatalError" "TIDAL requires authentication, please authenticate now (check logs)"
TidaldlStatusCheck
tidal-dl
if command -v script >/dev/null 2>&1; then
script -q -c "PYTHONUNBUFFERED=1 XDG_CONFIG_HOME=/config/extended tidal-dl-ng login" /dev/null
else
PYTHONUNBUFFERED=1 XDG_CONFIG_HOME=/config/extended tidal-dl-ng login
fi
fi

if [ ! -d /config/extended/cache/tidal ]; then
Expand All @@ -347,18 +357,16 @@ TidalClientSetup () {
fi

TidaldlStatusCheck
#log "TIDAL :: Upgrade tidal-dl to newer version..."
#pip3 install tidal-dl==2022.07.06.1 --no-cache-dir &>/dev/null

}

TidaldlStatusCheck () {
until false
do
running=no
if ps aux | grep "tidal-dl" | grep -v "grep" | read; then
if ps aux | grep "tidal-dl-ng" | grep -v "grep" | read; then
running=yes
log "STATUS :: TIDAL-DL :: BUSY :: Pausing/waiting for all active tidal-dl tasks to end..."
log "STATUS :: TIDAL-DL-NG :: BUSY :: Pausing/waiting for all active tidal-dl-ng tasks to end..."
sleep 2
continue
fi
Expand All @@ -367,12 +375,12 @@ TidaldlStatusCheck () {
}

TidalClientTest () {
log "TIDAL :: tidal-dl client setup verification..."
log "TIDAL :: tidal-dl-ng client setup verification..."
i=0
while [ $i -lt 3 ]; do
i=$(( $i + 1 ))
TidaldlStatusCheck
tidal-dl -q Normal -o "$audioPath"/incomplete -l "$tidalClientTestDownloadId" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng dl "https://tidal.com/browse/album/$tidalClientTestDownloadId" 2>&1 | tee -a "/config/logs/$logFileName"
downloadCount=$(find "$audioPath"/incomplete -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ $downloadCount -le 0 ]; then
continue
Expand All @@ -382,9 +390,7 @@ TidalClientTest () {
done
tidalClientTest="unknown"
if [ $downloadCount -le 0 ]; then
if [ -f /config/xdg/.tidal-dl.token.json ]; then
rm /config/xdg/.tidal-dl.token.json
fi
rm -f "${tidalDlNgConfigDir}"/*auth*.json "${tidalDlNgConfigDir}"/*token*.json
log "TIDAL :: ERROR :: Download failed"
log "TIDAL :: ERROR :: You will need to re-authenticate on next script run..."
log "TIDAL :: ERROR :: Exiting..."
Expand Down Expand Up @@ -557,7 +563,9 @@ DownloadProcess () {
if [ "$2" == "TIDAL" ]; then
TidaldlStatusCheck

tidal-dl -q $tidalQuality -o "$audioPath/incomplete" -l "$1" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg download_base_path "$audioPath/incomplete" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg quality_audio "$tidalQuality" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng dl "https://tidal.com/browse/album/$1" 2>&1 | tee -a "/config/logs/$logFileName"

# Verify Client Works...
clientTestDlCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
Expand Down
59 changes: 37 additions & 22 deletions lidarr/TidalVideoDownloader.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/with-contenv bash
scriptVersion="2.1"
scriptVersion="2.2"
scriptName="TidalVideoDownloader"

#### Import Settings
Expand All @@ -24,6 +24,9 @@ verifyConfig () {
downloadPath="/config/extended/downloads"
fi
videoDownloadPath="$downloadPath/tidal/videos"
tidalDlNgConfigDir="/config/extended/tidal_dl_ng"
tidalDlNgConfigFile="${tidalDlNgConfigDir}/config.json"
tidalDlNgConfigTemplate="/config/extended/tidal-dl.json"
if [ -z "$videoScriptInterval" ]; then
videoScriptInterval="15m"
fi
Expand All @@ -45,24 +48,35 @@ verifyConfig () {
}

TidalClientSetup () {
log "TIDAL :: Verifying tidal-dl configuration"
if [ ! -f /config/xdg/.tidal-dl.json ]; then
log "TIDAL :: No default config found, importing default config \"tidal.json\""
if [ -f /config/extended/tidal-dl.json ]; then
cp /config/extended/tidal-dl.json /config/xdg/.tidal-dl.json
chmod 777 -R /config/xdg/
log "TIDAL :: Verifying tidal-dl-ng configuration"
if [ ! -d /config/extended ]; then
mkdir -p /config/extended
fi
if [ ! -d "$tidalDlNgConfigDir" ]; then
mkdir -p "$tidalDlNgConfigDir"
fi
if [ ! -f "$tidalDlNgConfigFile" ]; then
log "TIDAL :: No default config found, importing default config \"tidal-dl.json\""
if [ -f "$tidalDlNgConfigTemplate" ]; then
cp "$tidalDlNgConfigTemplate" "$tidalDlNgConfigFile"
chmod 777 -R "$tidalDlNgConfigDir"
fi
fi

tidal-dl -o "$videoDownloadPath"/incomplete 2>&1 | tee -a "/config/logs/$logFileName"
tidalQuality=HiFi

if [ ! -f /config/xdg/.tidal-dl.token.json ]; then
#log "TIDAL :: ERROR :: Downgrade tidal-dl for workaround..."
#pip3 install tidal-dl==2022.3.4.2 --no-cache-dir &>/dev/null
tidalQuality=LOSSLESS
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg download_base_path "$videoDownloadPath/incomplete" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg quality_audio "$tidalQuality" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg quality_video "1080" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg path_binary_ffmpeg "/usr/bin/ffmpeg" 2>&1 | tee -a "/config/logs/$logFileName"

if ! ls "${tidalDlNgConfigDir}"/*auth*.json "${tidalDlNgConfigDir}"/*token*.json 1>/dev/null 2>&1; then
log "TIDAL :: ERROR :: Loading client for required authentication, please authenticate, then exit the client..."
NotifyWebhook "FatalError" "TIDAL requires authentication, please authenticate now (check logs)"
tidal-dl 2>&1 | tee -a "/config/logs/$logFileName"
if command -v script >/dev/null 2>&1; then
script -q -c "PYTHONUNBUFFERED=1 XDG_CONFIG_HOME=/config/extended tidal-dl-ng login" /dev/null
else
PYTHONUNBUFFERED=1 XDG_CONFIG_HOME=/config/extended tidal-dl-ng login
fi
fi

if [ ! -d "$videoDownloadPath/incomplete" ]; then
Expand All @@ -81,9 +95,9 @@ TidaldlStatusCheck () {
until false
do
running=no
if ps aux | grep "tidal-dl" | grep -v "grep" | read; then
if ps aux | grep "tidal-dl-ng" | grep -v "grep" | read; then
running=yes
log "STATUS :: TIDAL-DL :: BUSY :: Pausing/waiting for all active tidal-dl tasks to end..."
log "STATUS :: TIDAL-DL-NG :: BUSY :: Pausing/waiting for all active tidal-dl-ng tasks to end..."
sleep 2
continue
fi
Expand All @@ -92,12 +106,12 @@ TidaldlStatusCheck () {
}

TidalClientTest () {
log "TIDAL :: tidal-dl client setup verification..."
log "TIDAL :: tidal-dl-ng client setup verification..."
i=0
while [ $i -lt 3 ]; do
i=$(( $i + 1 ))
TidaldlStatusCheck
tidal-dl -q Normal -o "$videoDownloadPath"/incomplete -l "$tidalClientTestDownloadId" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng dl "https://tidal.com/browse/album/$tidalClientTestDownloadId" 2>&1 | tee -a "/config/logs/$logFileName"
downloadCount=$(find "$videoDownloadPath"/incomplete -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ $downloadCount -le 0 ]; then
continue
Expand All @@ -107,9 +121,7 @@ TidalClientTest () {
done
tidalClientTest="unknown"
if [ $downloadCount -le 0 ]; then
if [ -f /config/xdg/.tidal-dl.token.json ]; then
rm /config/xdg/.tidal-dl.token.json
fi
rm -f "${tidalDlNgConfigDir}"/*auth*.json "${tidalDlNgConfigDir}"/*token*.json
log "TIDAL :: ERROR :: Download failed"
log "TIDAL :: ERROR :: You will need to re-authenticate on next script run..."
log "TIDAL :: ERROR :: Exiting..."
Expand Down Expand Up @@ -339,7 +351,10 @@ VideoProcess () {

downloadFailed=false
log "$processCount/$lidarrArtistCount :: $lidarrArtistName :: $tidalVideoProcessNumber/$tidalVideoIdsCount :: $videoTitle ($id) :: Downloading..."
tidal-dl -r P1080 -o "$videoDownloadPath/incomplete" -l "$videoUrl" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg download_base_path "$videoDownloadPath/incomplete" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg quality_video "1080" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng cfg path_binary_ffmpeg "/usr/bin/ffmpeg" 2>&1 | tee -a "/config/logs/$logFileName"
XDG_CONFIG_HOME=/config/extended tidal-dl-ng dl "$videoUrl" 2>&1 | tee -a "/config/logs/$logFileName"
find "$videoDownloadPath/incomplete" -type f -exec mv "{}" "$videoDownloadPath/incomplete"/ \;
find "$videoDownloadPath/incomplete" -mindepth 1 -type d -exec rm -rf "{}" \; &>/dev/null
find "$videoDownloadPath/incomplete" -type f -regex ".*/.*\.\(mkv\|mp4\)" -print0 | while IFS= read -r -d '' video; do
Expand Down
4 changes: 2 additions & 2 deletions lidarr/setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ uv pip install --system --upgrade --no-cache-dir --break-system-packages \
pylast \
mutagen \
r128gain \
tidal-dl \
tidal-dl-ng \
deemix \
langdetect \
apprise && \
Expand Down Expand Up @@ -107,7 +107,7 @@ if [ ! -f /config/extended/deemix_config.json ]; then
fi

if [ ! -f /config/extended/tidal-dl.json ]; then
echo "Download Tidal config..."
echo "Download Tidal (tidal-dl-ng) config..."
curl -sfL "https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/lidarr/tidal-dl.json" -o /config/extended/tidal-dl.json
echo "Done"
fi
Expand Down
17 changes: 16 additions & 1 deletion lidarr/tidal-dl.json
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
{"albumFolderFormat": "atd", "apiKeyIndex": 4, "audioQuality": "HiFi", "checkExist": true, "downloadPath": "/downloads/lidarr-extended/incomplete", "includeEP": true, "language": "0", "lyricFile": true, "multiThread": false, "saveAlbumInfo": false, "saveCovers": false, "showProgress": true, "showTrackInfo": true, "trackFileFormat": "{TrackNumber} - {TrackTitle}", "usePlaylistFolder": false, "videoFileFormat": "{VideoNumber} - {ArtistName} - {VideoTitle}{ExplicitFlag}", "videoQuality": "P1080"}
{
"download_base_path": "/downloads/lidarr-extended/incomplete",
"quality_audio": "LOSSLESS",
"quality_video": "1080",
"format_album": "{album_artist}/{album_title} ({album_year})",
"format_track": "{track_number} - {track_title}",
"format_playlist": "{playlist_title}/{track_number} - {track_title}",
"format_mix": "{mix_title}/{track_number} - {track_title}",
"format_video": "{artist_name} - {track_title}",
"path_binary_ffmpeg": "/usr/bin/ffmpeg",
"extract_flac": false,
"save_album_info": false,
"save_covers": false,
"save_lyrics": true,
"hide_progress": false
}