POL_GoG_download

Informations

Créateur Messages
Quentin PÂRIS Anonymous

Information

Cet installateur a été accepté par l'équipe.

Informations

Plate-formes :
Téléchargements : 316540
Wine: System

Retours d'expérience

Description

Ask the user about its credentials, then download all the pieces of a GOG.com game, checking their integrity using the provided MD5 hashes.

Parameters:
- 1: GOG ID of game (like the last component of its gamecard URL)
- (optional: --alternate BASENAME BASEINDEX)
- (optional: --patch)
- (optional: --bonus)
- 2..: lowercase MD5 hash of each piece

Specifying --alternate allows to download a secondary installer for the same game (example: Alone in the Dark 2 and 3 are secondary installers for Alone in the Dark)
Default BASENAME: setup_<GOG ID>
Default BASEINDEX: 0

Specify --patch for game updates URLs
Specify --bonus for bonus contents URLs

Some hashes can be an empty string ("") to disable hash checking (not recommended).

Pieces will be named BASENAME.exe, BASENAME-1.bin, BASENAME-2.bin, etc. and the function assigns $POL_GoG_location with the full path of the first piece.

Code source

#!/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:

Contribuer
Membre Messages
petch Mercredi 17 Février 2016 à 20:20
petch

Information

Cette mise à jour a été acceptée par l'équipe

Messages

bugfixes 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

Nouveau code source

#!/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"

Réponses

Edité par petch

petch Mercredi 17 Février 2016 à 20:03
petch

Warning

Cette mise à jour n'a pas été approuvée par l'équipe.
Utilisez-la à vos risques et périls

Messages

Use 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"

Nouveau code source

#!/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"

Réponses

Mystic-Mirage Dimanche 29 Novembre 2015 à 1:36
Mystic-Mirage

Messages

As 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.

Réponses

Dimanche 29 Novembre 2015 à 10:35
Until this script is fixed to work at all, no need to add languages support (that didn't exist when it was written)
trevorh Mardi 5 Aoüt 2014 à 17:25
trevorh Anonymous

Warning

Cette mise à jour n'a pas été approuvée par l'équipe.
Utilisez-la à vos risques et périls

Messages

Passing 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

Nouveau code source

#!/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"

Réponses

trevorh Mardi 5 Aoüt 2014 à 8:14
trevorh Anonymous

Warning

Cette mise à jour n'a pas été approuvée par l'équipe.
Utilisez-la à vos risques et périls

Messages

Allow 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

Nouveau code source

#!/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"

Réponses

Mardi 5 Aoüt 2014 à 12:31
Empty md5s already had a semantic: download but do not check the part hash (as documented). Maybe some other value should be used ("skip"?)
Also my feeling is that while this change provides a solution for the problem at hand, it does not provide a solution for other known deficiencies of those gog support scripts: ability to download a game, maybe for a specific language, maybe also download a patch, or extras (say the manual, if they didn't include it in the main installer),...
That would require a much more expressive interface, or be able to fetch meta-informations about downloadables, like lgogdownloader does...

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