parent
f1a4fa626e
commit
e54383c612
1 changed files with 50 additions and 38 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
scriptVersion="1.2"
|
scriptVersion="1.3"
|
||||||
scriptName="DailySeriesEpisodeTrimmer"
|
scriptName="SeriesEpisodeTrimmer"
|
||||||
|
|
||||||
#### Import Settings
|
#### Import Settings
|
||||||
source /config/extended.conf
|
source /config/extended.conf
|
||||||
|
@ -27,33 +27,47 @@ seriesId=$sonarr_series_id
|
||||||
seriesData=$(curl -s "$arrUrl/api/v3/series/$seriesId?apikey=$arrApiKey")
|
seriesData=$(curl -s "$arrUrl/api/v3/series/$seriesId?apikey=$arrApiKey")
|
||||||
seriesTitle=$(echo $seriesData | jq -r ".title")
|
seriesTitle=$(echo $seriesData | jq -r ".title")
|
||||||
seriesType=$(echo $seriesData | jq -r ".seriesType")
|
seriesType=$(echo $seriesData | jq -r ".seriesType")
|
||||||
|
seriesTags=$(echo $seriesData | jq -r ".tags[]")
|
||||||
seriesEpisodeData=$(curl -s "$arrUrl/api/v3/episode?seriesId=$seriesId&apikey=$arrApiKey")
|
seriesEpisodeData=$(curl -s "$arrUrl/api/v3/episode?seriesId=$seriesId&apikey=$arrApiKey")
|
||||||
seriesEpisodeIds=$(echo "$seriesEpisodeData" | jq -r " . | sort_by(.airDate) | reverse | .[] | select(.hasFile==true) | .id")
|
seriesEpisodeIds=$(echo "$seriesEpisodeData" | jq -r " . | sort_by(.airDate) | reverse | .[] | select(.hasFile==true) | .id")
|
||||||
seriesEpisodeIdsCount=$(echo "$seriesEpisodeIds" | wc -l)
|
seriesEpisodeIdsCount=$(echo "$seriesEpisodeIds" | wc -l)
|
||||||
|
|
||||||
|
# If sonarr series is tagged, match via tag to support series that are not considered daily
|
||||||
|
if [ -z "$sonarrSeriesEpisodeTrimmerTag" ]; then
|
||||||
|
tagMatch="false"
|
||||||
|
else
|
||||||
|
tagMatch="false"
|
||||||
|
for tagId in $seriesTags; do
|
||||||
|
tagLabel="$(curl -s "$arrUrl/api/v3/tag/$tagId?apikey=$arrApiKey" | jq -r ".label")"
|
||||||
|
if [ "$sonarrSeriesEpisodeTrimmerTag" == "$tagLabel" ]; then
|
||||||
|
tagMatch="true"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
# Verify series is marked as "daily" type by sonarr, skip if not...
|
# Verify series is marked as "daily" type by sonarr, skip if not...
|
||||||
if [ $seriesType != "daily" ]; then
|
if [ $seriesType != "daily" ] && [ "$tagMatch" == "false" ]; then
|
||||||
log "$seriesTitle (ID:$seriesId) :: TYPE :: $seriesType :: ERROR :: Non-daily series, skipping..."
|
log "$seriesTitle (ID:$seriesId) :: ERROR :: Series does not match TYPE: Daily or TAG: $sonarrSeriesEpisodeTrimmerTag, skipping..."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Skip processing if less than 14 episodes were found to be downloaded
|
# Skip processing if less than 14 episodes were found to be downloaded
|
||||||
if [ $seriesEpisodeIdsCount -lt $maximumDailyEpisodes ]; then
|
if [ $seriesEpisodeIdsCount -lt $maximumDailyEpisodes ]; then
|
||||||
log "$seriesTitle (ID:$seriesId) :: TYPE :: $seriesType :: ERROR :: Series has not exceeded $maximumDailyEpisodes downloaded episodes ($seriesEpisodeIdsCount files found), skipping..."
|
log "$seriesTitle (ID:$seriesId) :: ERROR :: Series has not exceeded $maximumDailyEpisodes downloaded episodes ($seriesEpisodeIdsCount files found), skipping..."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Begin processing "daily" series type
|
# Begin processing "daily" series type
|
||||||
if [ $seriesType == daily ]; then
|
|
||||||
seriesEpisodeData=$(curl -s "$arrUrl/api/v3/episode?seriesId=$seriesId&apikey=$arrApiKey")
|
seriesEpisodeData=$(curl -s "$arrUrl/api/v3/episode?seriesId=$seriesId&apikey=$arrApiKey")
|
||||||
seriesEpisodeIds=$(echo "$seriesEpisodeData"| jq -r " . | sort_by(.airDate) | reverse | .[] | select(.hasFile==true) | .id")
|
seriesEpisodeIds=$(echo "$seriesEpisodeData"| jq -r " . | sort_by(.airDate) | reverse | .[] | select(.hasFile==true) | .id")
|
||||||
processId=0
|
processId=0
|
||||||
seriesRefreshRequired=false
|
seriesRefreshRequired=false
|
||||||
for id in $seriesEpisodeIds; do
|
for id in $seriesEpisodeIds; do
|
||||||
processId=$(( $processId + 1 ))
|
processId=$(( $processId + 1 ))
|
||||||
if [ $processId -gt $maximumDailyEpisodes ]; then
|
|
||||||
episodeData=$(curl -s "http://localhost:8989/api/v3/episode/$id?apikey=$arrApiKey")
|
episodeData=$(curl -s "http://localhost:8989/api/v3/episode/$id?apikey=$arrApiKey")
|
||||||
episodeSeriesId=$(echo "$episodeData" | jq -r ".seriesId")
|
episodeSeriesId=$(echo "$episodeData" | jq -r ".seriesId")
|
||||||
|
if [ $processId -gt $maximumDailyEpisodes ]; then
|
||||||
episodeTitle=$(echo "$episodeData" | jq -r ".title")
|
episodeTitle=$(echo "$episodeData" | jq -r ".title")
|
||||||
episodeSeasonNumber=$(echo "$episodeData" | jq -r ".seasonNumber")
|
episodeSeasonNumber=$(echo "$episodeData" | jq -r ".seasonNumber")
|
||||||
episodeNumber=$(echo "$episodeData" | jq -r ".episodeNumber")
|
episodeNumber=$(echo "$episodeData" | jq -r ".episodeNumber")
|
||||||
|
@ -61,23 +75,21 @@ if [ $seriesType == daily ]; then
|
||||||
episodeFileId=$(echo "$episodeData" | jq -r ".episodeFileId")
|
episodeFileId=$(echo "$episodeData" | jq -r ".episodeFileId")
|
||||||
|
|
||||||
# Unmonitor downloaded episode if greater than 14 downloaded episodes
|
# Unmonitor downloaded episode if greater than 14 downloaded episodes
|
||||||
log "$seriesTitle (ID:$episodeSeriesId) :: TYPE :: $seriesType :: S${episodeSeasonNumber}E${episodeNumber} :: $episodeAirDate :: $episodeTitle :: Unmonitored Episode ID :: $id"
|
log "$seriesTitle (ID:$episodeSeriesId) :: S${episodeSeasonNumber}E${episodeNumber} :: $episodeTitle :: Unmonitored Episode ID :: $id"
|
||||||
umonitorEpisode=$(curl -s "$arrUrl/api/v3/episode/monitor?apikey=$arrApiKey" -X PUT --data-raw "{\"episodeIds\":[$id],\"monitored\":false}")
|
umonitorEpisode=$(curl -s "$arrUrl/api/v3/episode/monitor?apikey=$arrApiKey" -X PUT --data-raw "{\"episodeIds\":[$id],\"monitored\":false}")
|
||||||
|
|
||||||
# Delete downloaded episode if greater than 14 downloaded episodes
|
# Delete downloaded episode if greater than 14 downloaded episodes
|
||||||
log "$seriesTitle (ID:$episodeSeriesId) :: TYPE :: $seriesType :: S${episodeSeasonNumber}E${episodeNumber} :: $episodeAirDate :: $episodeTitle :: Deleted File ID :: $episodeFileId"
|
log "$seriesTitle (ID:$episodeSeriesId) :: S${episodeSeasonNumber}E${episodeNumber} :: $episodeTitle :: Deleted File ID :: $episodeFileId"
|
||||||
deleteFile=$(curl -s "$arrUrl/api/v3/episodefile/$episodeFileId?apikey=$arrApiKey" -X DELETE)
|
deleteFile=$(curl -s "$arrUrl/api/v3/episodefile/$episodeFileId?apikey=$arrApiKey" -X DELETE)
|
||||||
seriesRefreshRequired=true
|
seriesRefreshRequired=true
|
||||||
else
|
else
|
||||||
# Skip if less than required 14 downloaded episodes exist
|
# Skip if less than required 14 downloaded episodes exist
|
||||||
log "$seriesTitle (ID:$episodeSeriesId) :: TYPE :: $seriesType :: Skipping Episode ID :: $id"
|
log "$seriesTitle (ID:$episodeSeriesId) :: Skipping Episode ID :: $id"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ "$seriesRefreshRequired" = "true" ]; then
|
if [ "$seriesRefreshRequired" = "true" ]; then
|
||||||
# Refresh Series after changes
|
# Refresh Series after changes
|
||||||
log "$seriesTitle (ID:$episodeSeriesId) :: TYPE :: $seriesType :: Refresh Series"
|
log "$seriesTitle (ID:$episodeSeriesId) :: Refresh Series"
|
||||||
refreshSeries=$(curl -s "$arrUrl/api/v3/command?apikey=$arrApiKey" -X POST --data-raw "{\"name\":\"RefreshSeries\",\"seriesId\":$episodeSeriesId}")
|
refreshSeries=$(curl -s "$arrUrl/api/v3/command?apikey=$arrApiKey" -X POST --data-raw "{\"name\":\"RefreshSeries\",\"seriesId\":$episodeSeriesId}")
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
|
Loading…
Reference in a new issue