nabetaの日記: 遅まきながら艦これをする
んで、Chrome のキャッシュに溜まるデータを取り出すスクリプトを作る(←まじめに艦隊指揮とれよ)
引数にブラウザのキャッシュのディレクトリを指定すると、フラッシュのファイルとMP3のファイルを探して、ディレクトリにコピーするだけの機能で、現在、艦娘のボイスファイル(mp3)と艦娘との名寄せの方法に悩んでいるところ(MP3を再生して声を聞けば判るのだけど、それではスクリプト化した意味がないし)
# -*- mode: python; coding: utf-8 -*-
#
# Time-stamp:
#
#
import os
import sys
import glob
import shutil
import hashlib
# for debug
#
#
def buffer2hexlist(buffer, start, count):
result = []
for item in range(count):
result.append('%02X' % ord(buffer[start + item]))
return result
# file signature string
#
#
def fileSignature(filePath):
magic = {
'SWF': [ '43', '57', '53' ],
'ID3': [ '49', '44', '33' ],
'MP3': [ 'FF', 'FB' ],
'JPG': [ 'FF', 'D8' ],
'BMP': [ '42', '4D' ],
'GIF': [ '47', '49', '46', '38' ]
}
with open(filePath, "rb") as file:
data = file.read(8)
blist = buffer2hexlist(data, 0, 8)
file.close()
for ftype, signature in magic.iteritems():
flag = 1
for id,val in zip(signature, blist):
if id != val:
flag = 0
break
if flag == 1:
return ftype
return 'UNKNOWN'
# move to your storage
#
#
def retrieveFile( fileType, fileName ):
storageDir = os.path.join(".",fileType)
if not os.path.exists(storageDir):
os.makedirs(storageDir)
dupfile = os.path.join(storageDir,fileName)
if not os.path.exists(dupfile):
shutil.copyfile(f, dupfile)
else:
print "already have"
return
# Chrome's default cache
# "c:/Users/Admiral/AppData/Local/Google/Chrome/User Data/Default/Cache"
#
# USAGE:
# $ python kanColleCache.py "c:/Users/Admiral/AppData/Local/Google/Chrome/User Data/Default/Cache"
#
if __name__ == '__main__':
for path in sys.argv[1:]:
for fname in os.listdir(path):
f = os.path.join(path,fname)
if os.path.isdir(f):
continue
hash = hashlib.md5( os.path.join(path,f) ).hexdigest()
fsig = fileSignature(f)
print "%(hash)s : %(signature)s %(filename)s" % { 'hash':hash, 'signature':fsig, 'filename':fname}
if fsig == 'SWF':
retrieveFile('SWF', hash+".swf")
elif fsig == 'MP3':
retrieveFile('MP3', hash+".mp3")
遅まきながら艦これをする More ログイン