From c237b0554de9e17d2feb84484faadd1af1f0f983 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 17 Dec 2022 18:59:49 +0000 Subject: [PATCH] generate.js: fix artwork for mail, add audio metadata for ifuckinglovescience, add jsdoc hints, oopify RadioMetadata, add RadioPlaybackInfo --- generate.js | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 245 insertions(+), 5 deletions(-) diff --git a/generate.js b/generate.js index 72acc26..e8b7a1e 100755 --- a/generate.js +++ b/generate.js @@ -7,7 +7,7 @@ const objSerialize = (obj, keys, cb) => { for (const key of keys) a[key] = obj[key] if (cb) - return cb(a) + return cb(a, obj) return a } @@ -21,6 +21,12 @@ const objBulkSet = (obj, target, pairs) => { const notNullElse = (a, fallback) => a != null && a != undefined ? a : fallback +/** + * @public + * @constructor + * @params {string} id + * @returns {RadioItem} + */ const RadioItem = function (id) { this.id = id this.metadata = undefined @@ -29,11 +35,58 @@ const RadioItem = function (id) { return this } +/** + * @public + * @params {string} id + * @returns {RadioItem} + */ RadioItem.new = id => new RadioItem(id) -RadioItem.prototype.setMetadata = function (title, artist, href, extra) { objBulkSet(this, "metadata", { title, artist, href, extra }); return this } + +/** + * @public + * @params {string|undefined} title + * @params {string|undefined} artist + * @params {URL|string|undefined} [href] href + * @params {string} [extra] extra Playback effects. i.e: Pitch, speed + * @returns {RadioItem} + */ +RadioItem.prototype.setMetadata = function (title, artist, href, extra) { + if (!this.metadata) + this.metadata = RadioMetadata.new() + objBulkSet(this, "metadata", { title, artist, href, extra }); + return this +} + +/** + * @public + * @params {string[]} tags + * @returns {RadioItem} + */ RadioItem.prototype.addTags = function (tags) { this.tags = this.tags ? [ ...(this.tags), ...tags ] : tags; return this } + +/** + * Alias for addTags; prefixes all items with "radio-media-style-" + * @public + * @params {string[]} tags + * @returns {RadioItem} + * @see RadioItem.prototype.addTags + */ RadioItem.prototype.addStyleTags = function (tags) { return this.addTags(tags.map(a => `radio-media-style-${a}`)); return this } + +/** + * @public + * @params {RadioSource} source + * @returns {RadioItem} + */ RadioItem.prototype.addSource = function (source) { this.sources.push(source); return this } + +/** + * Set metadata for songs that were previously on nigge.rs; adds the "niggers" tag. + * @public + * @params {string|undefined} nigid + * @params {string|undefined} nigkey + * @returns {RadioItem} + */ RadioItem.prototype.setNiggadata = function (nigid, nigkey) { this.setMetadata() this.metadata._nigid = nigid @@ -42,6 +95,10 @@ RadioItem.prototype.setNiggadata = function (nigid, nigkey) { return this } +/** + * @deprecated + * @returns {Object} + */ RadioItem.prototype.serialize = function () { return objSerialize(this, [ "id", @@ -50,6 +107,11 @@ RadioItem.prototype.serialize = function () { ], obj => ({ ...obj, "sources": this.sources.map(source => source.serialize()) })) } +/** + * @public + * @readonly + * @enum {number} + */ const EDisplayType = { "NATIVE": -1, "LANDSCAPE": 0, @@ -57,6 +119,13 @@ const EDisplayType = { "STRETCH": 2 } +/** + * @public + * @constructor + * @params {string} type + * @params {string[]} [codecs] codecs + * @returns {RadioSource} + */ const RadioSource = function (type, codecs) { this.type = type this.uri = null @@ -65,14 +134,74 @@ const RadioSource = function (type, codecs) { return this } +/** + * @public + * @params {string} type + * @params {string[]} [codecs] codecs + * @returns {RadioSource} + */ RadioSource.new = (type, codecs) => new RadioSource(type, codecs) + +/** + * @public + * @params {string} uri + * @returns {RadioSource} + */ RadioSource.prototype.setURI = function (uri) { this.uri = uri; return this } + +/** + * Set metadata that specifically applies to *this* source. Used for items where the audio has a different attribution than + * the video. + * @public + * @params {string|undefined} title + * @params {string|undefined} artist + * @params {URL|string|undefined} [href] href + * @params {string} [extra] extra Playback effects. i.e: Pitch, speed + * @returns {RadioSource} + */ +RadioSource.prototype.setMetadata = function (title, artist, href, extra) { + if (!this.metadata) + this.metadata = RadioMetadata.new() + objBulkSet(this, "metadata", { title, artist, href, extra }); + return this +} + + +/** + * @public + * @params {RadioPlaybackInfo} playbackInfo + * @returns {RadioSource} + */ +RadioSource.prototype.setPlaybackInfo = function (playbackInfo) { this.playbackinfo = playbackInfo; return this; } + +/** + * @public + * @params {string} uri + * @returns {RadioSource} + */ RadioSource.prototype.setTypeWCodec = function (type, codecs) { this.type = type this.codecs = codecs?.length ? codecs : undefined return this } -// LLL[], LLL + +/** + * @public + * @params {string} uri + * @params {string} type + * @params {string} size + * @params {EDisplayType} [displayType] displayType + * @returns {RadioSource} + */ +/** + * @public + * @params {string} uri + * @params {string} type + * @params {string[]} codecs + * @params {String} size + * @params {EDisplayType} [displayType] displayType + * @returns {RadioSource} + */ RadioSource.prototype.addPreview = function () { let uri, type, codecs, size, displayType if (typeof arguments[0] == "string" && typeof arguments[1] == "string" && arguments[2] instanceof Array) { @@ -93,14 +222,33 @@ RadioSource.prototype.addPreview = function () { return this } +/** + * @deprecated + * @returns {Object} + */ RadioSource.prototype.serialize = function () { return objSerialize(this, [ "type", "codecs", "uri" - ], obj => ({ ...obj, "previews": this.previews.map(preview => preview.serialize(obj)) })) + ], (obj, self) => ({ + ...obj, + "metadata": self.metadata ? self.metadata.serialize() : undefined, + "playbackinfo": self.playbackinfo ? self.playbackinfo.serialize() : undefined, + "previews": this.previews.map(preview => preview.serialize(obj)) + })) } +/** + * @public + * @constructor + * @params {string} uri + * @params {string} type + * @params {string[]} codecs + * @params {String} size + * @params {EDisplayType} [displayType=null] size + * @returns {RadioPreview} + */ const RadioPreview = function (uri, type, codecs, size, displayType=null) { this.uri = uri this.type = type @@ -110,7 +258,22 @@ const RadioPreview = function (uri, type, codecs, size, displayType=null) { return this } +/** + * @public + * @params {string} uri + * @params {string} type + * @params {string[]} codecs + * @params {String} size + * @params {EDisplayType} [displayType=null] size + * @returns {RadioPreview} + */ RadioPreview.new = (uri, type, codecs, size, displayType) => new RadioPreview(uri, type, codecs, size, displayType) + +/** + * @deprecated + * @params {RadioSource} radioSource + * @returns {Object} + */ RadioPreview.prototype.serialize = function (radioSource) { this.display_type = notNullElse(this.display_type, radioSource.type.startsWith("video/") ? EDisplayType.NATIVE : EDisplayType.SQUARE) return objSerialize(this, [ @@ -122,6 +285,81 @@ RadioPreview.prototype.serialize = function (radioSource) { ]) } +/** + * @public + * @constructor + * @params {string|undefined} title + * @params {string|undefined} artist + * @params {URL|string|undefined} [href] href + * @params {string} [extra] extra Playback effects. i.e: Pitch, speed + * @returns {RadioMetadata} + */ +const RadioMetadata = function (title, artist, href, extra) { + this.title = title + this.artist = artist + this.href = href + this.extra = extra + return this +} + +/** + * @public + * @params {string|undefined} title + * @params {string|undefined} artist + * @params {URL|string|undefined} [href] href + * @params {string} [extra] extra Playback effects. i.e: Pitch, speed + * @returns {RadioMetadata} + */ +RadioMetadata.new = (title, artist, href, extra) => new RadioMetadata(title, artist, href, extra) + +/** + * @deprecated + * @params {RadioSource} radioSource + * @returns {Object} + */ +RadioMetadata.prototype.serialize = function () { + console.log(this) + return objSerialize(this, [ + "title", + "artist", + "href", + "extra" + ]) +} + +/** + * @public + * @constructor + * @returns {RadioPlaybackInfo} + */ +const RadioPlaybackInfo = function () { + this.volume = undefined + return this +} + +/** + * @public + * @param {number} volume - Playback volume. Crude version of ReplayGain + * @returns {RadioPlaybackInfo} + */ +RadioPlaybackInfo.prototype.setPlaybackVolume = function (volume) { this.volume = volume; return this; } + +/** + * @public + * @returns {RadioPlaybackInfo} + */ +RadioPlaybackInfo.new = () => new RadioPlaybackInfo() + +/** + * @deprecated + * @returns {Object} + */ +RadioPlaybackInfo.prototype.serialize = function () { + return objSerialize(this, [ + "volume" + ]) +} + const mediaItems = [ RadioItem.new("nightinjunitaki") @@ -241,6 +479,7 @@ const mediaItems = [ .addPreview("mxc://glowers.club/IhivpcDssjnjSDHBdMEGGwVp", "image/jpg", "320x180")) .addSource(RadioSource.new("audio/mp3", [ "mp3" ]) .setURI("mxc://glowers.club/uoohwSBNmaXjTLZFwodmEwwr") + .setMetadata("I FUCKING LOVE SCIENCE", "Hank Green", "https://youtu.be/RECuQaaGGfA") .addPreview("mxc://glowers.club/aAYxVtwfHuIqXzYkrVwHZDjl", "image/jpg", "500x500")), RadioItem.new("dootnukem") @@ -800,7 +1039,8 @@ const mediaItems = [ .setMetadata("AOLNATION - Mail", "Personal Pong", "https://soundcloud.com/personalpong/aolnation-mail") .addSource(RadioSource.new("audio/mp3", [ "mp3" ]) .setURI("mxc://glowers.club/HEDaNdMsVFzIgYDkymkxnhob") - .addPreview("mxc://glowers.club/LhOramTbXftTqwlmpoPnTLQI", "image/jpg", "617x414")) + .setPlaybackInfo(RadioPlaybackInfo.new().setPlaybackVolume(.25)) + .addPreview("mxc://glowers.club/vBvnVioYcHeIGtvHRAaWWCab", "image/jpg", "500x500")) // TODO: needs artwork // RadioItem.new("isisman")