# You may distribute this under the terms of the MIT License.
dl_codes = {"pico8": "7tiann/pico-8_", "picotron": "8pwrtp/picotron_", "voxatron": "5r8npa/voxatron_"}
dl_os = {"osx": "osx", "windows": "windows", "linux": "amd64", "linux_x86": "i386", "raspi": "raspi"}
dl_url = 'https://lexaloffle.com/dl/'
import requests
import pick



def download(game: str, version: str, os: str):
    url = f"{dl_url}{dl_codes[game]}{version}_{dl_os[os]}.zip"
    r = requests.get(url)
    if r.status_code == 200:
        return r.content
    elif r.status_code == 404:
        raise FileNotFoundError(f"Url \"{url}\" was not found.")

def main():
    game, _ = pick.pick(list(dl_codes.keys()), title='Game:')
    os, _ = pick.pick(list(dl_os.keys()), title='OS:')
    print('Version: (this can be obtained on Lexaloffle\'s website, don\'t include the v at the start)')
    version = input('> ')
    with open('game.zip', 'wb') as f:
        f.write(download(game, version, os))
    print('Downloaded to game.zip.')
    print('Game downloaded!')
if __name__ == '__main__':
    main()
