Guest User

ssdl.py

a guest
Jun 12th, 2016
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.39 KB | None | 0 0
  1. import sqlite3
  2. import sys
  3. import os
  4. import urllib
  5.  
  6. if len(sys.argv) <= 2 :
  7.     # Print program information if there aren't enough arguments
  8.     print sys.argv[0] + " database pattern"
  9.     print "pattern is a SQL 'LIKE' pattern. i.e. %.unity3d or b/%"
  10. else :
  11.     # Create a database connection for the database file provided
  12.     conn = sqlite3.connect(sys.argv[1])
  13.     c = conn.cursor()
  14.     # Query for all files that match the given pattern
  15.     c.execute('SELECT name, hash FROM manifests WHERE name LIKE "' + sys.argv[2] + '"')
  16.    
  17.     # Create the download directory if it doesn't already exist
  18.     if not os.path.exists("dl") :
  19.         os.makedirs("dl")
  20.    
  21.     count = 0
  22.     failures = 0
  23.     # Loop through all matching rows
  24.     for row in c :
  25.         count += 1
  26.         name = row[0]
  27.         hash = row[1]
  28.        
  29.         try :
  30.             # Download the file from the correct location based on its file extension
  31.             if name.endswith(".unity3d") :
  32.                 print "Downloading asset bundle " + name
  33.                 urllib.urlretrieve("http://storage.game.starlight-stage.jp/dl/resources/High/AssetBundles/Android/" + hash, "dl/" + name)
  34.             elif name.endswith(".acb") :
  35.                 # Audio files have an extra directory name in the front that needs to be split out
  36.                 print "Downloading audio " + name
  37.                 slashpos = name.index("/")
  38.                 dir = name[:slashpos + 1]
  39.                 name = name[slashpos + 1:]
  40.                 urllib.urlretrieve("http://storage.game.starlight-stage.jp/dl/resources/High/Sound/Common/" + dir + hash, "dl/" + name)
  41.             elif name.endswith(".mdb") or name.endswith(".bdb") :
  42.                 print "Downloading database " + name
  43.                 urllib.urlretrieve("http://storage.game.starlight-stage.jp/dl/resources/Generic/" + hash, "dl/" + name)
  44.             else :
  45.                 print "Skipping unknown file " + name
  46.                 failures += 1
  47.                 count -= 1
  48.         except IOError as err :
  49.             # Something went wrong downloading or saving the file
  50.             print "Error downloading " + name + ": " + str(err)
  51.             failures += 1
  52.             count -= 1
  53.     # All files are done, so print the success/failure count
  54.     print "Downloaded " + str(count) + " file(s)"
  55.     if failures > 0 :
  56.         print "Failed to download " + str(failures) + " file(s)"
Add Comment
Please, Sign In to add comment