Merge pull request #59 from jasperaelvoet/main

YouTube fallback
This commit is contained in:
RandomNinjaAtk 2023-08-16 08:39:40 -04:00 committed by GitHub
commit 27c53702a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 122 additions and 1 deletions

View file

@ -1387,6 +1387,126 @@ SearchProcess () {
touch "/config/extended/logs/notfound/$wantedAlbumId--$lidarrArtistForeignArtistId--$lidarrAlbumForeignAlbumId"
chmod 777 "/config/extended/logs/notfound/$wantedAlbumId--$lidarrArtistForeignArtistId--$lidarrAlbumForeignAlbumId"
fi
if [ $notFoundYoutubeFallback == "true" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Falling back to YouTube"
lidarrAlbumData=$(curl -X GET "$arrUrl/api/v1/album/${checkLidarrAlbumId}" --header "X-Api-Key:"${arrApiKey} -H "Content-Type: application/json")
lidarrAlbumId=$(jq -r '.releases[0].albumId' <<< "$lidarrAlbumData")
tracks=$(curl -X GET "$arrUrl/api/v1/track?albumId=${lidarrAlbumId}" --header "X-Api-Key:"${arrApiKey} -H "Content-Type: application/json")
downloadedAlbumTitleClean="$(echo "$4" | sed -e "s%[^[:alpha:][:digit:]._' ]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')"
downloadedAlbumFolder="$lidarrArtistNameSanitized-$downloadedAlbumTitleClean ($3)-${albumquality^^}-$1-$2"
if [[ -z $lidarrAlbumId ]]; then
echo "Album not found on Lidarr."
else
if [ -d "/temp-yt-dl" ]; then
rm -rf "/temp-yt-dl"
fi
mkdir -p /temp-yt-dl/
chmod 777 -R /temp-yt-dl/
chmod 777 -R "${audioPath}/incomplete/"
trackLength=$(echo $tracks | jq length)
trackLength=$((trackLength-1))
for i in `seq 0 $trackLength`
do
trackTitle=$(jq -r ".[$i].title" <<< "$tracks")
trackId=$(jq -r ".[$i].foreignTrackId" <<< "$tracks")
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $trackTitle :: Downloading from YouTube"
yt-dlp -q --audio-quality highest --audio-format aac -o "/temp-yt-dl/${trackId}" -x "ytsearch:${lidarrArtistName} - ${trackTitle} (Audio)"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $trackTitle :: Adding metadata"
ffmpeg -hide_banner -loglevel error -i "/temp-yt-dl/${trackId}.m4a" -metadata title="${trackTitle}" -metadata artist="${lidarrArtistName}" -metadata album="${lidarrAlbumTitle}" "${audioPath}/incomplete/${trackId}.m4a"
done
if [ -d "/temp-yt-dl" ]; then
rm -rf "/temp-yt-dl"
fi
if [ "$enableBeetsTagging" == "true" ]; then
if [ -f /config/extended/beets-error ]; then
rm /config/extended/beets-error
fi
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Processing files with beets..."
ProcessWithBeets "$audioPath"/incomplete/
if [ -f /config/extended/beets-error ]; then
return
fi
fi
if [ "$enableReplaygainTags" == "true" ]; then
AddReplaygainTags "$audioPath/incomplete"
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Replaygain Tagging Disabled (set enableReplaygainTags=true to enable...)"
fi
albumquality="$(find "$audioPath"/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^^}-$1-$2"
find "$audioPath/incomplete" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -print0 | while IFS= read -r -d '' audio; do
file="${audio}"
filenoext="${file%.*}"
filename="$(basename "$audio")"
extension="${filename##*.}"
filenamenoext="${filename%.*}"
if [ ! -d "$audioPath/complete" ]; then
mkdir -p "$audioPath"/complete
chmod 777 "$audioPath"/complete
fi
mkdir -p "$audioPath/complete/$downloadedAlbumFolder"
mv "$file" "$audioPath/complete/$downloadedAlbumFolder"/
done
chmod -R 777 "$audioPath"/complete
if [ -d "$audioPath/complete/$downloadedAlbumFolder" ]; then
NotifyLidarrForImport "$audioPath/complete/$downloadedAlbumFolder"
LidarrTaskStatusCheck
CheckLidarrBeforeImport "$checkLidarrAlbumId"
if [ "$alreadyImported" == "true" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Already Imported, skipping..."
rm -rf "$audioPath"/incomplete/*
fi
fi
if [ -d "$audioPath/complete/$downloadedAlbumFolder" ]; then
NotifyLidarrForImport "$audioPath/complete/$downloadedAlbumFolder"
LidarrTaskStatusCheck
CheckLidarrBeforeImport "$checkLidarrAlbumId"
if [ "$alreadyImported" == "true" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Already Imported, skipping..."
rm -rf "$audioPath"/incomplete/*
fi
fi
if [ -d "$audioPath/complete/$downloadedAlbumFolder" ]; then
NotifyLidarrForImport "$audioPath/complete/$downloadedAlbumFolder"
LidarrTaskStatusCheck
CheckLidarrBeforeImport "$checkLidarrAlbumId"
if [ "$alreadyImported" == "true" ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Already Imported, skipping..."
rm -rf "$audioPath"/incomplete/*
fi
fi
if [ -d "$audioPath/complete/$downloadedAlbumFolder" ]; then
rm -rf "$audioPath"/incomplete/*
fi
LidarrTaskStatusCheck
CheckLidarrBeforeImport "$checkLidarrAlbumId"
if [ "$alreadyImported" == "true" ]; then
break
fi
fi
fi
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Skip marking album as not found because it's a new release for 7 days..."
fi
@ -1941,4 +2061,4 @@ for (( ; ; )); do
sleep $audioScriptInterval
done
exit
exit

View file

@ -24,6 +24,7 @@ searchSort="date" # date or album :: Sorts the missing/cutoff list by release da
matchDistance="5" # The number of changes required to transform the searched album title into a possible found album title match... (0, requires a perfect match)
lidarrSearchForMissing="true" # true = enabled :: When artists are added, search for them using Lidarr's built in functionality
retryNotFound="90" ## :: Number of days between re-attempting the download of previously notfound albums
notFoundYoutubeFallback="false" # true = enabled :: When the album is marked it not found, it will download the audio via YouTube (less acurate). It will continue trying to download via deezer/tidal.
# CLIENT
dlClientSource="deezer" # deezer, tidal or both :: set to both, to use both clients, tidal requires extra steps, view logging output