@ -1,18 +1,20 @@
#!/usr/bin/env bash
scriptVersion = "1.0.0 07 "
scriptVersion = "1.0.0 1 0"
arrEventType = " $radarr_eventtype "
arrItemId = $radarr_movie_id
tmdbApiKey = "3b7751e3179f796565d88fdb2fcdf426"
autoScan = "false"
if [ ! -z " $1 " ] ; then
arrItemId = $1
autoScan = "true"
fi
# Debugging
#arrItemId=1 1677
#extrasLanguages= en
#arrItemId=1
#extrasLanguages= it-IT, en-US
#extrasType=all
#extrasOfficialOnly= tru e
#extrasOfficialOnly= fals e
#extrasKodiCompatibility=true
#extrasSingle=false
#enableExtras=true
@ -65,6 +67,7 @@ arrItemData=$(curl -s "$arrUrl/api/v3/movie/$arrItemId?apikey=$arrApiKey")
itemTitle = $( echo " $arrItemData " | jq -r .title)
itemHasFile = $( echo " $arrItemData " | jq -r .hasFile)
itemPath = " $( echo " $arrItemData " | jq -r ".path" ) "
itemFolder = " $( basename " $itemPath " ) "
itemRelativePath = " $( echo " $arrItemData " | jq -r ".movieFile.relativePath" ) "
itemTrailerId = " $( echo " $arrItemData " | jq -r ".youTubeTrailerId" ) "
tmdbId = " $( echo " $arrItemData " | jq -r ".tmdbId" ) "
@ -76,151 +79,156 @@ if [ ! -d "$itemPath" ]; then
fi
if [ " $extrasSingle " = = "true" ] ; then
if [ " $extrasKodiCompatibility " = = "true" ] ; then
extrasFileName = "movie-trailer"
else
extrasFileName = "trailers/Trailer"
fi
if [ ! -z " $itemTrailerId " ] ; then
if [ ! -f " $itemPath / $extrasFileName .mkv " ] ; then
log " $itemTitle :: Trailer :: Downloading Trailer ( $itemTrailerId )... "
if [ ! -z " $cookiesFile " ] ; then
yt-dlp --cookies " $cookiesFile " -o " $itemPath / $extrasFileName " --write-sub --sub-lang $extrasLanguages --embed-subs --merge-output-format mkv --no-mtime --geo-bypass " https://www.youtube.com/watch?v= $itemTrailerId "
else
yt-dlp -o " $itemPath / $extrasFileName " --write-sub --sub-lang $extrasLanguages --embed-subs --merge-output-format mkv --no-mtime --geo-bypass " https://www.youtube.com/watch?v= $itemTrailerId "
fi
if python3 /usr/local/sma/manual.py --config "/sma.ini" -i " $itemPath / $extrasFileName .mkv " -nt & >/dev/null; then
sleep 0.01
log " $itemTitle :: Trailer :: Processed with SMA... "
rm /usr/local/sma/config/*log*
else
log " $itemTitle :: Trailer :: ERROR :: SMA Processing Error "
rm " $itemPath / $extrasFileName .mkv "
log " $itemTitle :: Trailer :: INFO: deleted: $itemPath / $extrasFileName .mkv "
fi
if [ -f " $itemPath / $extrasFileName .mkv " ] ; then
chmod 666 " $itemPath / $extrasFileName .mkv "
chown abc:abc " $itemPath / $extrasFileName .mkv "
fi
else
log " $itemTitle :: Trailer :: Already downloaded... "
fi
else
log " $itemTitle :: Trailer :: ERROR :: No Trailer ID Found, Skipping... "
fi
exit
extrasType = "trailer"
fi
tmdbVideosListData = $( curl -s " https://api.themoviedb.org/3/movie/ $tmdbId /videos?api_key= $tmdbApiKey " | jq -r '.results[] | select(.site=="YouTube")' )
IFS = ',' read -r -a filters <<< " $extrasLanguages "
for filter in " ${ filters [@] } "
do
tmdbVideosListData = $( curl -s " https://api.themoviedb.org/3/movie/ $tmdbId /videos?api_key= $tmdbApiKey &language= $filter " | jq -r '.results[] | select(.site=="YouTube")' )
log " $itemTitle :: Searching for \" $filter \" extras... "
if [ " $extrasType " = = "all" ] ; then
tmdbVideosListDataIds = $( echo " $tmdbVideosListData " | jq -r " select(.iso_639_1==\" $filter \") | .id ")
tmdbVideosListDataIdsCount = $( echo " $tmdbVideosListData " | jq -r " select(.iso_639_1==\" $filter \") | .id " | wc -l)
tmdbVideosListDataIds = $( echo " $tmdbVideosListData " | jq -r ".id" )
tmdbVideosListDataIdsCount = $( echo " $tmdbVideosListData " | jq -r ".id" | wc -l)
else
tmdbVideosListDataIds = $( echo " $tmdbVideosListData " | jq -r " select(.iso_639_1==\"$filter \" and . type==\"Trailer\") | .id ")
tmdbVideosListDataIdsCount = $( echo " $tmdbVideosListData " | jq -r " select(.iso_639_1==\"$filter \" and . type==\"Trailer\") | .id " | wc -l)
tmdbVideosListDataIds = $( echo " $tmdbVideosListData " | jq -r "select(.type==\"Trailer\") | .id" )
tmdbVideosListDataIdsCount = $( echo " $tmdbVideosListData " | jq -r "select(.type==\"Trailer\") | .id" | wc -l)
fi
if [ -z " $tmdbVideosListDataIds " ] ; then
log " $itemTitle :: None found... "
continue
else
break
fi
done
if [ $tmdbVideosListDataIdsCount -le 0 ] ; then
log " $itemTitle :: No Extras Found, skipping... "
exit
fi
log " $itemTitle :: $tmdbVideosListDataIdsCount Extras Found! "
i = 0
for id in $( echo " $tmdbVideosListDataIds " ) ; do
i = $(( i + 1 ))
tmdbExtraData = " $( echo " $tmdbVideosListData " | jq -r " select(.id==\" $id \") " ) "
tmdbExtraTitle = " $( echo " $tmdbExtraData " | jq -r .name) "
tmdbExtraTitleClean = " $( echo " $tmdbExtraTitle " | sed -e " s/[^[:alpha:][:digit:] $^&_+=()'%;{},.@#]/ /g " -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' ) "
tmdbExtraKey = " $( echo " $tmdbExtraData " | jq -r .key) "
tmdbExtraType = " $( echo " $tmdbExtraData " | jq -r .type) "
tmdbExtraOfficial = " $( echo " $tmdbExtraData " | jq -r .official) "
if [ " $tmdbExtraOfficial " != "true" ] ; then
if [ " $extrasOfficialOnly " = = "true" ] ; then
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: Not official, skipping... "
continue
fi
if [ $tmdbVideosListDataIdsCount -le 0 ] ; then
log " $itemTitle :: No Extras Found, skipping... "
exit
fi
if [ " $tmdbExtraType " = = "Featurette" ] ; then
extraFolderName = "featurettes"
elif [ " $tmdbExtraType " = = "Trailer" ] ; then
extraFolderName = "trailers"
elif [ " $tmdbExtraType " = = "Behind the Scenes" ] ; then
extraFolderName = "behind the scenes"
else
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: ERROR :: Extra Type Not found "
if [ -f "/config/logs/MovieExtras-InvalidType.txt" ] ; then
if cat "/config/logs/MovieExtras-InvalidType.txt" | grep " $tmdbExtraType " | read; then
log " $itemTitle :: $tmdbVideosListDataIdsCount Extras Found! "
i = 0
for id in $( echo " $tmdbVideosListDataIds " ) ; do
i = $(( i + 1 ))
updatePlex = "false"
tmdbExtraData = " $( echo " $tmdbVideosListData " | jq -r " select(.id==\" $id \") " ) "
tmdbExtraTitle = " $( echo " $tmdbExtraData " | jq -r .name) "
tmdbExtraTitleClean = " $( echo " $tmdbExtraTitle " | sed -e " s/[^[:alpha:][:digit:] $^&_+=()'%;{},.@#]/ /g " -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' ) "
tmdbExtraKey = " $( echo " $tmdbExtraData " | jq -r .key) "
tmdbExtraType = " $( echo " $tmdbExtraData " | jq -r .type) "
tmdbExtraOfficial = " $( echo " $tmdbExtraData " | jq -r .official) "
if [ " $tmdbExtraOfficial " != "true" ] ; then
if [ " $extrasOfficialOnly " = = "true" ] ; then
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: Not official, skipping... "
continue
fi
fi
if [ " $tmdbExtraType " = = "Featurette" ] ; then
extraFolderName = "featurettes"
elif [ " $tmdbExtraType " = = "Trailer" ] ; then
extraFolderName = "trailers"
elif [ " $tmdbExtraType " = = "Behind the Scenes" ] ; then
extraFolderName = "behind the scenes"
else
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: ERROR :: Extra Type Not found "
if [ -f "/config/logs/MovieExtras-InvalidType.txt" ] ; then
if cat "/config/logs/MovieExtras-InvalidType.txt" | grep " $tmdbExtraType " | read; then
continue
else
echo " $tmdbExtraType " >> "/config/logs/MovieExtras-InvalidType.txt"
fi
fi
echo " $tmdbExtraType " >> "/config/logs/MovieExtras-InvalidType.txt"
continue
fi
if [ " $extrasSingle " = = "true" ] ; then
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: Single Trailer Enabled... "
if [ " $extrasKodiCompatibility " = = "true" ] ; then
finalPath = " $itemPath "
finalFileName = "movie-trailer"
else
echo " $tmdbExtraType " >> "/config/logs/MovieExtras-InvalidType.txt"
finalPath = " $itemPath / $extraFolderName "
finalFileName = " $itemFolder "
fi
else
finalPath = " $itemPath / $extraFolderName "
finalFileName = " $tmdbExtraTitleClean "
fi
echo " $tmdbExtraType " >> "/config/logs/MovieExtras-InvalidType.txt"
continue
fi
if [ ! -d " $itemPath / $extraFolderName " ] ; then
mkdir -p " $itemPath / $extraFolderName "
chmod 777 " $itemPath / $extraFolderName "
chown abc:abc " $itemPath / $extraFolderName "
fi
if [ ! -d " $finalPath " ] ; then
mkdir -p " $finalPath "
chmod 777 " $finalPath "
chown abc:abc " $finalPath "
fi
finalPath = " $itemPath / $extraFolderName "
if [ -f " $finalPath / $tmdbExtraTitleClean .mkv " ] ; then
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ( $tmdbExtraKey ) :: Already Downloaded, skipping... "
continue
fi
if [ -f " $finalPath / $finalFileName .mkv " ] ; then
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ( $tmdbExtraKey ) :: Already Downloaded, skipping... "
if [ " $extrasSingle " = = "true" ] ; then
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: Finished processing single trailer download "
break
fi
continue
fi
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ( $tmdbExtraKey ) :: Downloading... "
if [ ! -z " $cookiesFile " ] ; then
yt-dlp --cookies " $cookiesFile " -o " $finalPath / $tmdbExtraTitleClean " --write-sub --sub-lang $extrasLanguages --embed-subs --merge-output-format mkv --no-mtime --geo-bypass " https://www.youtube.com/watch?v= $tmdbExtraKey " & >/dev/null
else
yt-dlp -o " $finalPath / $tmdbExtraTitleClean " --write-sub --sub-lang $extrasLanguages --embed-subs --merge-output-format mkv --no-mtime --geo-bypass " https://www.youtube.com/watch?v= $tmdbExtraKey " & >/dev/null
fi
if [ -f " $finalPath / $tmdbExtraTitleClean .mkv " ] ; then
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ( $tmdbExtraKey ) :: Compete "
chmod 666 " $finalPath / $tmdbExtraTitleClean .mkv "
chown abc:abc " $finalPath / $tmdbExtraTitleClean .mkv "
else
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ( $tmdbExtraKey ) :: ERROR :: Download Failed "
continue
fi
videoLanguages = " $( echo " $extrasLanguages " | sed "s/-[[:alpha:]][[:alpha:]]//g" ) "
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ( $tmdbExtraKey ) :: Downloading... "
if [ ! -z " $cookiesFile " ] ; then
yt-dlp --cookies " $cookiesFile " -o " $finalPath / $finalFileName " --write-sub --sub-lang $videoLanguages --embed-subs --merge-output-format mkv --no-mtime --geo-bypass " https://www.youtube.com/watch?v= $tmdbExtraKey " & >/dev/null
else
yt-dlp -o " $finalPath / $finalFileName " --write-sub --sub-lang $videoLanguages --embed-subs --merge-output-format mkv --no-mtime --geo-bypass " https://www.youtube.com/watch?v= $tmdbExtraKey " & >/dev/null
fi
if [ -f " $finalPath / $finalFileName .mkv " ] ; then
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ( $tmdbExtraKey ) :: Compete "
chmod 666 " $finalPath / $finalFileName .mkv "
chown abc:abc " $finalPath / $finalFileName .mkv "
else
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle ( $tmdbExtraKey ) :: ERROR :: Download Failed "
continue
fi
if python3 /usr/local/sma/manual.py --config "/sma.ini" -i " $finalPath / $finalFileName .mkv " -nt & /dev/null; then
sleep 0.01
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: Processed with SMA... "
rm /usr/local/sma/config/*log*
else
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: ERROR :: SMA Processing Error "
rm " $finalPath / $finalFileName .mkv "
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: INFO: deleted: $finalPath / $finalFileName .mkv "
fi
updatePlex = "true"
if [ " $extrasSingle " = = "true" ] ; then
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: Finished processing single trailer download "
break
fi
done
if python3 /usr/local/sma/manual.py --config "/sma.ini" -i " $finalPath / $tmdbExtraTitleClean .mkv " -nt & >/dev/null; then
sleep 0.01
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: Processed with SMA... "
rm /usr/local/sma/config/*log*
else
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: ERROR :: SMA Processing Error "
rm " $finalPath / $tmdbExtraTitleClean .mkv "
log " $itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: $tmdbExtraTitle :: INFO: deleted: $finalPath / $tmdbExtraTitleClean .mkv "
fi
done
# Process item with PlexNotify.bash if plexToken is configured
if [ ! -z " $plexToken " ] ; then
log "Using PlexNotify.bash to update Plex...."
bash /config/extended/scripts/PlexNotify.bash " $itemPath "
# Always update plex if extra is downloaded
if [ " $updatePlex " = = "true" ] ; then
log "Using PlexNotify.bash to update Plex...."
bash /config/extended/scripts/PlexNotify.bash " $itemPath "
exit
fi
# Do not notify plex if this script was triggered by the AutoExtras.bash and no Extras were downloaded
if [ " $autoScan " = = "true" ] ; then
log "Skipping plex notification, not needed...."
exit
else
log "Using PlexNotify.bash to update Plex...."
bash /config/extended/scripts/PlexNotify.bash " $itemPath "
exit
fi
fi
exit