feat(igdb): oyun aramasına yıl filtreleme desteği ekle

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.
This commit is contained in:
2026-02-04 23:11:49 +03:00
parent 7bf699be70
commit 3735c78bd0
2 changed files with 78 additions and 7 deletions

1
.gitignore vendored
View File

@@ -7,4 +7,5 @@
.token-cache
# Test dosyaları
test-games/
*.tmp

View File

@@ -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)"