mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-06-06 12:51:57 +02:00
add 'Tags' and 'Category' options to SketchfabUpload node
This commit is contained in:
parent
7f29497b2f
commit
e665176209
1 changed files with 64 additions and 14 deletions
|
@ -100,6 +100,46 @@ class SketchfabUpload(desc.Node):
|
||||||
exclusive=True,
|
exclusive=True,
|
||||||
uid=[0],
|
uid=[0],
|
||||||
),
|
),
|
||||||
|
desc.ListAttribute(
|
||||||
|
elementDesc=desc.StringParam(
|
||||||
|
name='tag',
|
||||||
|
label='Tag',
|
||||||
|
description='Tag cannot be longer than 48 characters.',
|
||||||
|
value='',
|
||||||
|
uid=[0],
|
||||||
|
),
|
||||||
|
name="tags",
|
||||||
|
label="Tags",
|
||||||
|
description="Maximum of 42 separate tags.",
|
||||||
|
group="",
|
||||||
|
),
|
||||||
|
desc.ChoiceParam(
|
||||||
|
name='category',
|
||||||
|
label='Category',
|
||||||
|
description='Maximum of 2 categories.',
|
||||||
|
value='none',
|
||||||
|
values=['none',
|
||||||
|
'animals-pets',
|
||||||
|
'architecture',
|
||||||
|
'art-abstract',
|
||||||
|
'cars-vehicles',
|
||||||
|
'characters-creatures',
|
||||||
|
'cultural-heritage-history',
|
||||||
|
'electronics-gadgets',
|
||||||
|
'fashion-style',
|
||||||
|
'food-drink',
|
||||||
|
'furniture-home',
|
||||||
|
'music',
|
||||||
|
'nature-plants',
|
||||||
|
'news-politics',
|
||||||
|
'people',
|
||||||
|
'places-travel',
|
||||||
|
'science-technology',
|
||||||
|
'sports-fitness',
|
||||||
|
'weapons-military'],
|
||||||
|
exclusive=True,
|
||||||
|
uid=[0],
|
||||||
|
),
|
||||||
desc.BoolParam(
|
desc.BoolParam(
|
||||||
name='isPublished',
|
name='isPublished',
|
||||||
label='Publish',
|
label='Publish',
|
||||||
|
@ -139,18 +179,6 @@ class SketchfabUpload(desc.Node):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
def resolvedPaths(self, inputFiles):
|
|
||||||
paths = []
|
|
||||||
for inputFile in inputFiles:
|
|
||||||
if os.path.isdir(inputFile.value):
|
|
||||||
for path, subdirs, files in os.walk(inputFile.value):
|
|
||||||
for name in files:
|
|
||||||
paths.append(os.path.join(path, name))
|
|
||||||
else:
|
|
||||||
for f in glob.glob(inputFile.value):
|
|
||||||
paths.append(f)
|
|
||||||
return paths
|
|
||||||
|
|
||||||
def upload(self, apiToken, modelFile, data, chunk):
|
def upload(self, apiToken, modelFile, data, chunk):
|
||||||
modelEndpoint = 'https://api.sketchfab.com/v3/models'
|
modelEndpoint = 'https://api.sketchfab.com/v3/models'
|
||||||
f = open(modelFile, 'rb')
|
f = open(modelFile, 'rb')
|
||||||
|
@ -172,6 +200,18 @@ class SketchfabUpload(desc.Node):
|
||||||
chunk.logger.error(u'Upload failed with error: {}'.format(r.json()))
|
chunk.logger.error(u'Upload failed with error: {}'.format(r.json()))
|
||||||
raise RuntimeError()
|
raise RuntimeError()
|
||||||
|
|
||||||
|
def resolvedPaths(self, inputFiles):
|
||||||
|
paths = []
|
||||||
|
for inputFile in inputFiles:
|
||||||
|
if os.path.isdir(inputFile.value):
|
||||||
|
for path, subdirs, files in os.walk(inputFile.value):
|
||||||
|
for name in files:
|
||||||
|
paths.append(os.path.join(path, name))
|
||||||
|
else:
|
||||||
|
for f in glob.glob(inputFile.value):
|
||||||
|
paths.append(f)
|
||||||
|
return paths
|
||||||
|
|
||||||
def stopped(self):
|
def stopped(self):
|
||||||
return self._stopped
|
return self._stopped
|
||||||
|
|
||||||
|
@ -183,14 +223,21 @@ class SketchfabUpload(desc.Node):
|
||||||
if not chunk.node.inputFiles:
|
if not chunk.node.inputFiles:
|
||||||
chunk.logger.warning('Nothing to upload')
|
chunk.logger.warning('Nothing to upload')
|
||||||
return
|
return
|
||||||
|
if chunk.node.apiToken.value == '':
|
||||||
|
chunk.logger.error('Need API token.')
|
||||||
|
raise RuntimeError()
|
||||||
if len(chunk.node.title.value) > 48:
|
if len(chunk.node.title.value) > 48:
|
||||||
chunk.logger.error('Title cannot be longer than 48 characters.')
|
chunk.logger.error('Title cannot be longer than 48 characters.')
|
||||||
raise RuntimeError()
|
raise RuntimeError()
|
||||||
if len(chunk.node.description.value) > 1024:
|
if len(chunk.node.description.value) > 1024:
|
||||||
chunk.logger.error('Description cannot be longer than 1024 characters.')
|
chunk.logger.error('Description cannot be longer than 1024 characters.')
|
||||||
raise RuntimeError()
|
raise RuntimeError()
|
||||||
if chunk.node.apiToken.value == '':
|
tags = [ i.value for i in chunk.node.tags.value.values() ]
|
||||||
chunk.logger.error('Need API token.')
|
if all(len(i) > 48 for i in tags) and len(tags) > 0:
|
||||||
|
chunk.logger.error('Tags cannot be longer than 48 characters.')
|
||||||
|
raise RuntimeError()
|
||||||
|
if len(tags) > 42:
|
||||||
|
chunk.logger.error('Maximum of 42 separate tags.')
|
||||||
raise RuntimeError()
|
raise RuntimeError()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -198,11 +245,14 @@ class SketchfabUpload(desc.Node):
|
||||||
'name': chunk.node.title.value,
|
'name': chunk.node.title.value,
|
||||||
'description': chunk.node.description.value,
|
'description': chunk.node.description.value,
|
||||||
'license': chunk.node.license.value,
|
'license': chunk.node.license.value,
|
||||||
|
'tags': str(tags),
|
||||||
'isPublished': chunk.node.isPublished.value,
|
'isPublished': chunk.node.isPublished.value,
|
||||||
'isInspectable': chunk.node.isInspectable.value,
|
'isInspectable': chunk.node.isInspectable.value,
|
||||||
'private': chunk.node.isPrivate.value,
|
'private': chunk.node.isPrivate.value,
|
||||||
'password': chunk.node.password.value
|
'password': chunk.node.password.value
|
||||||
}
|
}
|
||||||
|
if chunk.node.category.value != 'none':
|
||||||
|
data.update({'categories': chunk.node.category.value})
|
||||||
chunk.logger.debug('Data to be sent: {}'.format(str(data)))
|
chunk.logger.debug('Data to be sent: {}'.format(str(data)))
|
||||||
|
|
||||||
# pack files into .zip to reduce file size and simplify process
|
# pack files into .zip to reduce file size and simplify process
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue