Skip to content

Commit

Permalink
Updated Movie and DBCheck
Browse files Browse the repository at this point in the history
Updated how DBCheck does its check and added event option to Movie, also added a build.bat for pyinstaller.
  • Loading branch information
MightyZanark committed Jul 5, 2022
1 parent 5b29515 commit f1f3187
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 70 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ __pycache__/
database/
movie/
sound/
Test.py
dist/
build/
*.spec
93 changes: 43 additions & 50 deletions DBCheck.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,52 @@
import os, requests, json
import os, requests, json, asyncio

cur_dir = os.getcwd()
max_test = 20
test_multi = 10
conf = r'.\config.json'
db_dir = r'.\database'

def update_db():
async def update_db():
# Checks if database folder exist, if it doesn't then create one
if not os.path.isdir(db_dir):
os.mkdir(db_dir)

print('Checking for database updates...')
await check_update()

# Downloads the new database alongside manifests
# print('Downloading database and manifests...')
download_manifest('db')
download_manifest('sound')
download_manifest('movie')
print(">> Update completed!")

# Downloads .db and sound/movie manifest to use for L2D, BGM extraction, etc.
def download_manifest(type):
with open(conf, 'r') as f:
data = json.load(f)
t = str(data[type])
hash = data["hash"]
manifest_name = t.split("/")[-1]
ver = str(data["TruthVersion"])

if type == 'db':
print("Downloading database...")
database = requests.get(f'{t}/{hash[:2]}/{hash}').content
with open('master.cdb', 'wb') as cdb:
cdb.write(database)
os.system(f'Coneshell_call.exe -cdb master.cdb "{db_dir}\\master.db"')
os.remove('master.cdb')
print("> Finished downloading database!\n")

else:
print(f'Downloading {manifest_name}...')
manifest = requests.get(t.replace('version', ver)).content
with open(f'{db_dir}\\{manifest_name}', 'wb') as m:
m.write(manifest)
print("> Download completed!\n")

async def check_update():
with open(conf, 'r+') as j:
c = json.load(j)
version = int(c["TruthVersion"])
Expand All @@ -31,24 +66,10 @@ def update_db():

# Checks if the TruthVersion is the same as in the latest_ver.json
if version == int(c["TruthVersion"]):

# Checks if master.db or manifests file exist. If it doesn't, then download them
# If anyone has a better way to approach this, you can do a pull request or make a suggestion from the "Issues" tab
while True:
if not os.path.isfile(f'{db_dir}\\master.db'):
print(f'No database file detected, downloading the latest: [{version}]')
download_manifest('db')
elif not os.path.isfile(f'{db_dir}\\moviemanifest'):
print("No moviemanifest file detected, downloading...")
download_manifest('movie')
elif not os.path.isfile(f'{db_dir}\\sound2manifest'):
print("No sound2manifest file detected, downloading...")
download_manifest('sound')
else:
print("> Database is up to date!")
break
print('> Database version is up to date!')

else:
print(f'New version available: [{version}], updating database...')
# Updates config.json
r = requests.get(str(c["masterdata"]).replace('version', str(version))).content
l = str(r).split(',')
Expand All @@ -57,38 +78,10 @@ def update_db():
c["hash"] = hash
j.seek(0)
json.dump(c, j, indent=1)

print('>> Update check completed!\n')
return

# Downloads the new database alongside manifests
print(f'New version available: [{version}], updating database...')
download_manifest('db')
download_manifest('sound')
download_manifest('movie')
print("> Update completed!")

# Downloads .db and sound/movie manifest to use for L2D, BGM extraction, etc.
def download_manifest(type):
with open(conf, 'r') as f:
data = json.load(f)
t = str(data[type])
hash = data["hash"]
manifest_name = t.split("/")[-1]
ver = str(data["TruthVersion"])

if type == 'db':
print("Downloading database...")
database = requests.get(f'{t}/{hash[:2]}/{hash}').content
with open('master.cdb', 'wb') as cdb:
cdb.write(database)
os.system(f'Coneshell_call.exe -cdb master.cdb "{db_dir}\\master.db"')
os.remove('master.cdb')
print("> Finished downloading database!\n")

else:
print(f'Downloading {manifest_name}...')
manifest = requests.get(t.replace('version',ver)).content
with open(f'{db_dir}\\{manifest_name}', 'wb') as m:
m.write(manifest)
print("> Download completed!\n")

if __name__ == '__main__':
update_db()
asyncio.run(update_db())
19 changes: 13 additions & 6 deletions Movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@
summon_dir = r'.\movie\summon'
summon_name = re.compile('character_\d+_000001\.usm')

event_dir = r'.\movie\event'
event_name = re.compile('story_5\d{5}[7-9]0[1-2]\.usm')

mov = {
'dir': {
'cutin': cutin_dir,
'l2d': l2d_dir,
'summon': summon_dir
'summon': summon_dir,
'event': event_dir
},
'name': {
'cutin': cutin_name,
'l2d': l2d_name,
'summon': summon_name
'summon': summon_name,
'event': event_name
}
}

Expand All @@ -36,6 +41,7 @@ def generate_list(mov_name: str, dir_name):
if not os.path.isdir(dir_name):
os.makedirs(dir_name)

# print(mov_name)
with open(manifest_path, 'r') as m:
for lines in m:
l = lines.split(',')
Expand All @@ -50,6 +56,7 @@ def generate_list(mov_name: str, dir_name):

# Downloads all video files that doesn't exist yet
def download_file(name, hash):
# print(f'Filename is {name}')
if not os.path.isfile(name) and not os.path.isfile(f'.\\{str(name).split(".")[1]}.mp4'):
print(f'Downloading {name}...')
r = requests.get(f'{movie_url}/{hash[:2]}/{hash}').content
Expand All @@ -66,8 +73,8 @@ def convert_file(name):
if not os.path.isfile(f'.\\{str(name).split(".")[1]}.mp4'):
os.system(f'UsmToolkit convert -c "{name}" -o "{os.path.dirname(name)}"')

else:
print(f'File [.\\{str(name).split(".")[1]}.mp4] already exists')
# else:
# print(f'File [.\\{str(name).split(".")[1]}.mp4] already exists')

except Exception as e:
print(f'An ERROR occured\n{e}')
Expand All @@ -80,7 +87,7 @@ def main():
input("Press ENTER to exit this window")

else:
mov_type = input("Select type: 'cutin' 'l2d' 'summon'\n")
mov_type = input("Select type: 'cutin' 'l2d' 'summon' 'event'\n")

try:
dir_name = mov['dir'][mov_type.strip()]
Expand All @@ -102,7 +109,7 @@ def main():
input(">> Download and conversion completed!\nPress ENTER to exit this window")

except:
print("> INVALID TYPE! <\nCurrent types are only 'cutin', 'l2d', or 'summon'\n")
print("> INVALID TYPE! <\nCurrent types are only 'cutin', 'l2d', 'summon', or 'event'\n")
input("Press ENTER to exit this window")


Expand Down
8 changes: 5 additions & 3 deletions Run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import asyncio
from DBCheck import update_db
from Movie import main as movie
from Sound import main as sound

def main():
async def main():
print("\n---------- Priconne Utilities ----------\n")
print("> DBCheck: Checks if DB is up to date, recommended to do first time")
print("> Movie: Downloads L2D, UB Cutin, or Summon animations depending on what you want")
Expand All @@ -10,7 +12,7 @@ def main():
ans = input("Choose action: 'DBCheck' 'Movie'\n")
if str(ans).lower().strip() == 'dbcheck':
print("'DBCheck' option chosen, checking and updating DB...\n")
update_db()
await update_db()
input("\nAll task is done!\nPress ENTER to exit this window")

elif str(ans).lower().strip() == 'movie':
Expand All @@ -22,4 +24,4 @@ def main():
input("Press ENTER to exit this window")

if __name__ == '__main__':
main()
asyncio.run(main())
19 changes: 10 additions & 9 deletions Sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@

bgm_dir = r'.\sound\bgm'
bgm_name = re.compile('bgm_.+\.(acb||awb)')
bgm_extracted_name = re.compile('bgm_.+\.m4a')

sound = {
'dir': {
'bgm': bgm_dir
},
'name': {
'bgm': bgm_name
},
'extracted': {
'bgm': bgm_extracted_name
}
}

Expand All @@ -40,14 +36,19 @@ def generate_list(snd_name, snd_dir):


def download_file(name: str, hash):
if not os.path.isfile(name) and not os.path.isfile(f'.\\{name.split(".")[1]}.m4a'):
dirName = os.path.dirname(name)
realFileName = name.split('\\')[-1]
nameCheck = re.compile(f'{realFileName.split(".")[0]}.+?m4a')
checked = check_file(nameCheck, dirName)

if not os.path.isfile(name) and checked is None:
print(f'Downloading {name}...')
r = requests.get(f'{sound_url}/{hash[:2]}/{hash}').content
with open(name, 'wb') as f:
f.write(r)

else:
print(f'File {name} already exists')
# else:
# print(f'File {name} already exists')

def convert_file(name: str):
dir_name = os.path.dirname(name)
Expand All @@ -57,7 +58,7 @@ def convert_file(name: str):
acbInternal = os.path.join(acbUnpackDir, 'internal')
acbExternal = os.path.join(acbUnpackDir, 'external')

nameCheck = re.compile(f'{realFilename.split(".")[0]}.+\.m4a')
nameCheck = re.compile(f'{realFilename.split(".")[0]}.+?m4a')
checked = check_file(nameCheck, dir_name)

if checked is None:
Expand Down Expand Up @@ -96,7 +97,7 @@ def convert_file(name: str):
def check_file(fn, fd):
for file in os.listdir(fd):
a = re.search(fn, file)
if a is not None:
if a:
return a.group()

def main():
Expand Down
1 change: 1 addition & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyinstaller -y --onefile Run.py
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"TruthVersion": 10039200,
"hash": "b6454316730af52362b58b656129a613",
"TruthVersion": 10039500,
"hash": "6570a400cacce97dc5db5bb4a9dafe0b",
"assetmanifest": "http://prd-priconne-redive.akamaized.net/dl/Resources/version/Jpn/AssetBundles/Windows/manifest/manifest_assetmanifest",
"masterdata": "http://prd-priconne-redive.akamaized.net/dl/Resources/version/Jpn/AssetBundles/Windows/manifest/masterdata_assetmanifest",
"movie": "http://prd-priconne-redive.akamaized.net/dl/Resources/version/Jpn/Movie/PC/High/manifest/moviemanifest",
Expand Down

0 comments on commit f1f3187

Please sign in to comment.