Skip to content

Instantly share code, notes, and snippets.

@lambda-fairy
Created August 28, 2012 08:17
Show Gist options
  • Save lambda-fairy/3496108 to your computer and use it in GitHub Desktop.
Save lambda-fairy/3496108 to your computer and use it in GitHub Desktop.
Epic Technic downloader thingy
#!/usr/bin/env python
from argparse import ArgumentParser
from collections import namedtuple
import os
import requests
import yaml
TECHNIC_URL = 'https://github.com/TechnicPack/Technic/raw/master'
def main():
p = ArgumentParser(
description='Download the files that make up the Technic mod pack.',
epilog='Kudos for reading the docs, Kuangda!'
)
p.add_argument('pack_name', metavar='PACK', type=str, default='tekkit',
nargs='?', help='which mod pack to download (default: %(default)s)')
p.add_argument('--pack-version', metavar='VERSION', type=str, default=None,
nargs='?', help='which version to use (default: recommended build)')
args = p.parse_args()
# Download ALL the things
print('Grabbing file list')
for f in download_paths(args.pack_name, args.pack_version):
print('Downloading %s' % f.url)
with open(f.file_name, 'w') as out:
out.write(requests.get(f.url).content)
print('Ducks!')
class File(namedtuple('File', 'category name version extension')):
@property
def file_name(self):
return '%s-%s.%s' % (self.name, self.version, self.extension)
@property
def url(self):
# e.g. https://.../cheeseshop/cheeseshop-1.2.zip
return os.path.join(TECHNIC_URL, self.category, self.name, self.file_name)
def download_paths(pack_name, version=None):
r = requests.get(os.path.join(TECHNIC_URL, pack_name, 'modpack.yml'))
meta = yaml.load(r.text)
if version is None:
version = meta['recommended']
mods = extract_paths('mods', meta['builds'][version]['mods'], 'zip')
libs = extract_paths('Libraries', meta['lib-1'], 'jar')
return mods + libs
def extract_paths(category, manifest, extension):
return [File(category, name, version, extension)
for name, version in manifest.items()]
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print('\nCaught interrupt signal; quitting')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment