POL_GoG_download
Informations
Creator | Message |
---|---|
Quentin PÂRIS
|
InformationThis installer has been approved by the team. InformationsPlatforms: Feedbacks0 0 DescriptionAsk the user about its credentials, then download all the pieces of a GOG.com game, checking their integrity using the provided MD5 hashes.
Source code#!/bin/bash local GAME="$1" # option: --altername 'basename' baseindex: get pieces starting from another index than 0 # options: --patch: patches | --bonus: bonus contents # 2.. MD5: hash of the pieces # Will download as many pieces as extra parameters # Hashes are recommended for large downloads anyway shift local BASENAME="setup_$GAME" local INDEX=0 if [ "$1" = "--alternate" ]; then BASENAME="$2" INDEX="$3" shift 3 fi # URL = ${BASEURL}/${GAME}/${INDEXPREFIX}${INDEX} local BASEURL="https://secure.gog.com/downlink" local INDEXPREFIX="en1installer" if [ "$1" = "--patch" ]; then INDEXPREFIX="en1patch" shift elif [ "$1" = "--bonus" ]; then BASEURL="https://secure.gog.com/downlink/file" INDEXPREFIX="" shift fi local PIECES="$#" local GOG_REPO="$(POL_Config_Read GOG_REPO)" if [ -z "$GOG_REPO" ]; then POL_SetupWindow_textbox "$(eval_gettext 'In what directory do you want to download GOG files?')" "$TITLE" "$POL_USER_ROOT/tmp/" GOG_REPO="$APP_ANSWER" POL_Config_Write GOG_REPO "$GOG_REPO" fi local ALREADY_IN_SESSION="$GOG_LOGIN" [ "$ALREADY_IN_SESSION" ] || POL_Call POL_GoG_login # Download [ -d "$GOG_REPO" ] || mkdir -p "$GOG_REPO" cd "$GOG_REPO" || cd "$POL_USER_ROOT/tmp/" POL_Debug_Message "Will download into $PWD" download_piece () { # 1: URL # 2: filename # 3: MD5 hash # 4: Title # Failed piece from previous download, maybe reference MD5 was corrected? local FAILEDPIECE="$2.failed" if [ -n "$3" -a ! -e "$2" -a -e "$FAILEDPIECE" ]; then POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ "$(POL_MD5_file $FAILEDPIECE)" = "$3" ]; then mv "$FAILEDPIECE" "$2" fi fi [ -e "$2" ] && return local TMPPIECE="$2.part" while true; do POL_System_wget "$1" "$4" --referer=https://www.gog.com/ --no-check-certificate --keep-session-cookies --load-cookies="$COOKIES_FINAL" --save-cookies="$COOKIES_FINAL" --continue -O "$TMPPIECE" POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ ! -e "$TMPPIECE" ]; then GOGDMSG="$(eval_gettext 'Download failed')" elif [ -n "$3" ] && [ "$(POL_MD5_file $TMPPIECE)" != "$3" ]; then GOGDMSG="$(eval_gettext 'Download seems to be corrupted')\n$(eval_gettext 'The file could also have been updated. If the problem persists, consider reporting the issue so that the script can be adjusted.')" mv "$TMPPIECE" "$FAILEDPIECE" else # Success mv "$TMPPIECE" "$2" [ -e "$FAILEDPIECE" ] && rm "$FAILEDPIECE" break fi POL_SetupWindow_question "$GOGDMSG\n$(eval_gettext 'Retry?')" "$TITLE" [ "$APP_ANSWER" = "TRUE" ] || POL_Debug_Fatal "$GOGDMSG" done } download_piece "$BASEURL/$GAME/${INDEXPREFIX}$INDEX" "$BASENAME.exe" "$1" "$BASENAME (1/$PIECES)" if [ $PIECES -gt 1 ]; then local n=2 while [ $n -le $PIECES ]; do download_piece "$BASEURL/$GAME/${INDEXPREFIX}$((INDEX+n-1))" "$BASENAME-$((n-1)).bin" "${!n}" "$BASENAME ($n/$PIECES)" let n=$((n+1)) done fi # If we were already in session, it's caller responsability to close it [ "$ALREADY_IN_SESSION" ] || POL_Call POL_GoG_logout POL_GoG_downloaded="True" POL_GoG_location="$PWD/$BASENAME.exe" |
Contributions
Filters:
ContributeMember | Message |
petch | Wednesday 17 February 2016 at 20:20 |
petch
|
InformationThis update has been approved by the team. Messagebugfixes for login/logout integration Differences@@ -67,7 +67,7 @@ local TMPPIECE="$2.part" while true; do - POL_System_wget "$1" "$4" --referer=https://www.gog.com/ --no-check-certificate --keep-session-cookies --load-cookies="$FINAL_COOKIES" --save-cookies="$FINAL_COOKIES" --continue -O "$TMPPIECE" + POL_System_wget "$1" "$4" --referer=https://www.gog.com/ --no-check-certificate --keep-session-cookies --load-cookies="$COOKIES_FINAL" --save-cookies="$COOKIES_FINAL" --continue -O "$TMPPIECE" POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ ! -e "$TMPPIECE" ]; then New source code#!/bin/bash local GAME="$1" # option: --altername 'basename' baseindex: get pieces starting from another index than 0 # options: --patch: patches | --bonus: bonus contents # 2.. MD5: hash of the pieces # Will download as many pieces as extra parameters # Hashes are recommended for large downloads anyway shift local BASENAME="setup_$GAME" local INDEX=0 if [ "$1" = "--alternate" ]; then BASENAME="$2" INDEX="$3" shift 3 fi # URL = ${BASEURL}/${GAME}/${INDEXPREFIX}${INDEX} local BASEURL="https://secure.gog.com/downlink" local INDEXPREFIX="en1installer" if [ "$1" = "--patch" ]; then INDEXPREFIX="en1patch" shift elif [ "$1" = "--bonus" ]; then BASEURL="https://secure.gog.com/downlink/file" INDEXPREFIX="" shift fi local PIECES="$#" local GOG_REPO="$(POL_Config_Read GOG_REPO)" if [ -z "$GOG_REPO" ]; then POL_SetupWindow_textbox "$(eval_gettext 'In what directory do you want to download GOG files?')" "$TITLE" "$POL_USER_ROOT/tmp/" GOG_REPO="$APP_ANSWER" POL_Config_Write GOG_REPO "$GOG_REPO" fi local ALREADY_IN_SESSION="$GOG_LOGIN" [ "$ALREADY_IN_SESSION" ] || POL_Call POL_GoG_login # Download [ -d "$GOG_REPO" ] || mkdir -p "$GOG_REPO" cd "$GOG_REPO" || cd "$POL_USER_ROOT/tmp/" POL_Debug_Message "Will download into $PWD" download_piece () { # 1: URL # 2: filename # 3: MD5 hash # 4: Title # Failed piece from previous download, maybe reference MD5 was corrected? local FAILEDPIECE="$2.failed" if [ -n "$3" -a ! -e "$2" -a -e "$FAILEDPIECE" ]; then POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ "$(POL_MD5_file $FAILEDPIECE)" = "$3" ]; then mv "$FAILEDPIECE" "$2" fi fi [ -e "$2" ] && return local TMPPIECE="$2.part" while true; do POL_System_wget "$1" "$4" --referer=https://www.gog.com/ --no-check-certificate --keep-session-cookies --load-cookies="$COOKIES_FINAL" --save-cookies="$COOKIES_FINAL" --continue -O "$TMPPIECE" POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ ! -e "$TMPPIECE" ]; then GOGDMSG="$(eval_gettext 'Download failed')" elif [ -n "$3" ] && [ "$(POL_MD5_file $TMPPIECE)" != "$3" ]; then GOGDMSG="$(eval_gettext 'Download seems to be corrupted')\n$(eval_gettext 'The file could also have been updated. If the problem persists, consider reporting the issue so that the script can be adjusted.')" mv "$TMPPIECE" "$FAILEDPIECE" else # Success mv "$TMPPIECE" "$2" [ -e "$FAILEDPIECE" ] && rm "$FAILEDPIECE" break fi POL_SetupWindow_question "$GOGDMSG\n$(eval_gettext 'Retry?')" "$TITLE" [ "$APP_ANSWER" = "TRUE" ] || POL_Debug_Fatal "$GOGDMSG" done } download_piece "$BASEURL/$GAME/${INDEXPREFIX}$INDEX" "$BASENAME.exe" "$1" "$BASENAME (1/$PIECES)" if [ $PIECES -gt 1 ]; then local n=2 while [ $n -le $PIECES ]; do download_piece "$BASEURL/$GAME/${INDEXPREFIX}$((INDEX+n-1))" "$BASENAME-$((n-1)).bin" "${!n}" "$BASENAME ($n/$PIECES)" let n=$((n+1)) done fi # If we were already in session, it's caller responsability to close it [ "$ALREADY_IN_SESSION" ] || POL_Call POL_GoG_logout POL_GoG_downloaded="True" POL_GoG_location="$PWD/$BASENAME.exe" RepliesEdited by petch |
petch | Wednesday 17 February 2016 at 20:03 |
petch
|
WarningThis update has not been approved yet by the team. MessageUse POL_GoG_login/logout Differences@@ -39,36 +39,8 @@ fi -# Login / open session -local COOKIES="$POL_USER_ROOT/tmp/gog_cookies" -local COOKIES_2="$POL_USER_ROOT/tmp/gog_cookies2" -while true; do - POL_SetupWindow_login "$(eval_gettext 'Please enter your gog.com login to download $BASENAME')" "$TITLE" "http://www.gog.com/" - - POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE" - - rm "$COOKIES" 2> /dev/null - rm "$COOKIES_2" 2> /dev/null - gutm="$($POL_WGET http://www.gog.com/ -O- --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" | sed -n 's/^.*id="gutm" value="\([^"]*\)".*$/\1/p')" - gutm="$(POL_Website_urlencode "$gutm")" - - buk="$($POL_WGET "http://www.gog.com/user/ajax" -O- --post-data="a=get&c=gamecard&p1=false&p2=false&auth=&gutm=$gutm" --save-cookies=$COOKIES_2 --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" |sed -n 's/^.*"buk":"\([^"]*\)".*/\1/p')" - buk="$(POL_Website_urlencode "$buk")" - - $POL_WGET https://secure.gog.com/login --save-cookies=$COOKIES --load-cookies=$COOKIES_2 --post-data="log_email=$(POL_Website_urlencode "$POL_LOGIN")&log_password=$(POL_Website_urlencode "$POL_PASSWORD")&redirectOk=/&unlockSettings=0&btn_login=Log me in&buk=$buk" --no-check-certificate -O- --header="DNT: 1" --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" - - unset POL_LOGIN POL_PASSWORD - - local AUTH_SESSION="$(awk '$6 == "guc_al" { print $7 }' $COOKIES)" - [ "$AUTH_SESSION" != "0" ] && break - unset AUTH_SESSION - - POL_SetupWindow_question "$(eval_gettext 'Gog.com login failed, try again?')" "$TITLE" - if [ "$APP_ANSWER" = "FALSE" ]; then - POL_SetupWindow_Close - exit - fi -done +local ALREADY_IN_SESSION="$GOG_LOGIN" +[ "$ALREADY_IN_SESSION" ] || POL_Call POL_GoG_login # Download [ -d "$GOG_REPO" ] || mkdir -p "$GOG_REPO" @@ -125,8 +97,8 @@ done fi -# Close session -rm -f "$COOKIES" +# If we were already in session, it's caller responsability to close it +[ "$ALREADY_IN_SESSION" ] || POL_Call POL_GoG_logout POL_GoG_downloaded="True" POL_GoG_location="$PWD/$BASENAME.exe" New source code#!/bin/bash local GAME="$1" # option: --altername 'basename' baseindex: get pieces starting from another index than 0 # options: --patch: patches | --bonus: bonus contents # 2.. MD5: hash of the pieces # Will download as many pieces as extra parameters # Hashes are recommended for large downloads anyway shift local BASENAME="setup_$GAME" local INDEX=0 if [ "$1" = "--alternate" ]; then BASENAME="$2" INDEX="$3" shift 3 fi # URL = ${BASEURL}/${GAME}/${INDEXPREFIX}${INDEX} local BASEURL="https://secure.gog.com/downlink" local INDEXPREFIX="en1installer" if [ "$1" = "--patch" ]; then INDEXPREFIX="en1patch" shift elif [ "$1" = "--bonus" ]; then BASEURL="https://secure.gog.com/downlink/file" INDEXPREFIX="" shift fi local PIECES="$#" local GOG_REPO="$(POL_Config_Read GOG_REPO)" if [ -z "$GOG_REPO" ]; then POL_SetupWindow_textbox "$(eval_gettext 'In what directory do you want to download GOG files?')" "$TITLE" "$POL_USER_ROOT/tmp/" GOG_REPO="$APP_ANSWER" POL_Config_Write GOG_REPO "$GOG_REPO" fi local ALREADY_IN_SESSION="$GOG_LOGIN" [ "$ALREADY_IN_SESSION" ] || POL_Call POL_GoG_login # Download [ -d "$GOG_REPO" ] || mkdir -p "$GOG_REPO" cd "$GOG_REPO" || cd "$POL_USER_ROOT/tmp/" POL_Debug_Message "Will download into $PWD" download_piece () { # 1: URL # 2: filename # 3: MD5 hash # 4: Title # Failed piece from previous download, maybe reference MD5 was corrected? local FAILEDPIECE="$2.failed" if [ -n "$3" -a ! -e "$2" -a -e "$FAILEDPIECE" ]; then POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ "$(POL_MD5_file $FAILEDPIECE)" = "$3" ]; then mv "$FAILEDPIECE" "$2" fi fi [ -e "$2" ] && return local TMPPIECE="$2.part" while true; do POL_System_wget "$1" "$4" --no-check-certificate --load-cookies="$COOKIES" --continue -O "$TMPPIECE" POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ ! -e "$TMPPIECE" ]; then GOGDMSG="$(eval_gettext 'Download failed')" elif [ -n "$3" ] && [ "$(POL_MD5_file $TMPPIECE)" != "$3" ]; then GOGDMSG="$(eval_gettext 'Download seems to be corrupted')\n$(eval_gettext 'The file could also have been updated. If the problem persists, consider reporting the issue so that the script can be adjusted.')" mv "$TMPPIECE" "$FAILEDPIECE" else # Success mv "$TMPPIECE" "$2" [ -e "$FAILEDPIECE" ] && rm "$FAILEDPIECE" break fi POL_SetupWindow_question "$GOGDMSG\n$(eval_gettext 'Retry?')" "$TITLE" [ "$APP_ANSWER" = "TRUE" ] || POL_Debug_Fatal "$GOGDMSG" done } download_piece "$BASEURL/$GAME/${INDEXPREFIX}$INDEX" "$BASENAME.exe" "$1" "$BASENAME (1/$PIECES)" if [ $PIECES -gt 1 ]; then local n=2 while [ $n -le $PIECES ]; do download_piece "$BASEURL/$GAME/${INDEXPREFIX}$((INDEX+n-1))" "$BASENAME-$((n-1)).bin" "${!n}" "$BASENAME ($n/$PIECES)" let n=$((n+1)) done fi # If we were already in session, it's caller responsability to close it [ "$ALREADY_IN_SESSION" ] || POL_Call POL_GoG_logout POL_GoG_downloaded="True" POL_GoG_location="$PWD/$BASENAME.exe" Replies |
Mystic-Mirage | Sunday 29 November 2015 at 1:36 |
Mystic-Mirage
|
MessageAs I can see -- English language is only supported (hardcoded) for now? Any chance to support other languages? For example, GOG's Pathologic Classic HD game has three installers -- en1installer* for English, pl1installer* for Polish and ru1installer for Russian. RepliesSunday 29 November 2015 at 10:35
|
trevorh | Tuesday 5 August 2014 at 17:25 |
trevorh
|
WarningThis update has not been approved yet by the team. MessagePassing skip will now skip that place file. Differences@@ -5,6 +5,7 @@ # options: --patch: patches | --bonus: bonus contents # 2.. MD5: hash of the pieces # Will download as many pieces as extra parameters +# Passing skip will skip trying to download that place file # Hashes are recommended for large downloads anyway shift @@ -20,15 +21,20 @@ local BASEURL="https://secure.gog.com/downlink" local INDEXPREFIX="en1installer" if [ "$1" = "--patch" ]; then - INDEXPREFIX="en1patch" + INDEXPREFIX="en1patch" shift elif [ "$1" = "--bonus" ]; then BASEURL="https://secure.gog.com/downlink/file" - INDEXPREFIX="" + INDEXPREFIX="" shift fi -local PIECES="$#" +local PIECES=0 +for arg in "$@"; do + if [ "${arg}" != "skip" ]; then + PIECES=$((${PIECES}+1)) + fi +done local GOG_REPO="$(POL_Config_Read GOG_REPO)" @@ -117,10 +123,15 @@ download_piece "$BASEURL/$GAME/${INDEXPREFIX}$INDEX" "$BASENAME.exe" "$1" "$BASENAME (1/$PIECES)" -if [ $PIECES -gt 1 ]; then +if [ $# -gt 1 ]; then local n=2 - while [ $n -le $PIECES ]; do - download_piece "$BASEURL/$GAME/${INDEXPREFIX}$((INDEX+n-1))" "$BASENAME-$((n-1)).bin" "${!n}" "$BASENAME ($n/$PIECES)" + local offset=0 + while [ $n -le $# ]; do + if [ "${!n}" != "skip" ]; then + download_piece "$BASEURL/$GAME/${INDEXPREFIX}$((INDEX+n-1))" "$BASENAME-$((n-1-offset)).bin" "${!n}" "$BASENAME ($n/$PIECES)" + else + let offset=$((offset+1)) + fi let n=$((n+1)) done fi @@ -129,4 +140,4 @@ rm -f "$COOKIES" POL_GoG_downloaded="True" -POL_GoG_location="$PWD/$BASENAME.exe" +POL_GoG_location="$PWD/$BASENAME.exe" \ No newline at end of file New source code#!/bin/bash local GAME="$1" # option: --altername 'basename' baseindex: get pieces starting from another index than 0 # options: --patch: patches | --bonus: bonus contents # 2.. MD5: hash of the pieces # Will download as many pieces as extra parameters # Passing skip will skip trying to download that place file # Hashes are recommended for large downloads anyway shift local BASENAME="setup_$GAME" local INDEX=0 if [ "$1" = "--alternate" ]; then BASENAME="$2" INDEX="$3" shift 3 fi # URL = ${BASEURL}/${GAME}/${INDEXPREFIX}${INDEX} local BASEURL="https://secure.gog.com/downlink" local INDEXPREFIX="en1installer" if [ "$1" = "--patch" ]; then INDEXPREFIX="en1patch" shift elif [ "$1" = "--bonus" ]; then BASEURL="https://secure.gog.com/downlink/file" INDEXPREFIX="" shift fi local PIECES=0 for arg in "$@"; do if [ "${arg}" != "skip" ]; then PIECES=$((${PIECES}+1)) fi done local GOG_REPO="$(POL_Config_Read GOG_REPO)" if [ -z "$GOG_REPO" ]; then POL_SetupWindow_textbox "$(eval_gettext 'In what directory do you want to download GOG files?')" "$TITLE" "$POL_USER_ROOT/tmp/" GOG_REPO="$APP_ANSWER" POL_Config_Write GOG_REPO "$GOG_REPO" fi # Login / open session local COOKIES="$POL_USER_ROOT/tmp/gog_cookies" local COOKIES_2="$POL_USER_ROOT/tmp/gog_cookies2" while true; do POL_SetupWindow_login "$(eval_gettext 'Please enter your gog.com login to download $BASENAME')" "$TITLE" "http://www.gog.com/" POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE" rm "$COOKIES" 2> /dev/null rm "$COOKIES_2" 2> /dev/null gutm="$($POL_WGET http://www.gog.com/ -O- --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" | sed -n 's/^.*id="gutm" value="\([^"]*\)".*$/\1/p')" gutm="$(POL_Website_urlencode "$gutm")" buk="$($POL_WGET "http://www.gog.com/user/ajax" -O- --post-data="a=get&c=gamecard&p1=false&p2=false&auth=&gutm=$gutm" --save-cookies=$COOKIES_2 --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" |sed -n 's/^.*"buk":"\([^"]*\)".*/\1/p')" buk="$(POL_Website_urlencode "$buk")" $POL_WGET https://secure.gog.com/login --save-cookies=$COOKIES --load-cookies=$COOKIES_2 --post-data="log_email=$(POL_Website_urlencode "$POL_LOGIN")&log_password=$(POL_Website_urlencode "$POL_PASSWORD")&redirectOk=/&unlockSettings=0&btn_login=Log me in&buk=$buk" --no-check-certificate -O- --header="DNT: 1" --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" unset POL_LOGIN POL_PASSWORD local AUTH_SESSION="$(awk '$6 == "guc_al" { print $7 }' $COOKIES)" [ "$AUTH_SESSION" != "0" ] && break unset AUTH_SESSION POL_SetupWindow_question "$(eval_gettext 'Gog.com login failed, try again?')" "$TITLE" if [ "$APP_ANSWER" = "FALSE" ]; then POL_SetupWindow_Close exit fi done # Download [ -d "$GOG_REPO" ] || mkdir -p "$GOG_REPO" cd "$GOG_REPO" || cd "$POL_USER_ROOT/tmp/" POL_Debug_Message "Will download into $PWD" download_piece () { # 1: URL # 2: filename # 3: MD5 hash # 4: Title # Failed piece from previous download, maybe reference MD5 was corrected? local FAILEDPIECE="$2.failed" if [ -n "$3" -a ! -e "$2" -a -e "$FAILEDPIECE" ]; then POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ "$(POL_MD5_file $FAILEDPIECE)" = "$3" ]; then mv "$FAILEDPIECE" "$2" fi fi [ -e "$2" ] && return local TMPPIECE="$2.part" while true; do POL_System_wget "$1" "$4" --no-check-certificate --load-cookies="$COOKIES" --continue -O "$TMPPIECE" POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ ! -e "$TMPPIECE" ]; then GOGDMSG="$(eval_gettext 'Download failed')" elif [ -n "$3" ] && [ "$(POL_MD5_file $TMPPIECE)" != "$3" ]; then GOGDMSG="$(eval_gettext 'Download seems to be corrupted')\n$(eval_gettext 'The file could also have been updated. If the problem persists, consider reporting the issue so that the script can be adjusted.')" mv "$TMPPIECE" "$FAILEDPIECE" else # Success mv "$TMPPIECE" "$2" [ -e "$FAILEDPIECE" ] && rm "$FAILEDPIECE" break fi POL_SetupWindow_question "$GOGDMSG\n$(eval_gettext 'Retry?')" "$TITLE" [ "$APP_ANSWER" = "TRUE" ] || POL_Debug_Fatal "$GOGDMSG" done } download_piece "$BASEURL/$GAME/${INDEXPREFIX}$INDEX" "$BASENAME.exe" "$1" "$BASENAME (1/$PIECES)" if [ $# -gt 1 ]; then local n=2 local offset=0 while [ $n -le $# ]; do if [ "${!n}" != "skip" ]; then download_piece "$BASEURL/$GAME/${INDEXPREFIX}$((INDEX+n-1))" "$BASENAME-$((n-1-offset)).bin" "${!n}" "$BASENAME ($n/$PIECES)" else let offset=$((offset+1)) fi let n=$((n+1)) done fi # Close session rm -f "$COOKIES" POL_GoG_downloaded="True" POL_GoG_location="$PWD/$BASENAME.exe" Replies |
trevorh | Tuesday 5 August 2014 at 8:14 |
trevorh
|
WarningThis update has not been approved yet by the team. MessageAllow scripts to skip missing indices by passing an empty parameter. For use where GOG does not use consecutive indices such as with Heroes of Might and Magic 5. Differences@@ -5,37 +5,43 @@ # options: --patch: patches | --bonus: bonus contents # 2.. MD5: hash of the pieces # Will download as many pieces as extra parameters +# An empty parameter will skip trying to download that place file # Hashes are recommended for large downloads anyway shift local BASENAME="setup_$GAME" local INDEX=0 if [ "$1" = "--alternate" ]; then - BASENAME="$2" - INDEX="$3" - shift 3 + BASENAME="$2" + INDEX="$3" + shift 3 fi # URL = ${BASEURL}/${GAME}/${INDEXPREFIX}${INDEX} local BASEURL="https://secure.gog.com/downlink" local INDEXPREFIX="en1installer" if [ "$1" = "--patch" ]; then - INDEXPREFIX="en1patch" - shift + INDEXPREFIX="en1patch" + shift elif [ "$1" = "--bonus" ]; then - BASEURL="https://secure.gog.com/downlink/file" - INDEXPREFIX="" - shift + BASEURL="https://secure.gog.com/downlink/file" + INDEXPREFIX="" + shift fi -local PIECES="$#" +local PIECES=0 +for arg in "$@"; do + if [ "${arg}" != "" ]; then + PIECES=$((${PIECES}+1)) + fi +done local GOG_REPO="$(POL_Config_Read GOG_REPO)" if [ -z "$GOG_REPO" ]; then - POL_SetupWindow_textbox "$(eval_gettext 'In what directory do you want to download GOG files?')" "$TITLE" "$POL_USER_ROOT/tmp/" - GOG_REPO="$APP_ANSWER" - POL_Config_Write GOG_REPO "$GOG_REPO" + POL_SetupWindow_textbox "$(eval_gettext 'In what directory do you want to download GOG files?')" "$TITLE" "$POL_USER_ROOT/tmp/" + GOG_REPO="$APP_ANSWER" + POL_Config_Write GOG_REPO "$GOG_REPO" fi @@ -43,31 +49,31 @@ local COOKIES="$POL_USER_ROOT/tmp/gog_cookies" local COOKIES_2="$POL_USER_ROOT/tmp/gog_cookies2" while true; do - POL_SetupWindow_login "$(eval_gettext 'Please enter your gog.com login to download $BASENAME')" "$TITLE" "http://www.gog.com/" + POL_SetupWindow_login "$(eval_gettext 'Please enter your gog.com login to download $BASENAME')" "$TITLE" "http://www.gog.com/" - POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE" + POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE" - rm "$COOKIES" 2> /dev/null - rm "$COOKIES_2" 2> /dev/null - gutm="$($POL_WGET http://www.gog.com/ -O- --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" | sed -n 's/^.*id="gutm" value="\([^"]*\)".*$/\1/p')" - gutm="$(POL_Website_urlencode "$gutm")" + rm "$COOKIES" 2> /dev/null + rm "$COOKIES_2" 2> /dev/null + gutm="$($POL_WGET http://www.gog.com/ -O- --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" | sed -n 's/^.*id="gutm" value="\([^"]*\)".*$/\1/p')" + gutm="$(POL_Website_urlencode "$gutm")" - buk="$($POL_WGET "http://www.gog.com/user/ajax" -O- --post-data="a=get&c=gamecard&p1=false&p2=false&auth=&gutm=$gutm" --save-cookies=$COOKIES_2 --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" |sed -n 's/^.*"buk":"\([^"]*\)".*/\1/p')" - buk="$(POL_Website_urlencode "$buk")" + buk="$($POL_WGET "http://www.gog.com/user/ajax" -O- --post-data="a=get&c=gamecard&p1=false&p2=false&auth=&gutm=$gutm" --save-cookies=$COOKIES_2 --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" |sed -n 's/^.*"buk":"\([^"]*\)".*/\1/p')" + buk="$(POL_Website_urlencode "$buk")" - $POL_WGET https://secure.gog.com/login --save-cookies=$COOKIES --load-cookies=$COOKIES_2 --post-data="log_email=$(POL_Website_urlencode "$POL_LOGIN")&log_password=$(POL_Website_urlencode "$POL_PASSWORD")&redirectOk=/&unlockSettings=0&btn_login=Log me in&buk=$buk" --no-check-certificate -O- --header="DNT: 1" --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" + $POL_WGET https://secure.gog.com/login --save-cookies=$COOKIES --load-cookies=$COOKIES_2 --post-data="log_email=$(POL_Website_urlencode "$POL_LOGIN")&log_password=$(POL_Website_urlencode "$POL_PASSWORD")&redirectOk=/&unlockSettings=0&btn_login=Log me in&buk=$buk" --no-check-certificate -O- --header="DNT: 1" --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" - unset POL_LOGIN POL_PASSWORD + unset POL_LOGIN POL_PASSWORD - local AUTH_SESSION="$(awk '$6 == "guc_al" { print $7 }' $COOKIES)" - [ "$AUTH_SESSION" != "0" ] && break - unset AUTH_SESSION + local AUTH_SESSION="$(awk '$6 == "guc_al" { print $7 }' $COOKIES)" + [ "$AUTH_SESSION" != "0" ] && break + unset AUTH_SESSION - POL_SetupWindow_question "$(eval_gettext 'Gog.com login failed, try again?')" "$TITLE" - if [ "$APP_ANSWER" = "FALSE" ]; then - POL_SetupWindow_Close - exit - fi + POL_SetupWindow_question "$(eval_gettext 'Gog.com login failed, try again?')" "$TITLE" + if [ "$APP_ANSWER" = "FALSE" ]; then + POL_SetupWindow_Close + exit + fi done # Download @@ -77,56 +83,61 @@ download_piece () { - # 1: URL - # 2: filename - # 3: MD5 hash - # 4: Title - - # Failed piece from previous download, maybe reference MD5 was corrected? - local FAILEDPIECE="$2.failed" - if [ -n "$3" -a ! -e "$2" -a -e "$FAILEDPIECE" ]; then - POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" - if [ "$(POL_MD5_file $FAILEDPIECE)" = "$3" ]; then - mv "$FAILEDPIECE" "$2" - fi - fi - - [ -e "$2" ] && return - - local TMPPIECE="$2.part" - while true; do - POL_System_wget "$1" "$4" --no-check-certificate --load-cookies="$COOKIES" --continue -O "$TMPPIECE" - - POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" - if [ ! -e "$TMPPIECE" ]; then - GOGDMSG="$(eval_gettext 'Download failed')" - elif [ -n "$3" ] && [ "$(POL_MD5_file $TMPPIECE)" != "$3" ]; then - GOGDMSG="$(eval_gettext 'Download seems to be corrupted')\n$(eval_gettext 'The file could also have been updated. If the problem persists, consider reporting the issue so that the script can be adjusted.')" - mv "$TMPPIECE" "$FAILEDPIECE" - else - # Success - mv "$TMPPIECE" "$2" - [ -e "$FAILEDPIECE" ] && rm "$FAILEDPIECE" - break - fi - - POL_SetupWindow_question "$GOGDMSG\n$(eval_gettext 'Retry?')" "$TITLE" - [ "$APP_ANSWER" = "TRUE" ] || POL_Debug_Fatal "$GOGDMSG" - done + # 1: URL + # 2: filename + # 3: MD5 hash + # 4: Title + + # Failed piece from previous download, maybe reference MD5 was corrected? + local FAILEDPIECE="$2.failed" + if [ -n "$3" -a ! -e "$2" -a -e "$FAILEDPIECE" ]; then + POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" + if [ "$(POL_MD5_file $FAILEDPIECE)" = "$3" ]; then + mv "$FAILEDPIECE" "$2" + fi + fi + + [ -e "$2" ] && return + + local TMPPIECE="$2.part" + while true; do + POL_System_wget "$1" "$4" --no-check-certificate --load-cookies="$COOKIES" --continue -O "$TMPPIECE" + + POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" + if [ ! -e "$TMPPIECE" ]; then + GOGDMSG="$(eval_gettext 'Download failed')" + elif [ -n "$3" ] && [ "$(POL_MD5_file $TMPPIECE)" != "$3" ]; then + GOGDMSG="$(eval_gettext 'Download seems to be corrupted')\n$(eval_gettext 'The file could also have been updated. If the problem persists, consider reporting the issue so that the script can be adjusted.')" + mv "$TMPPIECE" "$FAILEDPIECE" + else + # Success + mv "$TMPPIECE" "$2" + [ -e "$FAILEDPIECE" ] && rm "$FAILEDPIECE" + break + fi + + POL_SetupWindow_question "$GOGDMSG\n$(eval_gettext 'Retry?')" "$TITLE" + [ "$APP_ANSWER" = "TRUE" ] || POL_Debug_Fatal "$GOGDMSG" + done } download_piece "$BASEURL/$GAME/${INDEXPREFIX}$INDEX" "$BASENAME.exe" "$1" "$BASENAME (1/$PIECES)" -if [ $PIECES -gt 1 ]; then - local n=2 - while [ $n -le $PIECES ]; do - download_piece "$BASEURL/$GAME/${INDEXPREFIX}$((INDEX+n-1))" "$BASENAME-$((n-1)).bin" "${!n}" "$BASENAME ($n/$PIECES)" - let n=$((n+1)) - done +if [ $# -gt 1 ]; then + local n=2 + local offset=0 + while [ $n -le $# ]; do + if [ "${!n}" != "" ]; then + download_piece "$BASEURL/$GAME/${INDEXPREFIX}$((INDEX+n-1))" "$BASENAME-$((n-1-offset)).bin" "${!n}" "$BASENAME ($n/$PIECES)" + else + let offset=$((offset+1)) + fi + let n=$((n+1)) + done fi # Close session rm -f "$COOKIES" POL_GoG_downloaded="True" -POL_GoG_location="$PWD/$BASENAME.exe" +POL_GoG_location="$PWD/$BASENAME.exe" \ No newline at end of file New source code#!/bin/bash local GAME="$1" # option: --altername 'basename' baseindex: get pieces starting from another index than 0 # options: --patch: patches | --bonus: bonus contents # 2.. MD5: hash of the pieces # Will download as many pieces as extra parameters # An empty parameter will skip trying to download that place file # Hashes are recommended for large downloads anyway shift local BASENAME="setup_$GAME" local INDEX=0 if [ "$1" = "--alternate" ]; then BASENAME="$2" INDEX="$3" shift 3 fi # URL = ${BASEURL}/${GAME}/${INDEXPREFIX}${INDEX} local BASEURL="https://secure.gog.com/downlink" local INDEXPREFIX="en1installer" if [ "$1" = "--patch" ]; then INDEXPREFIX="en1patch" shift elif [ "$1" = "--bonus" ]; then BASEURL="https://secure.gog.com/downlink/file" INDEXPREFIX="" shift fi local PIECES=0 for arg in "$@"; do if [ "${arg}" != "" ]; then PIECES=$((${PIECES}+1)) fi done local GOG_REPO="$(POL_Config_Read GOG_REPO)" if [ -z "$GOG_REPO" ]; then POL_SetupWindow_textbox "$(eval_gettext 'In what directory do you want to download GOG files?')" "$TITLE" "$POL_USER_ROOT/tmp/" GOG_REPO="$APP_ANSWER" POL_Config_Write GOG_REPO "$GOG_REPO" fi # Login / open session local COOKIES="$POL_USER_ROOT/tmp/gog_cookies" local COOKIES_2="$POL_USER_ROOT/tmp/gog_cookies2" while true; do POL_SetupWindow_login "$(eval_gettext 'Please enter your gog.com login to download $BASENAME')" "$TITLE" "http://www.gog.com/" POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE" rm "$COOKIES" 2> /dev/null rm "$COOKIES_2" 2> /dev/null gutm="$($POL_WGET http://www.gog.com/ -O- --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" | sed -n 's/^.*id="gutm" value="\([^"]*\)".*$/\1/p')" gutm="$(POL_Website_urlencode "$gutm")" buk="$($POL_WGET "http://www.gog.com/user/ajax" -O- --post-data="a=get&c=gamecard&p1=false&p2=false&auth=&gutm=$gutm" --save-cookies=$COOKIES_2 --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" |sed -n 's/^.*"buk":"\([^"]*\)".*/\1/p')" buk="$(POL_Website_urlencode "$buk")" $POL_WGET https://secure.gog.com/login --save-cookies=$COOKIES --load-cookies=$COOKIES_2 --post-data="log_email=$(POL_Website_urlencode "$POL_LOGIN")&log_password=$(POL_Website_urlencode "$POL_PASSWORD")&redirectOk=/&unlockSettings=0&btn_login=Log me in&buk=$buk" --no-check-certificate -O- --header="DNT: 1" --user-agent="Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0" unset POL_LOGIN POL_PASSWORD local AUTH_SESSION="$(awk '$6 == "guc_al" { print $7 }' $COOKIES)" [ "$AUTH_SESSION" != "0" ] && break unset AUTH_SESSION POL_SetupWindow_question "$(eval_gettext 'Gog.com login failed, try again?')" "$TITLE" if [ "$APP_ANSWER" = "FALSE" ]; then POL_SetupWindow_Close exit fi done # Download [ -d "$GOG_REPO" ] || mkdir -p "$GOG_REPO" cd "$GOG_REPO" || cd "$POL_USER_ROOT/tmp/" POL_Debug_Message "Will download into $PWD" download_piece () { # 1: URL # 2: filename # 3: MD5 hash # 4: Title # Failed piece from previous download, maybe reference MD5 was corrected? local FAILEDPIECE="$2.failed" if [ -n "$3" -a ! -e "$2" -a -e "$FAILEDPIECE" ]; then POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ "$(POL_MD5_file $FAILEDPIECE)" = "$3" ]; then mv "$FAILEDPIECE" "$2" fi fi [ -e "$2" ] && return local TMPPIECE="$2.part" while true; do POL_System_wget "$1" "$4" --no-check-certificate --load-cookies="$COOKIES" --continue -O "$TMPPIECE" POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4" if [ ! -e "$TMPPIECE" ]; then GOGDMSG="$(eval_gettext 'Download failed')" elif [ -n "$3" ] && [ "$(POL_MD5_file $TMPPIECE)" != "$3" ]; then GOGDMSG="$(eval_gettext 'Download seems to be corrupted')\n$(eval_gettext 'The file could also have been updated. If the problem persists, consider reporting the issue so that the script can be adjusted.')" mv "$TMPPIECE" "$FAILEDPIECE" else # Success mv "$TMPPIECE" "$2" [ -e "$FAILEDPIECE" ] && rm "$FAILEDPIECE" break fi POL_SetupWindow_question "$GOGDMSG\n$(eval_gettext 'Retry?')" "$TITLE" [ "$APP_ANSWER" = "TRUE" ] || POL_Debug_Fatal "$GOGDMSG" done } download_piece "$BASEURL/$GAME/${INDEXPREFIX}$INDEX" "$BASENAME.exe" "$1" "$BASENAME (1/$PIECES)" if [ $# -gt 1 ]; then local n=2 local offset=0 while [ $n -le $# ]; do if [ "${!n}" != "" ]; then download_piece "$BASEURL/$GAME/${INDEXPREFIX}$((INDEX+n-1))" "$BASENAME-$((n-1-offset)).bin" "${!n}" "$BASENAME ($n/$PIECES)" else let offset=$((offset+1)) fi let n=$((n+1)) done fi # Close session rm -f "$COOKIES" POL_GoG_downloaded="True" POL_GoG_location="$PWD/$BASENAME.exe" RepliesTuesday 5 August 2014 at 12:31
|
This site allows content generated by members, and we promptly remove any content that infringes copyright according to our Terms of Service. To report copyright infringement, please send a notice to dmca-notice@playonlinux.com