Skip to content

Instantly share code, notes, and snippets.

@5S
Created February 2, 2017 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5S/788ab557332ef0eec183e581e4fe75df to your computer and use it in GitHub Desktop.
Save 5S/788ab557332ef0eec183e581e4fe75df to your computer and use it in GitHub Desktop.
取得済みの manifest を比較して差分をダウンロードするやつ 現時点では b のインストゥルメンタルのみ対応
import os
import sqlite3
import sys
import threading
import urllib2
BASEURL = "http://storage.game.starlight-stage.jp"
def write_file(dest, data):
with open(dest, "w") as fd:
fd.write(data)
def download_acb(name, hash, keep):
res = urllib2.urlopen("{base}/dl/resources/High/Sound/Common/b/{hash}".format(base=BASEURL, hash=hash))
if keep.lower() in ("y", "ye", "yes"):
write_file("b/{name}".format(name=name.replace("b/", "")), res.read())
elif keep.lower() in ("n", "no"):
write_file("b/{hash}".format(hash=hash), res.read())
def record_search(location):
con = sqlite3.connect(location)
con.row_factory = sqlite3.Row
cur = con.cursor()
res = cur.execute("SELECT * FROM manifests WHERE name LIKE 'b%acb'")
dict = {}
for acb in res:
dict[acb[0]] = acb[1]
con.close()
return dict
args = sys.argv
if len(args) != 3:
print "Could not find manifest file."
print "First argument must be a newer manifest location, and second argument must be a older one."
sys.exit()
else:
newer = args[1]
older = args[2]
newerList = record_search(newer)
olderList = record_search(older)
diff = list(set(newerList) - set(olderList))
if len(diff) != 0:
for acb in diff:
print "name: {name}, hash: {hash}".format(name=acb, hash=newerList[acb])
print "{count} new file(s) were found.".format(count=len(diff))
dl = raw_input("Do you want to download? [Y|N]: ")
if dl.lower() in ("y", "ye", "yes"):
if os.path.exists("b") is False:
os.mkdir("b")
keep = raw_input("Do you want to keep real *.acb name? [Y|N]: ")
threads = []
for acb in diff:
thread = threading.Thread(target=download_acb, args=(acb, newerList[acb], keep))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
print "Downloaded {count} file(s).".format(count=len(diff))
elif dl.lower() in ("n", "no"):
sys.exit()
else:
print "There is no difference."
print "New song has not been added, or the order of the argument is incorrect."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment