From ef42eee9c80d9983a66b9fa8ba8192a9441da8c8 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Sat, 18 Jan 2025 11:23:14 +0100 Subject: [PATCH] readme --- shell_jellyfin_actors_images_fix.sh | 122 ++++++---------------------- 1 file changed, 25 insertions(+), 97 deletions(-) diff --git a/shell_jellyfin_actors_images_fix.sh b/shell_jellyfin_actors_images_fix.sh index ad1e5e8..f5f2bd3 100644 --- a/shell_jellyfin_actors_images_fix.sh +++ b/shell_jellyfin_actors_images_fix.sh @@ -1,105 +1,33 @@ #!/bin/bash -api_url="http://server-ip:8096" -api_key="" -user_id="" +# API-Endpunkte und API-Schlüssel +api_url="http://192.168.178.30:8096" +api_key="18b973511efd4887a24e14fbdf8f61d5" +user_id="69c0f432ec3a46b58cbf2e900f5a3fd5" -# Ensure '/emby' is appended to the URL if not already present -if [[ ! "$api_url" =~ /emby$ ]]; then - api_url="$api_url/emby" -fi +# Hole die Liste der Personen +echo "Abrufen der Personenliste..." +response=$(curl -s "${base_url}/emby/Persons?api_key=${api_key}") -server_ip=$(echo "$api_url" | sed -E 's#^https?://([^:/]+).*$#\1#') +# Finde Personen ohne ImageTags und extrahiere die IDs +ids=($(echo "$response" | jq -c '.Items[] | select(.ImageTags | length == 0)' | jq -r '.Id' | sort -u)) +total=${#ids[@]} # Gesamtzahl der IDs -# --- ANSI escape codes for colors --- -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -NC='\033[0m' # No Color +echo "Gefundene Personen ohne ImageTags: $total" -# --- Check for force flag --- -force_flag=false -if [[ "$1" == "--force" ]]; then - force_flag=true -fi - -# --- Check server ping --- -if ping -c 1 "$server_ip" > /dev/null 2>&1; then - echo -e "${GREEN}✔ Server is reachable.${NC}" -else - echo -e "${RED}✘ Server is not reachable. Exiting.${NC}" - exit 1 -fi - -# --- Fetch person data --- -person_data=$(curl -s -w "\n%{http_code}" "$api_url/Persons?api_key=$api_key") -status_code=$(echo "$person_data" | tail -n 1) -person_data=$(echo "$person_data" | sed '$d') - -if [[ "$status_code" == "200" ]]; then - echo -e "${GREEN}✔ Successfully retrieved person data.${NC}" -else - echo -e "${RED}✘ Failed to retrieve person data. Server response code: $status_code${NC}" - exit 1 -fi - -# --- Count the total number of persons --- -total_persons=$(echo "$person_data" | jq -r '.Items | length') -echo -e "Total number of persons: ${YELLOW}$total_persons${NC}" - -# --- Process persons based on force flag --- -if [[ "$force_flag" == true ]]; then - echo "Processing all persons (force flag enabled)." - jq_expression='.Items[] | .Id' # Process all persons -else - echo "Processing only persons without ImageTags." - jq_expression='.Items[] | select(.ImageTags == null) | .Id' # Filter for those without ImageTags -fi - -# --- Get the count of persons to be processed --- -persons_to_process=$(echo "$person_data" | jq -r "$jq_expression" | wc -l) - -# --- Progress bar function --- -show_progress_bar() { - local current=$1 - local total=$2 - local bar_length=50 - local filled_length=$((($current * $bar_length) / $total)) - local remaining_length=$((bar_length - filled_length)) - local bar=$(printf "%${filled_length}s" '' | tr ' ' '=') - local remaining=$(printf "%${remaining_length}s" '' | tr ' ' '-') - local color=$3 # Color for the progress bar - printf "\r${color}Progress:${NC} [%s%s] %d/%d" "$bar" "$remaining" "$current" "$total" -} - -# --- Process each person ID --- -if [[ "$persons_to_process" -gt 0 ]]; then - current_person=0 - consecutive_errors=0 - echo "$person_data" | jq -r "$jq_expression" | while read -r person_id; do - response=$(curl -s -w "\n%{http_code}" "$api_url/Users/$user_id/Items/$person_id?api_key=$api_key") - person_details=$(echo "$response" | sed '$d') - status_code=$(echo "$response" | tail -n 1) - - if [[ "$status_code" == "200" ]]; then - ((current_person++)) - consecutive_errors=0 - show_progress_bar "$current_person" "$persons_to_process" "$GREEN" - else - ((consecutive_errors++)) - show_progress_bar "$current_person" "$persons_to_process" "$RED" - echo -e "\n${RED}✘ Error processing person ID '$person_id'. Server response code: $status_code${NC}" - if [[ "$consecutive_errors" -ge 10 ]]; then - echo -e "${RED}✘ Too many consecutive errors. Stopping.${NC}" - exit 1 - fi - fi - done - printf "\n" # Print a newline after the progress bar -else - if [[ "$force_flag" == true ]]; then - echo "No persons found." # If --force is used and no persons are found +# Iteriere durch die IDs mit Fortschrittsanzeige +for ((i=0; i/dev/null + if [ $? -eq 0 ]; then + echo " ^|^s Anfrage f r ID $id erfolgreich." else - echo "No persons found without ImageTags." + echo " ^|^w Anfrage f r ID $id fehlgeschlagen." fi -fi +done + +echo "Verarbeitung abgeschlossen!" \ No newline at end of file