diff --git a/README.md b/README.md index 1ec5168..30e22c7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Da nur die **fehlenden** Bilder geprüft werden, ist das Skript nach dem initial ## Vorraussetzung -`curl`: Sollte standardmäßig auf Linux installiert sein. +`curl` `sed` `tail` `wc` `ping`: Sollte standardmäßig auf Linux installiert sein. `jq`: Kann über den Paketmanager installiert werden: ```bash @@ -29,7 +29,7 @@ Das Script 3 Anpassungen um zu funktionieren **Beispiel:** ```bash -base_url="http://192.168.178.30:8096" +api_url="http://192.168.178.30:8096" api_key="18b973511efd4887a24e14fbdf8f61d5" user_id="69c0f432ec3a46b58cbf2e900f5a3fd5" ``` diff --git a/shell_jellyfin_actors_images_fix.sh b/shell_jellyfin_actors_images_fix.sh index 3b99adb..e6b315a 100644 --- a/shell_jellyfin_actors_images_fix.sh +++ b/shell_jellyfin_actors_images_fix.sh @@ -1,33 +1,105 @@ #!/bin/bash -# API-Endpunkte und API-Schlüssel -base_url="http://192.168.178.30:8096" -api_key="18b973511efd4887a24e14fbdf8f61d5" -user_id="69c0f432ec3a46b58cbf2e900f5a3fd5" +# API endpoint and your API key +# api_url="http://172.16.16.11:8096/emby" (dont forget the "/emby".. even though you use Jellyfin) +# api_key="xaxajsklujkjaskjaklsjokajss" +# user_id="kjkhkjahdjhsakjdhsakjdhkasd" -# Hole die Liste der Personen -echo "Abrufen der Personenliste..." -response=$(curl -s "${base_url}/emby/Persons?api_key=${api_key}") +api_url="http://server-ip:8096/emby" +api_key="" +user_id="" -# 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 +server_ip=$(echo "$api_url" | sed -E 's#^https?://([^:/]+).*$#\1#') -echo "Gefundene Personen ohne ImageTags: $total" +# --- ANSI escape codes for colors --- +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color -# Iteriere durch die IDs mit Fortschrittsanzeige -for ((i=0; i/dev/null - if [ $? -eq 0 ]; then - echo " ^|^s Anfrage f r ID $id erfolgreich." +# --- 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 else - echo " ^|^w Anfrage f r ID $id fehlgeschlagen." + echo "No persons found without ImageTags." fi -done - -echo "Verarbeitung abgeschlossen!" \ No newline at end of file +fi