From 3735c78bd018f1905b00f4b3de09f35d9c1f0770 Mon Sep 17 00:00:00 2001 From: wisecolt Date: Wed, 4 Feb 2026 23:11:49 +0300 Subject: [PATCH] =?UTF-8?q?feat(igdb):=20oyun=20aramas=C4=B1na=20y=C4=B1l?= =?UTF-8?q?=20filtreleme=20deste=C4=9Fi=20ekle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Oyun adında yıl belirtilirse (örneğin "Ghost Town 2025"), bu bilgiden yararlanarak IGDB'den doğru oyunu bulmak için yıl filtreleme özelliği eklendi. extract_year_from_name ve remove_year_from_name fonksiyonları eklendi. Yıl belirtilmişse daha fazla sonuç getirilip yıl aralığına göre en uygun oyun seçiliyor. --- .gitignore | 1 + poster-bash | 84 ++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 2c579f2..21e176d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ .token-cache # Test dosyaları +test-games/ *.tmp diff --git a/poster-bash b/poster-bash index e0b4971..6bd960c 100755 --- a/poster-bash +++ b/poster-bash @@ -750,12 +750,47 @@ auth_get_token() { # IGDB MODULE ############################################################################### -# Search for a game by name +# Extract year from game name (e.g., "Ghost Town 2025" -> "2025", "Ghost Town (2025)" -> "2025") +extract_year_from_name() { + local name="$1" + # Match 4 digit year (1900-2099) - with or without parentheses + if [[ "$name" =~ \(?[0-9]{4}\)? ]]; then + # Extract just the 4 digits + local year=$(echo "$name" | grep -oE '(19[0-9]{2}|20[0-9]{2})' | head -1) + echo "$year" + else + echo "" + fi +} + +# Remove year from game name (e.g., "Ghost Town 2025" -> "Ghost Town", "Ghost Town (2025)" -> "Ghost Town") +remove_year_from_name() { + local name="$1" + # Remove year in various formats: + # - "Game 2025" -> "Game" + # - "Game (2025)" -> "Game" + # - "Game(2025)" -> "Game" + # - "Game ( 2025 )" -> "Game" + echo "$name" | sed -E 's/ ?\(? ?[0-9]{4} ?\)?$//' | sed -E 's/ *$//' +} + +# Search for a game by name (supports year filtering) igdb_search_game() { local game_name="$1" log_debug "IGDB'de aranıyor: $game_name" + # Extract year from name if present + local year_from_name + year_from_name=$(extract_year_from_name "$game_name") + + if [ -n "$year_from_name" ]; then + log_debug "Oyun adından yıl alındı: $year_from_name" + # Remove year from name for cleaner search + game_name=$(remove_year_from_name "$game_name") + log_debug "Yıl çıkarılmış isim: $game_name" + fi + # Ensure we have a valid token if ! auth_get_token; then return 1 @@ -764,9 +799,14 @@ igdb_search_game() { local response local http_code - # Build APICalc query + # Build query - get more results if we have a year to filter + local limit="1" + if [ -n "$year_from_name" ]; then + limit="10" # Get more results to find the right year + fi + local query - query=$(printf 'search "%s"; fields name,cover; limit 1;' "$game_name") + query=$(printf 'search "%s"; fields name,cover,first_release_date; limit %s;' "$game_name" "$limit") # Make API request response=$(curl -s -w "\n%{http_code}" \ @@ -792,14 +832,44 @@ igdb_search_game() { return 1 fi - # Extract game info + # If we have a year, find the best matching result local game_id local name local cover_id - game_id=$(echo "$response" | jq -r '.[0].id // empty') - name=$(echo "$response" | jq -r '.[0].name // empty') - cover_id=$(echo "$response" | jq -r '.[0].cover // empty') + if [ -n "$year_from_name" ]; then + # Convert year to Unix timestamp range (start and end of year) + local year_start + local year_end + year_start=$(date -d "$year_from_name-01-01 00:00:00" +%s 2>/dev/null || echo "0") + year_end=$(date -d "$year_from_name-12-31 23:59:59" +%s 2>/dev/null || echo "0") + + # Find result with release date in the target year + game_id=$(echo "$response" | jq -r ".[] | select(.first_release_date != null) | select(.first_release_date >= $year_start and .first_release_date <= $year_end) | .id" | head -1) + + if [ -n "$game_id" ]; then + # Get the matching game's info + name=$(echo "$response" | jq -r ".[] | select(.id == $game_id) | .name") + cover_id=$(echo "$response" | jq -r ".[] | select(.id == $game_id) | .cover") + log_debug "Yıl $year_from_name için eşleşen oyun bulundu: $name" + else + # No exact year match, use first result + game_id=$(echo "$response" | jq -r '.[0].id // empty') + name=$(echo "$response" | jq -r '.[0].name // empty') + cover_id=$(echo "$response" | jq -r '.[0].cover // empty') + log_debug "Yıl $year_from_name için tam eşleşme yok, ilk sonuç kullanılıyor" + fi + else + # No year filter, use first result + game_id=$(echo "$response" | jq -r '.[0].id // empty') + name=$(echo "$response" | jq -r '.[0].name // empty') + cover_id=$(echo "$response" | jq -r '.[0].cover // empty') + fi + + if [ -z "$game_id" ]; then + log_debug "Oyun bulunamadı: $game_name" + return 1 + fi log_debug "Bulundu: $name (ID: $game_id, Cover: $cover_id)"