A user-generated content downloader

315
Denmark
Denmark
Here's a Python script of mine that I'd like to share before the servers are shut down. Given a URL from the GT Sport Discover site, it'll try to download the user-generated replay (.dat), photo (.jpg), decal (.svg) or livery overview (.png) (be it car, suit or helmet.)

The replays are raw game files and not videos (i.e. .dat and not .mp4.) Strangely, and unlike on the PS file system, these are not encrypted.

"What am I supposed to do with a GTS replay file?" you might ask. At this time, not much (I haven't reverse engineered the file format, but things like replay duration, lobby and player names are in there.) But sometime in the future it might be playable on a PS4 emulator - imagine showing your grandkids the many dive-bombs, shameful ramming attempts and the countless cars you punted off track in just one race, back when cars and racing games were a thing. Sounds like quality time to me, pops!

Usage:
Make sure to have Python 3 installed. Copy the script and save it somewhere as 'get_ugc.py' On the GT Sport Discover page, right-click an item and select "Copy Link" and paste the url on the command line as a script argument.

Example: "py get_ugc.py https://www.gran-turismo.com/us/gts...tured/decal/decal/7096450/5918311625250603544" will download a nice .svg of Felix the Cat.

Python:
# get_ugc.py by Skinny McLean
#
# Downloads user-generated content given a GT Sport Discover URL:
#    Replay .dat
#    Decal .svg
#    Car, helmet and suit overview .png
#    Race and scape photo .jpg
#
# Usage:
#    py get_ugc.py URL
#

import sys
import urllib.request

ugc_base = r'https://s3.amazonaws.com/gt7sp-prod/'

def create_path(id):
    id = str(id)
    l = len(id)
    return id[l-2:l] + '/' + id[l-4:l-2] + '/' + id[l-6:l-4] + '/' + id

def fetch(url, filename):
    try:
        urllib.request.urlretrieve(url, filename)
        print("Done!")
    except:
        print("Error: Couldn't download file!")
  
def create_replay_url(replay_id):
    if len(str(replay_id)) > 10:    # race or qualifying replay?
        return ugc_base + 'replay' + '/' + create_path(replay_id) + '_0.dat'
    else:
        return ugc_base + 'ranking' + '/' + create_path(replay_id) + '_0.dat'
   
def create_decal_url(decal_id):
    return ugc_base + 'decal' + '/' + create_path(decal_id) + '_0.svg'   

def create_livery_url(livery_id):
    return ugc_base + 'livery' + '/' + create_path(livery_id) + '_1.png'   

def create_photo_url(photo_id):
    return ugc_base + 'photo' + '/' + create_path(photo_id) + '_0.jpg'   

def download_replay(replay_id):
    print("Fetching replay. Please wait...")
    fetch(create_replay_url(replay_id), str(replay_id) + '.dat')

def download_decal(decal_id):
    print("Fetching decal. Please wait...")
    fetch(create_decal_url(decal_id), str(decal_id) + '.svg')

def download_livery(livery_id):
    print("Fetching livery. Please wait...")
    fetch(create_livery_url(livery_id), str(livery_id) + '.png')

def download_photo(photo_id):
    print("Fetching photo. Please wait...")
    fetch(create_photo_url(photo_id), str(photo_id) + '.jpg')

if __name__ == "__main__":
    if len(sys.argv) >= 2:
        url = sys.argv[1]
        if url.count("/"):
            id = url[url.rindex("/")+1:]
            if url.count("decal"):
                download_decal(id)
            elif url.count("replay") or url.count("ranking"):
                download_replay(id)
            elif url.count("livery"):
                download_livery(id)
            elif url.count("photo"):
                download_photo(id)
            exit()
    print('Error: Missing url!')
 
Back