2021-12-09 03:41:19 +00:00
|
|
|
# Purpose:
|
2021-12-09 16:57:05 +00:00
|
|
|
# This file goes through all batches, renames, and sorts all nft files to a Complete_Collection folder in Blend_My_NFTs
|
|
|
|
|
2021-12-09 03:41:19 +00:00
|
|
|
import bpy
|
|
|
|
import os
|
2021-12-09 12:52:32 +00:00
|
|
|
import copy
|
2021-12-09 03:41:19 +00:00
|
|
|
import json
|
2022-02-03 23:48:52 +00:00
|
|
|
import shutil
|
2022-03-12 17:02:01 +00:00
|
|
|
from . import Metadata
|
2021-12-09 03:41:19 +00:00
|
|
|
|
2022-01-09 01:33:25 +00:00
|
|
|
removeList = [".gitignore", ".DS_Store"]
|
|
|
|
|
2022-01-28 22:20:58 +00:00
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
def getNFType(nftBatch_save_path):
|
2021-12-09 03:41:19 +00:00
|
|
|
images = False
|
|
|
|
animations = False
|
|
|
|
models = False
|
|
|
|
metaData = False
|
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
batch1 = [x for x in os.listdir(nftBatch_save_path) if (x not in removeList)][0] # Gets first Batch and ignores removeList files
|
|
|
|
batchContent = os.listdir(os.path.join(nftBatch_save_path, batch1))
|
2021-12-31 04:08:47 +00:00
|
|
|
batchContent = [x for x in batchContent if (x not in removeList)]
|
|
|
|
|
2021-12-09 03:41:19 +00:00
|
|
|
if "Images" in batchContent:
|
|
|
|
images = True
|
|
|
|
if "Animations" in batchContent:
|
|
|
|
animations = True
|
|
|
|
if "Models" in batchContent:
|
|
|
|
models = True
|
2021-12-10 02:58:11 +00:00
|
|
|
if "BMNFT_metaData" in batchContent:
|
2021-12-09 03:41:19 +00:00
|
|
|
metaData = True
|
|
|
|
|
|
|
|
return images, animations, models, metaData
|
|
|
|
|
2021-12-10 02:58:11 +00:00
|
|
|
def getMetaDataDirty(completeMetaDataPath, i):
|
2022-01-28 22:20:58 +00:00
|
|
|
"""
|
2021-12-10 02:58:11 +00:00
|
|
|
Retrieves a given batches data determined by renderBatch in config.py
|
2022-01-28 22:20:58 +00:00
|
|
|
"""
|
2021-12-10 02:58:11 +00:00
|
|
|
|
|
|
|
file_name = os.path.join(completeMetaDataPath, i)
|
|
|
|
metaDataDirty = json.load(open(file_name))
|
|
|
|
|
|
|
|
name = metaDataDirty["name"]
|
|
|
|
NFT_DNA = metaDataDirty["NFT_DNA"]
|
2021-12-14 21:16:36 +00:00
|
|
|
NFT_Variants = metaDataDirty["NFT_Variants"]
|
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
for i in NFT_Variants:
|
|
|
|
x = NFT_Variants[i]
|
|
|
|
NFT_Variants[i] = x.split("_")[0]
|
2021-12-10 02:58:11 +00:00
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
return name, NFT_DNA, NFT_Variants
|
2021-12-10 02:58:11 +00:00
|
|
|
|
|
|
|
def sendMetaDataToJson(metaDataDict, metaDataPath, jsonName):
|
|
|
|
jsonMetaData = json.dumps(metaDataDict, indent=1, ensure_ascii=True)
|
|
|
|
with open(os.path.join(metaDataPath, jsonName), 'w') as outfile:
|
|
|
|
outfile.write(jsonMetaData + '\n')
|
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
def renameMetaData(rename_MetaData_Variables):
|
|
|
|
metaDataListOld = os.listdir(rename_MetaData_Variables.completeMetaDataPath)
|
|
|
|
cardanoMetaDataPath = os.path.join(rename_MetaData_Variables.completeCollPath, "Cardano_metaData")
|
|
|
|
solanaMetaDataPath = os.path.join(rename_MetaData_Variables.completeCollPath, "Solana_metaData")
|
|
|
|
erc721MetaDataPath = os.path.join(rename_MetaData_Variables.completeCollPath, "Erc721_metaData")
|
2021-12-10 02:58:11 +00:00
|
|
|
|
|
|
|
for i in metaDataListOld:
|
2022-03-11 01:03:20 +00:00
|
|
|
name, NFT_DNA, NFT_Variants = getMetaDataDirty(rename_MetaData_Variables.completeMetaDataPath, i)
|
2021-12-10 02:58:11 +00:00
|
|
|
|
|
|
|
file_name = os.path.splitext(i)[0]
|
|
|
|
file_num = file_name.split("_")[1]
|
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
if rename_MetaData_Variables.cardanoMetaDataBool:
|
2021-12-10 02:58:11 +00:00
|
|
|
if not os.path.exists(cardanoMetaDataPath):
|
2021-12-10 04:01:48 +00:00
|
|
|
os.mkdir(cardanoMetaDataPath)
|
2021-12-10 02:58:11 +00:00
|
|
|
|
2021-12-10 04:01:48 +00:00
|
|
|
cardanoJsonNew = "Cardano_" + i
|
|
|
|
cardanoNewName = name.split("_")[0] + "_" + str(file_num)
|
|
|
|
|
2022-03-12 17:18:41 +00:00
|
|
|
metaDataDictCardano = Metadata.returnCardanoMetaData(cardanoNewName, NFT_DNA, NFT_Variants, rename_MetaData_Variables.custom_Fields_File, rename_MetaData_Variables.enableCustomFields, rename_MetaData_Variables.cardano_description)
|
2021-12-10 02:58:11 +00:00
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
sendMetaDataToJson(metaDataDictCardano, cardanoMetaDataPath, cardanoJsonNew,)
|
|
|
|
|
|
|
|
if rename_MetaData_Variables.solanaMetaDataBool:
|
2021-12-10 02:58:11 +00:00
|
|
|
if not os.path.exists(solanaMetaDataPath):
|
|
|
|
os.mkdir(solanaMetaDataPath)
|
|
|
|
|
|
|
|
solanaJsonNew = "Solana_" + i
|
|
|
|
solanaNewName = name.split("_")[0] + "_" + str(file_num)
|
|
|
|
|
2022-03-12 17:18:41 +00:00
|
|
|
metaDataDictSolana = Metadata.returnSolanaMetaData(solanaNewName, NFT_DNA, NFT_Variants, rename_MetaData_Variables.custom_Fields_File, rename_MetaData_Variables.enableCustomFields, rename_MetaData_Variables.solana_description)
|
2022-03-11 01:03:20 +00:00
|
|
|
|
2021-12-10 02:58:11 +00:00
|
|
|
sendMetaDataToJson(metaDataDictSolana, solanaMetaDataPath, solanaJsonNew)
|
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
if rename_MetaData_Variables.erc721MetaData:
|
2021-12-10 02:58:11 +00:00
|
|
|
if not os.path.exists(erc721MetaDataPath):
|
|
|
|
os.mkdir(erc721MetaDataPath)
|
|
|
|
|
2021-12-10 04:01:48 +00:00
|
|
|
erc721JsonNew = "Erc721_" + i
|
|
|
|
erc721NewName = name.split("_")[0] + "_" + str(file_num)
|
2021-12-10 02:58:11 +00:00
|
|
|
|
2022-03-12 17:18:41 +00:00
|
|
|
metaDataDictErc721 = Metadata.returnErc721MetaData(erc721NewName, NFT_DNA, NFT_Variants, rename_MetaData_Variables.custom_Fields_File, rename_MetaData_Variables.enableCustomFields, rename_MetaData_Variables.erc721_description)
|
2022-03-11 01:03:20 +00:00
|
|
|
|
2021-12-10 04:01:48 +00:00
|
|
|
sendMetaDataToJson(metaDataDictErc721, erc721MetaDataPath, erc721JsonNew)
|
2021-12-09 16:57:05 +00:00
|
|
|
return
|
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
def reformatNFTCollection(refactor_panel_input):
|
|
|
|
images, animations, models, metaData = getNFType(refactor_panel_input.nftBatch_save_path)
|
2022-02-02 15:37:42 +00:00
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
global completeCollPath
|
|
|
|
global completeMetaDataPath
|
2021-12-09 03:41:19 +00:00
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
completeCollPath = os.path.join(refactor_panel_input.save_path, "Blend_My_NFTs Output", "Complete_Collection")
|
2021-12-09 12:52:32 +00:00
|
|
|
completeImagePath = os.path.join(completeCollPath, "Images")
|
|
|
|
completeAnimationsPath = os.path.join(completeCollPath, "Animations")
|
|
|
|
completeModelsPath = os.path.join(completeCollPath, "Models")
|
2021-12-10 02:58:11 +00:00
|
|
|
completeMetaDataPath = os.path.join(completeCollPath, "BMNFT_metaData")
|
2021-12-09 12:52:32 +00:00
|
|
|
|
2021-12-09 16:28:28 +00:00
|
|
|
if not os.path.exists(completeCollPath):
|
|
|
|
os.mkdir(completeCollPath)
|
|
|
|
if images and not os.path.exists(completeImagePath):
|
2021-12-09 12:52:32 +00:00
|
|
|
os.mkdir(completeImagePath)
|
2021-12-09 16:28:28 +00:00
|
|
|
if animations and not os.path.exists(completeAnimationsPath):
|
2021-12-09 12:52:32 +00:00
|
|
|
os.mkdir(completeAnimationsPath)
|
2021-12-09 16:28:28 +00:00
|
|
|
if models and not os.path.exists(completeModelsPath):
|
2021-12-09 12:52:32 +00:00
|
|
|
os.mkdir(completeModelsPath)
|
2021-12-09 16:28:28 +00:00
|
|
|
if metaData and not os.path.exists(completeMetaDataPath):
|
2021-12-09 12:52:32 +00:00
|
|
|
os.mkdir(completeMetaDataPath)
|
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
batchListDirty = os.listdir(refactor_panel_input.nftBatch_save_path)
|
2021-12-09 03:41:19 +00:00
|
|
|
batchList = [x for x in batchListDirty if (x not in removeList)]
|
|
|
|
|
2021-12-09 16:28:28 +00:00
|
|
|
imageCount = 1
|
|
|
|
animationCount = 1
|
|
|
|
modelCount = 1
|
|
|
|
dataCount = 1
|
2021-12-09 03:41:19 +00:00
|
|
|
for i in batchList:
|
|
|
|
if images:
|
2022-03-11 01:03:20 +00:00
|
|
|
imagesDir = os.path.join(refactor_panel_input.nftBatch_save_path, i, "Images")
|
2021-12-09 03:41:19 +00:00
|
|
|
imagesList = sorted(os.listdir(imagesDir))
|
|
|
|
|
2021-12-09 12:52:32 +00:00
|
|
|
for j in imagesList:
|
2022-03-11 01:03:20 +00:00
|
|
|
imageOldPath = os.path.join(refactor_panel_input.nftBatch_save_path, i, "Images", j)
|
2021-12-09 16:28:28 +00:00
|
|
|
nameOldDirty = copy.deepcopy(os.path.splitext(j)[0])
|
|
|
|
extension = copy.deepcopy(os.path.splitext(j)[1])
|
|
|
|
nameOldClean = nameOldDirty.split("_")[0]
|
2021-12-09 03:41:19 +00:00
|
|
|
|
2021-12-09 16:28:28 +00:00
|
|
|
nameNew = nameOldClean + "_" + str(imageCount)
|
|
|
|
imageNewPath = os.path.join(completeImagePath, nameNew + extension)
|
2021-12-09 03:41:19 +00:00
|
|
|
|
2021-12-09 16:28:28 +00:00
|
|
|
os.rename(imageOldPath, imageNewPath)
|
2021-12-09 03:41:19 +00:00
|
|
|
|
2021-12-09 16:28:28 +00:00
|
|
|
imageCount += 1
|
2021-12-09 03:41:19 +00:00
|
|
|
|
|
|
|
if animations:
|
2022-03-11 01:03:20 +00:00
|
|
|
animationsDir = os.path.join(refactor_panel_input.nftBatch_save_path, i, "Animations")
|
2021-12-09 16:28:28 +00:00
|
|
|
animationsList = sorted(os.listdir(animationsDir))
|
|
|
|
|
|
|
|
for j in animationsList:
|
2022-03-11 01:03:20 +00:00
|
|
|
animationOldPath = os.path.join(refactor_panel_input.nftBatch_save_path, i, "Animations", j)
|
2021-12-09 16:28:28 +00:00
|
|
|
nameOldDirty = copy.deepcopy(os.path.splitext(j)[0])
|
|
|
|
extension = copy.deepcopy(os.path.splitext(j)[1])
|
|
|
|
nameOldClean = nameOldDirty.split("_")[0]
|
|
|
|
|
|
|
|
nameNew = nameOldClean + "_" + str(animationCount)
|
|
|
|
animationNewPath = os.path.join(completeAnimationsPath, nameNew + extension)
|
|
|
|
|
|
|
|
os.rename(animationOldPath, animationNewPath)
|
|
|
|
|
|
|
|
animationCount += 1
|
|
|
|
|
2021-12-09 03:41:19 +00:00
|
|
|
if models:
|
2022-03-11 01:03:20 +00:00
|
|
|
modelsDir = os.path.join(refactor_panel_input.nftBatch_save_path, i, "Models")
|
2021-12-09 16:28:28 +00:00
|
|
|
modelsList = sorted(os.listdir(modelsDir))
|
|
|
|
|
|
|
|
for j in modelsList:
|
2022-03-11 01:03:20 +00:00
|
|
|
modelOldPath = os.path.join(refactor_panel_input.nftBatch_save_path, i, "Models", j)
|
2021-12-09 16:28:28 +00:00
|
|
|
nameOldDirty = copy.deepcopy(os.path.splitext(j)[0])
|
|
|
|
extension = copy.deepcopy(os.path.splitext(j)[1])
|
|
|
|
nameOldClean = nameOldDirty.split("_")[0]
|
|
|
|
|
|
|
|
nameNew = nameOldClean + "_" + str(modelCount)
|
|
|
|
modelsNewPath = os.path.join(completeModelsPath, nameNew + extension)
|
|
|
|
|
|
|
|
os.rename(modelOldPath, modelsNewPath)
|
|
|
|
|
|
|
|
modelCount += 1
|
|
|
|
|
|
|
|
if metaData:
|
2022-03-11 01:03:20 +00:00
|
|
|
dataDir = os.path.join(refactor_panel_input.nftBatch_save_path, i, "BMNFT_metaData")
|
2021-12-09 16:28:28 +00:00
|
|
|
dataList = sorted(os.listdir(dataDir))
|
|
|
|
|
|
|
|
for j in dataList:
|
2022-03-11 01:03:20 +00:00
|
|
|
dataOldPath = os.path.join(refactor_panel_input.nftBatch_save_path, i, "BMNFT_metaData", j)
|
2021-12-09 16:28:28 +00:00
|
|
|
nameOldDirty = copy.deepcopy(os.path.splitext(j)[0])
|
|
|
|
extension = copy.deepcopy(os.path.splitext(j)[1])
|
|
|
|
nameOldClean = nameOldDirty.split("_")[0]
|
|
|
|
|
|
|
|
nameNew = nameOldClean + "_" + str(dataCount)
|
|
|
|
dataNewPath = os.path.join(completeMetaDataPath, nameNew + extension)
|
|
|
|
os.rename(dataOldPath, dataNewPath)
|
|
|
|
|
2021-12-22 04:51:04 +00:00
|
|
|
BMFNT_Meta = json.load(open(dataNewPath))
|
|
|
|
name = BMFNT_Meta["name"].split("_")[0]
|
|
|
|
BMFNT_Meta["name"] = name + "_" + str(dataCount)
|
|
|
|
jsonMetaData = json.dumps(BMFNT_Meta, indent=1, ensure_ascii=True)
|
|
|
|
|
|
|
|
with open(dataNewPath, 'w') as outfile:
|
|
|
|
outfile.write(jsonMetaData + '\n')
|
|
|
|
|
2021-12-09 16:28:28 +00:00
|
|
|
dataCount += 1
|
2021-12-09 03:41:19 +00:00
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
print(f"All NFT files stored and sorted to the Complete_Collection folder in {refactor_panel_input.save_path}")
|
|
|
|
|
|
|
|
class rename_MetaData_Variables:
|
|
|
|
completeCollPath = completeCollPath
|
|
|
|
completeMetaDataPath = completeMetaDataPath
|
|
|
|
|
|
|
|
cardanoMetaDataBool = refactor_panel_input.cardanoMetaDataBool
|
|
|
|
solanaMetaDataBool = refactor_panel_input.solanaMetaDataBool
|
|
|
|
erc721MetaData = refactor_panel_input.erc721MetaData
|
|
|
|
|
|
|
|
custom_Fields_File = refactor_panel_input.custom_Fields_File
|
|
|
|
enableCustomFields = refactor_panel_input.enableCustomFields
|
|
|
|
|
|
|
|
|
|
|
|
cardano_description = refactor_panel_input.cardano_description
|
|
|
|
solana_description = refactor_panel_input.solana_description
|
|
|
|
erc721_description = refactor_panel_input.erc721_description
|
|
|
|
|
2021-12-09 03:41:19 +00:00
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
renameMetaData(rename_MetaData_Variables)
|
2021-12-10 02:58:11 +00:00
|
|
|
|
2022-03-11 01:03:20 +00:00
|
|
|
shutil.rmtree(refactor_panel_input.nftBatch_save_path)
|