this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

update get-tv

+64 -11
+64 -11
hosts/profiles/sync/tv/get-tv.sh
··· 8 8 TRACKING_FILE="/tank/media/tv/.downloaded_shows" 9 9 LOG_FILE="/tank/media/tv/download-log" 10 10 LOCK_FILE="/tmp/get-tv-sync.lock" 11 - SONARR_API_KEY="PLACEHOLDER" 11 + SONARR_API_KEY="9dba6d5f31eb42cf8c65f4f6f21cc8d2" 12 12 SONARR_URL="http://localhost:8989" 13 13 14 14 umask 002 ··· 18 18 touch "$TRACKING_FILE" 19 19 20 20 log() { echo "$(date): $1" >>"$LOG_FILE"; } 21 + 22 + # Extract a match key from a release name for fuzzy matching. 23 + # Sonarr's sourceTitle often differs from the actual filename on the seedbox: 24 + # - sourceTitle omits file extensions (.mkv, .ts, etc.) 25 + # - sourceTitle omits episode titles that appear in the actual filename 26 + # We match on episode identifier + release group, which are consistent on both sides. 27 + # Returns "episode_id|||group" e.g. "Top.Chef.S23E01|||RAWR" or "Jeopardy.2026.03.19|||BTN" 28 + match_key() { 29 + local name="$1" 30 + # Strip known video file extensions 31 + name="${name%.mkv}" 32 + name="${name%.ts}" 33 + name="${name%.mp4}" 34 + name="${name%.avi}" 35 + name="${name%.m4v}" 36 + 37 + local ep_id="" group="" 38 + 39 + # Extract release group: everything after the last hyphen 40 + if [[ "$name" == *-* ]]; then 41 + group="${name##*-}" 42 + fi 43 + 44 + # Extract episode identifier: show name + S##E##, YYYY.MM.DD, or S## pattern 45 + if [[ "$name" =~ ^(.*\.[Ss][0-9]+[Ee][0-9]+) ]]; then 46 + ep_id="${BASH_REMATCH[1]}" 47 + elif [[ "$name" =~ ^(.*\.[0-9]{4}\.[0-9]{2}\.[0-9]{2}) ]]; then 48 + ep_id="${BASH_REMATCH[1]}" 49 + elif [[ "$name" =~ ^(.*\.[Ss][0-9]+)\. ]]; then 50 + ep_id="${BASH_REMATCH[1]}" 51 + fi 52 + 53 + if [ -n "$ep_id" ] && [ -n "$group" ]; then 54 + echo "${ep_id}|||${group}" 55 + fi 56 + } 21 57 22 58 # Acquire exclusive lock to prevent concurrent runs 23 59 exec 9>"$LOCK_FILE" ··· 136 172 continue 137 173 fi 138 174 139 - # Check if it exists on the remote seedbox (exact match on entry name) 140 - # Use ENVIRON to pass source_title to awk, avoiding backslash interpretation from -v 141 - REMOTE_MATCH=$(SOURCE_TITLE="$source_title" awk -F'\t' 'BEGIN { name = ENVIRON["SOURCE_TITLE"] } $2 == name { print; exit }' "$REMOTE_LISTING_FILE") || true 175 + # Match sourceTitle against remote seedbox entries using episode ID + release group. 176 + # Sonarr's sourceTitle often differs from the actual filename (missing extension, 177 + # missing episode title in the name), so exact matching doesn't work. 178 + SOURCE_KEY=$(match_key "$source_title") 179 + if [ -z "$SOURCE_KEY" ]; then 180 + log "WARNING: Could not extract match key from sourceTitle: $source_title" 181 + continue 182 + fi 183 + 184 + REMOTE_MATCH="" 185 + while IFS=$'\t' read -r rtype rname; do 186 + [ -z "$rname" ] && continue 187 + REMOTE_KEY=$(match_key "$rname") 188 + if [ "$SOURCE_KEY" = "$REMOTE_KEY" ]; then 189 + REMOTE_MATCH="$rtype"$'\t'"$rname" 190 + break 191 + fi 192 + done <"$REMOTE_LISTING_FILE" 193 + 142 194 if [ -z "$REMOTE_MATCH" ]; then 143 195 log "Not yet on seedbox (still downloading?): $source_title" 144 196 continue ··· 146 198 147 199 # Determine if it's a directory or file from the listing 148 200 ENTRY_TYPE=$(echo "$REMOTE_MATCH" | cut -f1) 201 + REMOTE_NAME=$(echo "$REMOTE_MATCH" | cut -f2) 149 202 150 - log "Downloading '$source_title' -> '$series_folder/'" 203 + log "Downloading '$source_title' (remote: '$REMOTE_NAME') -> '$series_folder/'" 151 204 mkdir -p "$LOCAL_PATH/$series_folder" 152 205 153 206 if [ "$ENTRY_TYPE" = "d" ]; then 154 207 # Directory: rsync recursively, trailing slash to put contents into series folder 155 208 if rsync -rs --partial --timeout=600 --log-file="$LOG_FILE" \ 156 - "$REMOTE_HOST:$REMOTE_PATH$source_title/" \ 209 + "$REMOTE_HOST:$REMOTE_PATH$REMOTE_NAME/" \ 157 210 "$LOCAL_PATH/$series_folder/"; then 158 211 echo "$source_title" >>"$TRACKING_FILE" 159 - log "Successfully downloaded directory: $source_title" 212 + log "Successfully downloaded directory: $REMOTE_NAME" 160 213 DOWNLOADED=$((DOWNLOADED + 1)) 161 214 else 162 - log "Failed to download directory: $source_title" 215 + log "Failed to download directory: $REMOTE_NAME" 163 216 fi 164 217 else 165 218 # Single file: rsync into series folder 166 219 if rsync -s --partial --timeout=600 --log-file="$LOG_FILE" \ 167 - "$REMOTE_HOST:$REMOTE_PATH$source_title" \ 220 + "$REMOTE_HOST:$REMOTE_PATH$REMOTE_NAME" \ 168 221 "$LOCAL_PATH/$series_folder/"; then 169 222 echo "$source_title" >>"$TRACKING_FILE" 170 - log "Successfully downloaded file: $source_title" 223 + log "Successfully downloaded file: $REMOTE_NAME" 171 224 DOWNLOADED=$((DOWNLOADED + 1)) 172 225 else 173 - log "Failed to download file: $source_title" 226 + log "Failed to download file: $REMOTE_NAME" 174 227 fi 175 228 fi 176 229 done <<<"$RECORDS"