TimStats commited on
Commit
b3cd12b
·
verified ·
1 Parent(s): 6b2362c

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +14 -17
app.R CHANGED
@@ -165,25 +165,22 @@ apply_percentile_calcs <- function(data) {
165
  }
166
 
167
  get_player_image <- function(player_id) {
168
- # First try MLB format
169
- mlb_url <- sprintf("https://www.mlbstatic.com/playerheadshots/mlb/player/%s.jpg", player_id)
170
 
171
- result <- tryCatch({
172
- response <- httr::HEAD(mlb_url)
173
- if (httr::status_code(response) == 200) {
174
- return(mlb_url)
175
- }
176
-
177
- # If MLB fails, try MiLB format
178
- milb_url <- sprintf("https://www.mlbstatic.com/playerheadshots/milb/player/%s.jpg", player_id)
179
- response <- httr::HEAD(milb_url)
180
- if (httr::status_code(response) == 200) {
181
- return(milb_url)
182
- }
183
- }, error = function(e) NULL)
184
 
185
- # If both fail, return default MLB logo
186
- return("https://www.mlbstatic.com/team-logos/league-on-dark/1.jpg")
187
  }
188
 
189
  get_player_info <- function(player_id, season, level = "MLB") {
 
165
  }
166
 
167
  get_player_image <- function(player_id) {
168
+ # Try MLB silo image first
169
+ silo_url <- sprintf("https://img.mlbstatic.com/mlb-photos/image/upload/w_200,q_auto:best/v1/people/%s/headshot/silo/current", player_id)
170
 
171
+ # Check if silo works
172
+ silo_result <- tryCatch({
173
+ response <- httr::HEAD(silo_url)
174
+ httr::status_code(response) == 200
175
+ }, error = function(e) FALSE)
176
+
177
+ # If silo fails, use MiLB with correct formatting
178
+ if (!silo_result) {
179
+ return(sprintf("https://img.mlbstatic.com/mlb-photos/image/upload/c_fill,g_auto,b_white,ar_1:1/w_180/v1/people/%s/headshot/milb/current", player_id))
180
+ }
 
 
 
181
 
182
+ # Return silo if it worked
183
+ return(silo_url)
184
  }
185
 
186
  get_player_info <- function(player_id, season, level = "MLB") {