From b1388658cb570e75c2c5f7eee9f63006bca5cde8 Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Sun, 29 Dec 2024 23:42:46 +0500 Subject: [PATCH 1/3] check available steamgriddb --- data_from_portwine/scripts/add_in_steam.sh | 57 ++++++++++++---------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/data_from_portwine/scripts/add_in_steam.sh b/data_from_portwine/scripts/add_in_steam.sh index 717da97a..3bd871d5 100755 --- a/data_from_portwine/scripts/add_in_steam.sh +++ b/data_from_portwine/scripts/add_in_steam.sh @@ -100,7 +100,7 @@ getSteamId() { if [[ -n "${SteamIds:-}" ]] && jq -e --arg key "$NOSTAPPNAME" 'has($key)' <<< "${SteamIds}" > /dev/null; then SteamAppId=$(jq -r --arg key "${NOSTAPPNAME}" '.[$key]' <<< "${SteamIds}") else - if [[ -n "${1:-}" ]]; then + if [[ -n "${1:-}" ]] && [[ -z "${SGDBNOTAVAILABLE}" ]]; then getSteamGridDBId "${NOSTAPPNAME}" > /dev/null fi if [[ $SteamGridDBTypeSteam == true ]]; then @@ -108,6 +108,8 @@ getSteamId() { if jq -e ".success == true" <<< "${SRES}" > /dev/null 2>&1; then SteamAppId="$(jq -r '.data.platforms.steam.id' <<< "${SRES}")" fi + elif [[ -n "${SGDBNOTAVAILABLE}" ]]; then + SteamAppId="$(curl -s "https://api.steampowered.com/ISteamApps/GetAppList/v2/" | jq --arg name "${NOSTAPPNAME}" '.applist.apps[] | select(.name == $name) | .appid')" fi SteamIds=$(jq --arg key "${NOSTAPPNAME}" --arg value "${SteamAppId:-}" '. + {($key): $value}' <<< "${SteamIds:-$(jq -n '{}')}") echo "${SteamIds}" > "${cache_file}" @@ -120,15 +122,19 @@ getSteamId() { getSteamGridDBId() { unset SteamGridDBId NOSTAPPNAME="$1" - SGDBRES=$(curl -Ls -H "Authorization: Bearer ${SGDBAPIKEY}" "${BASESTEAMGRIDDBAPI}/search/autocomplete/${NOSTAPPNAME// /_}") - if jq -e ".success == true and (.data | length > 0)" <<< "${SGDBRES}" > /dev/null 2>&1; then - if jq -e '.data[0].types | contains(["steam"])' <<< "${SGDBRES}" > /dev/null; then - SteamGridDBTypeSteam=true - else - SteamGridDBTypeSteam=false + if [[ -z "${SGDBNOTAVAILABLE}" ]] && [[ -n "${SGDBAPIKEY}" ]] && [[ -n "${BASESTEAMGRIDDBAPI}" ]] && curl -fs -o /dev/null "${BASESTEAMGRIDDBAPI}"; then + SGDBRES=$(curl -Ls -H "Authorization: Bearer ${SGDBAPIKEY}" "${BASESTEAMGRIDDBAPI}/search/autocomplete/${NOSTAPPNAME// /_}") + if jq -e ".success == true and (.data | length > 0)" <<< "${SGDBRES}" > /dev/null 2>&1; then + if jq -e '.data[0].types | contains(["steam"])' <<< "${SGDBRES}" > /dev/null; then + SteamGridDBTypeSteam=true + else + SteamGridDBTypeSteam=false + fi + SteamGridDBId="$(jq '.data[0].id' <<< "${SGDBRES}")" + echo "${SteamGridDBId}" fi - SteamGridDBId="$(jq '.data[0].id' <<< "${SGDBRES}")" - echo "${SteamGridDBId}" + else + SGDBNOTAVAILABLE="1" fi } @@ -272,25 +278,30 @@ downloadImageSteam() { } downloadImageSteamGridDB() { - SGDBIMGAPI="${BASESTEAMGRIDDBAPI}/$1/game/${SteamGridDBId}?limit=1" - [[ -n "$3" ]] && SGDBIMGAPI+="&$3" - [[ -n "$4" ]] && SGDBIMGAPI+="&$4" - SGDBIMGRES=$(curl -Ls -H "Authorization: Bearer ${SGDBAPIKEY}" "${SGDBIMGAPI}") - if jq -e ".success == true and (.data | length > 0)" <<< "${SGDBIMGRES}" > /dev/null 2>&1; then - SGDBIMGURL=$(jq -r '.data[0].url' <<< "${SGDBIMGRES}") - downloadImage "${SGDBIMGURL}" "$2" - elif [[ -n "$3" ]]; then - downloadImageSteamGridDB "$1" "$2" "" "$4" + if [[ -n "${SteamGridDBId}" ]]; then + SGDBIMGAPI="${BASESTEAMGRIDDBAPI}/$1/game/${SteamGridDBId}?limit=1" + [[ -n "$3" ]] && SGDBIMGAPI+="&$3" + [[ -n "$4" ]] && SGDBIMGAPI+="&$4" + SGDBIMGRES=$(curl -Ls -H "Authorization: Bearer ${SGDBAPIKEY}" "${SGDBIMGAPI}") + if jq -e ".success == true and (.data | length > 0)" <<< "${SGDBIMGRES}" > /dev/null 2>&1; then + SGDBIMGURL=$(jq -r '.data[0].url' <<< "${SGDBIMGRES}") + downloadImage "${SGDBIMGURL}" "$2" + elif [[ -n "$3" ]]; then + downloadImageSteamGridDB "$1" "$2" "" "$4" + else + return 1 + fi else return 1 fi } addGrids() { - if [[ -n "${SGDBAPIKEY}" ]]; then - getSteamGridDBId "${name_desktop}" > /dev/null + getSteamGridDBId "${name_desktop}" > /dev/null + if [[ -n "${SGDBNOTAVAILABLE}" ]]; then + getSteamId > /dev/null fi - if [[ -n "${SteamGridDBId}" ]]; then + if [[ -n "${SteamGridDBId}" ]] || [[ -n "${SteamAppId}" ]]; then create_new_dir "${STCFGPATH}/grid" downloadImageSteamGridDB "grids" "${NOSTAIDGRID}.jpg" "mimes=image/jpeg" "dimensions=460x215,920x430" || downloadImageSteam "header.jpg" "${NOSTAIDGRID}.jpg" || echo "Failed to load header.jpg" downloadImageSteamGridDB "grids" "${NOSTAIDGRID}p.jpg" "mimes=image/jpeg" "dimensions=600x900,660x930" || downloadImageSteam "library_600x900_2x.jpg" "${NOSTAIDGRID}p.jpg" || echo "Failed to load library_600x900_2x.jpg" @@ -372,10 +383,6 @@ addNonSteamGame() { printf '\x08\x08\x08\x08' } >> "${SCPATH}" - # TODO: замень использование steamgriddb на steam так как сайт steamgriddb у многих без VPN не работает - # а пока просто блочим использование - export DOWNLOAD_STEAM_GRID="0" - if [[ "${DOWNLOAD_STEAM_GRID}" == "1" ]] ; then pw_start_progress_bar_block "${translations[Please wait. downloading covers for]} ${NOSTAPPNAME}" addGrids From f27eb542b30a0555ad8385e0d435eb2cac7b6383 Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Mon, 30 Dec 2024 14:18:36 +0500 Subject: [PATCH 2/3] var USE_STEABGRIDDB --- data_from_portwine/scripts/add_in_steam.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/data_from_portwine/scripts/add_in_steam.sh b/data_from_portwine/scripts/add_in_steam.sh index 3bd871d5..254a93f9 100755 --- a/data_from_portwine/scripts/add_in_steam.sh +++ b/data_from_portwine/scripts/add_in_steam.sh @@ -100,7 +100,7 @@ getSteamId() { if [[ -n "${SteamIds:-}" ]] && jq -e --arg key "$NOSTAPPNAME" 'has($key)' <<< "${SteamIds}" > /dev/null; then SteamAppId=$(jq -r --arg key "${NOSTAPPNAME}" '.[$key]' <<< "${SteamIds}") else - if [[ -n "${1:-}" ]] && [[ -z "${SGDBNOTAVAILABLE}" ]]; then + if [[ -n "${1:-}" ]] && [[ "${USE_STEABGRIDDB:-1}" == "1" ]]; then getSteamGridDBId "${NOSTAPPNAME}" > /dev/null fi if [[ $SteamGridDBTypeSteam == true ]]; then @@ -108,7 +108,7 @@ getSteamId() { if jq -e ".success == true" <<< "${SRES}" > /dev/null 2>&1; then SteamAppId="$(jq -r '.data.platforms.steam.id' <<< "${SRES}")" fi - elif [[ -n "${SGDBNOTAVAILABLE}" ]]; then + elif [[ "${USE_STEABGRIDDB:-1}" == "0" ]]; then SteamAppId="$(curl -s "https://api.steampowered.com/ISteamApps/GetAppList/v2/" | jq --arg name "${NOSTAPPNAME}" '.applist.apps[] | select(.name == $name) | .appid')" fi SteamIds=$(jq --arg key "${NOSTAPPNAME}" --arg value "${SteamAppId:-}" '. + {($key): $value}' <<< "${SteamIds:-$(jq -n '{}')}") @@ -122,7 +122,7 @@ getSteamId() { getSteamGridDBId() { unset SteamGridDBId NOSTAPPNAME="$1" - if [[ -z "${SGDBNOTAVAILABLE}" ]] && [[ -n "${SGDBAPIKEY}" ]] && [[ -n "${BASESTEAMGRIDDBAPI}" ]] && curl -fs -o /dev/null "${BASESTEAMGRIDDBAPI}"; then + if [[ "${USE_STEABGRIDDB:-1}" == "1" ]] && [[ -n "${SGDBAPIKEY}" ]] && [[ -n "${BASESTEAMGRIDDBAPI}" ]] && curl -fs -o /dev/null "${BASESTEAMGRIDDBAPI}"; then SGDBRES=$(curl -Ls -H "Authorization: Bearer ${SGDBAPIKEY}" "${BASESTEAMGRIDDBAPI}/search/autocomplete/${NOSTAPPNAME// /_}") if jq -e ".success == true and (.data | length > 0)" <<< "${SGDBRES}" > /dev/null 2>&1; then if jq -e '.data[0].types | contains(["steam"])' <<< "${SGDBRES}" > /dev/null; then @@ -134,7 +134,7 @@ getSteamGridDBId() { echo "${SteamGridDBId}" fi else - SGDBNOTAVAILABLE="1" + USE_STEABGRIDDB="0" fi } @@ -298,7 +298,7 @@ downloadImageSteamGridDB() { addGrids() { getSteamGridDBId "${name_desktop}" > /dev/null - if [[ -n "${SGDBNOTAVAILABLE}" ]]; then + if [[ "${USE_STEABGRIDDB:-1}" == "1" ]]; then getSteamId > /dev/null fi if [[ -n "${SteamGridDBId}" ]] || [[ -n "${SteamAppId}" ]]; then From 206556056674966f1531df93a5d9317b6584d875 Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Mon, 30 Dec 2024 14:27:56 +0500 Subject: [PATCH 3/3] timeouts --- data_from_portwine/scripts/add_in_steam.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/data_from_portwine/scripts/add_in_steam.sh b/data_from_portwine/scripts/add_in_steam.sh index 254a93f9..be9207fc 100755 --- a/data_from_portwine/scripts/add_in_steam.sh +++ b/data_from_portwine/scripts/add_in_steam.sh @@ -104,12 +104,12 @@ getSteamId() { getSteamGridDBId "${NOSTAPPNAME}" > /dev/null fi if [[ $SteamGridDBTypeSteam == true ]]; then - SRES=$(curl -Ls -e "https://www.steamgriddb.com/game/${SteamGridDBId}" "https://www.steamgriddb.com/api/public/game/${SteamGridDBId}") + SRES=$(curl -Ls --connect-timeout 5 -m 10 -e "https://www.steamgriddb.com/game/${SteamGridDBId}" "https://www.steamgriddb.com/api/public/game/${SteamGridDBId}") if jq -e ".success == true" <<< "${SRES}" > /dev/null 2>&1; then SteamAppId="$(jq -r '.data.platforms.steam.id' <<< "${SRES}")" fi elif [[ "${USE_STEABGRIDDB:-1}" == "0" ]]; then - SteamAppId="$(curl -s "https://api.steampowered.com/ISteamApps/GetAppList/v2/" | jq --arg name "${NOSTAPPNAME}" '.applist.apps[] | select(.name == $name) | .appid')" + SteamAppId="$(curl -s --connect-timeout 5 -m 10 "https://api.steampowered.com/ISteamApps/GetAppList/v2/" | jq --arg name "${NOSTAPPNAME}" '.applist.apps[] | select(.name == $name) | .appid')" fi SteamIds=$(jq --arg key "${NOSTAPPNAME}" --arg value "${SteamAppId:-}" '. + {($key): $value}' <<< "${SteamIds:-$(jq -n '{}')}") echo "${SteamIds}" > "${cache_file}" @@ -122,8 +122,8 @@ getSteamId() { getSteamGridDBId() { unset SteamGridDBId NOSTAPPNAME="$1" - if [[ "${USE_STEABGRIDDB:-1}" == "1" ]] && [[ -n "${SGDBAPIKEY}" ]] && [[ -n "${BASESTEAMGRIDDBAPI}" ]] && curl -fs -o /dev/null "${BASESTEAMGRIDDBAPI}"; then - SGDBRES=$(curl -Ls -H "Authorization: Bearer ${SGDBAPIKEY}" "${BASESTEAMGRIDDBAPI}/search/autocomplete/${NOSTAPPNAME// /_}") + if [[ "${USE_STEABGRIDDB:-1}" == "1" ]] && [[ -n "${SGDBAPIKEY}" ]] && [[ -n "${BASESTEAMGRIDDBAPI}" ]] && curl -fs --connect-timeout 5 -m 10 -o /dev/null "${BASESTEAMGRIDDBAPI}"; then + SGDBRES=$(curl -Ls --connect-timeout 5 -m 10 -H "Authorization: Bearer ${SGDBAPIKEY}" "${BASESTEAMGRIDDBAPI}/search/autocomplete/${NOSTAPPNAME// /_}") if jq -e ".success == true and (.data | length > 0)" <<< "${SGDBRES}" > /dev/null 2>&1; then if jq -e '.data[0].types | contains(["steam"])' <<< "${SGDBRES}" > /dev/null; then SteamGridDBTypeSteam=true @@ -261,7 +261,7 @@ restartSteam() { } downloadImage() { - if ! curl -Lf# -o "${STCFGPATH}/grid/$2" "$1"; then + if ! curl -Lf# --connect-timeout 5 -m 10 -o "${STCFGPATH}/grid/$2" "$1"; then return 1 fi } @@ -282,7 +282,7 @@ downloadImageSteamGridDB() { SGDBIMGAPI="${BASESTEAMGRIDDBAPI}/$1/game/${SteamGridDBId}?limit=1" [[ -n "$3" ]] && SGDBIMGAPI+="&$3" [[ -n "$4" ]] && SGDBIMGAPI+="&$4" - SGDBIMGRES=$(curl -Ls -H "Authorization: Bearer ${SGDBAPIKEY}" "${SGDBIMGAPI}") + SGDBIMGRES=$(curl -Ls --connect-timeout 5 -m 10 -H "Authorization: Bearer ${SGDBAPIKEY}" "${SGDBIMGAPI}") if jq -e ".success == true and (.data | length > 0)" <<< "${SGDBIMGRES}" > /dev/null 2>&1; then SGDBIMGURL=$(jq -r '.data[0].url' <<< "${SGDBIMGRES}") downloadImage "${SGDBIMGURL}" "$2" @@ -298,15 +298,15 @@ downloadImageSteamGridDB() { addGrids() { getSteamGridDBId "${name_desktop}" > /dev/null - if [[ "${USE_STEABGRIDDB:-1}" == "1" ]]; then + if [[ "${USE_STEABGRIDDB:-1}" == "0" ]]; then getSteamId > /dev/null fi if [[ -n "${SteamGridDBId}" ]] || [[ -n "${SteamAppId}" ]]; then create_new_dir "${STCFGPATH}/grid" - downloadImageSteamGridDB "grids" "${NOSTAIDGRID}.jpg" "mimes=image/jpeg" "dimensions=460x215,920x430" || downloadImageSteam "header.jpg" "${NOSTAIDGRID}.jpg" || echo "Failed to load header.jpg" - downloadImageSteamGridDB "grids" "${NOSTAIDGRID}p.jpg" "mimes=image/jpeg" "dimensions=600x900,660x930" || downloadImageSteam "library_600x900_2x.jpg" "${NOSTAIDGRID}p.jpg" || echo "Failed to load library_600x900_2x.jpg" - downloadImageSteamGridDB "heroes" "${NOSTAIDGRID}_hero.jpg" "mimes=image/jpeg" || downloadImageSteam "library_hero.jpg" "${NOSTAIDGRID}_hero.jpg" || echo "Failed to load library_hero.jpg" - downloadImageSteamGridDB "logos" "${NOSTAIDGRID}_logo.png" "mimes=image/png" || downloadImageSteam "logo.png" "${NOSTAIDGRID}_logo.png" || echo "Failed to load logo.png" + downloadImageSteamGridDB "grids" "${NOSTAIDGRID:-0}.jpg" "mimes=image/jpeg" "dimensions=460x215,920x430" || downloadImageSteam "header.jpg" "${NOSTAIDGRID:-0}.jpg" || echo "Failed to load header.jpg" + downloadImageSteamGridDB "grids" "${NOSTAIDGRID:-0}p.jpg" "mimes=image/jpeg" "dimensions=600x900,660x930" || downloadImageSteam "library_600x900_2x.jpg" "${NOSTAIDGRID:-0}p.jpg" || echo "Failed to load library_600x900_2x.jpg" + downloadImageSteamGridDB "heroes" "${NOSTAIDGRID:-0}_hero.jpg" "mimes=image/jpeg" || downloadImageSteam "library_hero.jpg" "${NOSTAIDGRID:-0}_hero.jpg" || echo "Failed to load library_hero.jpg" + downloadImageSteamGridDB "logos" "${NOSTAIDGRID:-0}_logo.png" "mimes=image/png" || downloadImageSteam "logo.png" "${NOSTAIDGRID:-0}_logo.png" || echo "Failed to load logo.png" else echo "Game is not found" fi