if "query" not in options: continue setItems = lu.filterByQueryString(items, options["query"]) if len(setItems) > 0: print("%s results found for '%s'" % (len(setItems), options["query"])) else: print("Warning: '%s' produces no results" % options["query"]) continue # limit the results if specified if "limit" in options and len(setItems) > options["limit"]: setItems = setItems[:options["limit"]] # Write set file outjson = [item["index"] for item in setItems] if len(setItems) > 10: setOutFile = OUTPUT_SET_DIR + keyName + ".json" setOutFileRel = OUTPUT_SET_DIR_REL + keyName + ".json" io.writeJSON(setOutFile, outjson) jsonsets[keyName] = {"src": setOutFileRel} # if only a small amount of items, don't bother to put it in its own json file else: jsonsets[keyName] = {"indices": outjson} # Write config file outjson = { "sets": jsonsets } io.writeJSON(CONFIG_FILE, outjson, pretty=True, prepend="_.extend(CONFIG, ", append=");")
soundConfig["filename"] = os.path.basename(audioFilename) soundConfig["spriteFilename"] = os.path.basename(dataFilename) soundConfig.pop("filenames", None) layout = soundOptions["layout"] if layout == "years": _soundConfig, soundData = getYearSounds(spriteData) soundConfig.update(_soundConfig) else: print("Invalid layout: %s" % layout) continue # Write sound file if soundData is not None: soundOutFile = OUTPUT_SOUND_DIR + soundKey + ".json" io.writeJSON(soundOutFile, soundData) soundConfig["src"] = OUTPUT_SOUND_DIR_REL + soundKey + ".json" soundConfig["isSprite"] = isSprite jsonSounds[soundKey] = soundConfig # Write config file outjson = {"sounds": jsonSounds} io.writeJSON(CONFIG_FILE, outjson, pretty=True, prepend="_.extend(CONFIG, ", append=");")
def makeSpriteFile(audioFn, dataFn, filenames, dur, matchDbValue=-9, reverb=0, quantities=None, sampleWidth=2, sampleRate=48000, channels=2): totalDuration = dur * len(filenames) if quantities is not None: totalDuration *= len(quantities) baseAudio = getBlankAudio(totalDuration, sampleWidth, sampleRate, channels) sprites = [] for i, fn in enumerate(filenames): audio = getAudio(fn, sampleWidth, sampleRate, channels) audio = matchDb(audio, matchDbValue) # normalize audio if reverb > 0: audio = applyReverb(audio, reverb) if quantities is not None: for j, q in enumerate(quantities): sectionStart = i * len(quantities) * dur + j * dur sectionBaseAudio = getBlankAudio(dur, sampleWidth, sampleRate, channels) volumeRange = (0.2, 0.8) count = q["count"] clipDur = int(1.0 * dur / q["count"]) audioClip = getAudioClip(audio, 0, clipDur, clipFadeIn=10, clipFadeOut=10) for k in range(q["count"]): p = 1.0 * k / (q["count"]-1) volume = mu.lerp((volumeRange[1], volumeRange[0]), p) qstart = k * clipDur dbAdjust = volumeToDb(volume) modifiedAudio = audioClip.apply_gain(dbAdjust) sectionBaseAudio = sectionBaseAudio.overlay(modifiedAudio, position=qstart) audioDur = len(sectionBaseAudio) # clip audio if necessary if audioDur > dur: sectionBaseAudio = sectionBaseAudio[:dur] # fade in and out sectionBaseAudio = sectionBaseAudio.fade_in(10).fade_out(20) baseAudio = baseAudio.overlay(sectionBaseAudio, position=sectionStart) sprite = { "src": os.path.basename(fn), "start": sectionStart, "dur": dur, "quantity": q["name"] } sprites.append(sprite) else: start = i*dur audioDur = len(audio) # clip audio if necessary if audioDur > dur: audio = audio[:dur] # fade in and out audio = audio.fade_in(10).fade_out(20) # paste section on base audio baseAudio = baseAudio.overlay(audio, position=start) sprite = { "src": os.path.basename(fn), "start": start, "dur": dur } sprites.append(sprite) format = os.path.basename(audioFn).split(".")[-1] baseAudio.export(audioFn, format=format) jsonOut = { "name": os.path.basename(audioFn), "sprites": sprites } io.writeJSON(dataFn, jsonOut, pretty=True) return jsonOut
if "text" in storyItem: itemOut.append({ "isHTML": True, "isDescription": True, "value": "<p>" + storyItem["text"] + "</p>" }) if "audio" in storyItem: itemOut.append({"isAudio": True, "value": storyItem["audio"]}) if "object" in storyItem: itemOut.append({"isObject": True, "value": storyItem["object"]}) print(f'Story item: {OUTPUT_FILE}{fileIndex}.json <{len(fileItems)}>') fileItems.append(itemOut) if len(fileItems) >= itemsPerFile or i >= (itemCount - 1): filenameOut = f'{OUTPUT_FILE}{fileIndex}.json' io.writeJSON(filenameOut, fileItems) fileIndex += 1 fileItems = [] mu.printProgress(i + 1, itemCount) outjson = { "metadata": { "itemCount": itemCount, "itemsPerFile": itemsPerFile, "itemsPath": OUTPUT_FILE_REL } } io.writeJSON(CONFIG_FILE, outjson,
"className": "radio-buttons radio-buttons-views", "default": True, "radioItems": viewOptions } } # Update HTML template src = "apps/template" dest = "apps/%s" % config["name"] indexFilenameTemplate = src + "/index.html" indexFilename = dest + "/index.html" # Check for footer content footerContent = '<div class="intro-footer">' if "credits" in config: footerContent += '<div class="credits">' if not isinstance(config["credits"], list): config["credits"] = [config["credits"]] for credit in config["credits"]: footerContent += f'<a href="{credit["url"]}" target="_blank"><img src="{credit["image"]}" alt="{credit["name"]}" /></a>' footerContent += '</div>' if "creditText" in config: footerContent += f'\n<p>{config["creditText"]}</p>' footerContent += '</div>' config["footerContent"] = footerContent su.formatTextFile(indexFilenameTemplate, indexFilename, config) io.copyFile(src + "/viewer.html", dest + "/viewer.html") io.writeJSON(OUTPUT_FILE, outjson, pretty=True, prepend="_.extend(CONFIG, ", append=");")
_labelConfig, labelData = getCategoryYearLabels() if _labelConfig is not None: labelConfig.update(_labelConfig) elif labelKey == "countries": _labelConfig, labelData = getCountryLabels() if _labelConfig is not None: labelConfig.update(_labelConfig) else: print("Invalid label key: %s" % labelKey) continue # Write position file if labelData is not None: labelOutFile = OUTPUT_LABEL_DIR + labelKey + ".json" io.writeJSON(labelOutFile, labelData) labelConfig["src"] = OUTPUT_LABEL_DIR_REL + labelKey + ".json" else: continue jsonLabels[labelKey] = labelConfig # Write config file outjson = {"labels": jsonLabels} io.writeJSON(CONFIG_FILE, outjson, pretty=True, prepend="_.extend(CONFIG, ", append=");")