Mholloway has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/395599 )
Change subject: Media endpoint output tweaks, pt. 2: derivatives ...................................................................... Media endpoint output tweaks, pt. 2: derivatives * Change 'derivatives' property name to 'sources' * Remove 'original' property for videos since the original is present in the sources * Split 'type' property into 'mime' and 'codecs' Bug: T177430 Change-Id: I411925b4db1bcb698dc0e5198fac617eef54d65b --- M lib/media.js M routes/media.js M spec.yaml M test/diff/results/page_media-enwiki-Hummingbird.json M test/lib/media/media-test.js 5 files changed, 103 insertions(+), 61 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps refs/changes/99/395599/1 diff --git a/lib/media.js b/lib/media.js index 23a381a..894e61a 100644 --- a/lib/media.js +++ b/lib/media.js @@ -67,7 +67,7 @@ let endTime; let thumbTime; let audioType; - let derivatives; + let sources; if (mediaType === Video) { const dataMw = JSON.parse(elem.getAttribute('data-mw')); if (dataMw) { @@ -75,19 +75,19 @@ endTime = dataMw.endtime; thumbTime = dataMw.thumbtime; } - const sources = elem.getElementsByTagName('source'); - if (sources.length) { - derivatives = [].map.call(sources, (source) => { - return { - source: source.getAttribute('src'), - type: source.getAttribute('type'), - title: source.getAttribute('data-title'), - short_title: source.getAttribute('data-shorttitle'), - width: source.getAttribute('data-file-width') || undefined, - height: source.getAttribute('data-file-height') || undefined - }; - }); - } + const sourceElems = elem.getElementsByTagName('source'); + sources = [].map.call(sourceElems, (source) => { + return { + source: source.getAttribute('src'), + mime: source.getAttribute('type').split('; ')[0], + // eslint-disable-next-line no-useless-escape + codecs: source.getAttribute('type').split('; ')[1].split('\"')[1].split(', '), + title: source.getAttribute('data-title'), + short_title: source.getAttribute('data-shorttitle'), + width: source.getAttribute('data-file-width') || undefined, + height: source.getAttribute('data-file-height') || undefined + }; + }); } else if (mediaType === Audio) { let parent = elem.parentNode; while (parent) { @@ -109,7 +109,7 @@ end_time: endTime, thumb_time: thumbTime, audio_type: audioType, - derivatives + sources }; }); } @@ -162,7 +162,7 @@ // Reject gallery items if they're too small. // Also reject SVG and PNG items by default, because they're likely to be // logos and/or presentational images. - return item.original && item.original.source + return item.sources || item.original && item.original.source && (item.type === Audio.name || item.original.width >= MIN_IMAGE_SIZE) && (item.type === Audio.name || item.original.height >= MIN_IMAGE_SIZE) && !item.original.mime.includes('svg') diff --git a/routes/media.js b/routes/media.js index cea40bc..fb39932 100644 --- a/routes/media.js +++ b/routes/media.js @@ -32,6 +32,11 @@ if (mediaItem.title === metadataItem.titles.canonical) { Object.assign(mediaItem, metadataItem); delete mediaItem.title; + + // delete 'original' property for videos + if (mediaItem.sources) { + delete mediaItem.original; + } } }); }); diff --git a/spec.yaml b/spec.yaml index 109bd34..e79baa9 100644 --- a/spec.yaml +++ b/spec.yaml @@ -597,11 +597,6 @@ width: /.+/ height: /.+/ mime: /.+/ - original: - source: /.+/ - width: /.+/ - height: /.+/ - mime: /.+/ license: /.+/ # from routes/definition.js @@ -1314,7 +1309,7 @@ duration: type: number description: the playback duration in seconds (for audio and video items) - derivatives: + sources: type: array description: a list of derivatives of the original file (applies only to videos) items: @@ -1339,7 +1334,6 @@ - file_page - type - thumbnail - - original - license additionalProperties: false diff --git a/test/diff/results/page_media-enwiki-Hummingbird.json b/test/diff/results/page_media-enwiki-Hummingbird.json index 1012d38..9e83b2b 100644 --- a/test/diff/results/page_media-enwiki-Hummingbird.json +++ b/test/diff/results/page_media-enwiki-Hummingbird.json @@ -218,10 +218,14 @@ "type": "video", "caption_html": "Slow motion video of hummingbirds feeding", "caption_text": "Slow motion video of hummingbirds feeding", - "derivatives": [ + "sources": [ { "source": "https://upload.wikimedia.org/wikipedia/commons/2/21/Hummingbird_feeding_closeup_2000fps.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "Original WebM file, 864 × 480 (955 kbps)", "short_title": "WebM source", "width": "864", @@ -229,25 +233,41 @@ }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/2/21/Hummingbird_feeding_closeup_2000fps.webm/Hummingbird_feeding_closeup_2000fps.webm.160p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "Low bandwidth WebM (160P)", "short_title": "WebM 160P" }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/2/21/Hummingbird_feeding_closeup_2000fps.webm/Hummingbird_feeding_closeup_2000fps.webm.240p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "Small WebM (240P)", "short_title": "WebM 240P" }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/2/21/Hummingbird_feeding_closeup_2000fps.webm/Hummingbird_feeding_closeup_2000fps.webm.360p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "WebM (360P)", "short_title": "WebM 360P" }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/2/21/Hummingbird_feeding_closeup_2000fps.webm/Hummingbird_feeding_closeup_2000fps.webm.480p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "SD WebM (480P)", "short_title": "WebM 480P" } @@ -262,12 +282,6 @@ "width": 320, "height": 178, "mime": "image/jpeg" - }, - "original": { - "source": "https://upload.wikimedia.org/wikipedia/commons/2/21/Hummingbird_feeding_closeup_2000fps.webm", - "width": 864, - "height": 480, - "mime": "video/webm" }, "file_page": "https://commons.wikimedia.org/wiki/File:Hummingbird_feeding_closeup_2000fps.webm", "duration": 168.669, @@ -333,10 +347,14 @@ "type": "video", "caption_html": "Hummingbird in <a rel=\"mw:WikiLink\" href=\"./Copiapó,_Chile\" title=\"Copiapó, Chile\" id=\"mwAaI\" class=\"mw-redirect\">Copiapó, Chile</a>: The apparent slow movement of its wings is a result of the <a rel=\"mw:WikiLink\" href=\"./Stroboscopic_effect\" title=\"Stroboscopic effect\" id=\"mwAaM\">stroboscopic effect</a>.", "caption_text": "Hummingbird in Copiapó, Chile: The apparent slow movement of its wings is a result of the stroboscopic effect.", - "derivatives": [ + "sources": [ { "source": "https://upload.wikimedia.org/wikipedia/commons/d/db/Hummingbird.ogv", - "type": "video/ogg; codecs=\"theora, vorbis\"", + "mime": "video/ogg", + "codecs": [ + "theora", + "vorbis" + ], "title": "Original Ogg file, 854 × 480 (2.55 Mbps)", "short_title": "Ogg source", "width": "854", @@ -344,25 +362,41 @@ }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/d/db/Hummingbird.ogv/Hummingbird.ogv.160p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "Low bandwidth WebM (160P)", "short_title": "WebM 160P" }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/d/db/Hummingbird.ogv/Hummingbird.ogv.240p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "Small WebM (240P)", "short_title": "WebM 240P" }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/d/db/Hummingbird.ogv/Hummingbird.ogv.360p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "WebM (360P)", "short_title": "WebM 360P" }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/d/db/Hummingbird.ogv/Hummingbird.ogv.480p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "SD WebM (480P)", "short_title": "WebM 480P" } @@ -377,12 +411,6 @@ "width": 320, "height": 180, "mime": "image/jpeg" - }, - "original": { - "source": "https://upload.wikimedia.org/wikipedia/commons/d/db/Hummingbird.ogv", - "width": 854, - "height": 480, - "mime": "application/ogg" }, "file_page": "https://commons.wikimedia.org/wiki/File:Hummingbird.ogg", "duration": 20.754066666667, @@ -447,10 +475,14 @@ }, { "type": "video", - "derivatives": [ + "sources": [ { "source": "https://upload.wikimedia.org/wikipedia/commons/f/fe/Humming_birds_feeding_at_1500fps.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "Original WebM file, 864 × 480 (1.03 Mbps)", "short_title": "WebM source", "width": "864", @@ -458,25 +490,41 @@ }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/f/fe/Humming_birds_feeding_at_1500fps.webm/Humming_birds_feeding_at_1500fps.webm.160p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "Low bandwidth WebM (160P)", "short_title": "WebM 160P" }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/f/fe/Humming_birds_feeding_at_1500fps.webm/Humming_birds_feeding_at_1500fps.webm.240p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "Small WebM (240P)", "short_title": "WebM 240P" }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/f/fe/Humming_birds_feeding_at_1500fps.webm/Humming_birds_feeding_at_1500fps.webm.360p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "WebM (360P)", "short_title": "WebM 360P" }, { "source": "https://upload.wikimedia.org/wikipedia/commons/transcoded/f/fe/Humming_birds_feeding_at_1500fps.webm/Humming_birds_feeding_at_1500fps.webm.480p.webm", - "type": "video/webm; codecs=\"vp8, vorbis\"", + "mime": "video/webm", + "codecs": [ + "vp8", + "vorbis" + ], "title": "SD WebM (480P)", "short_title": "WebM 480P" } @@ -491,12 +539,6 @@ "width": 320, "height": 178, "mime": "image/jpeg" - }, - "original": { - "source": "https://upload.wikimedia.org/wikipedia/commons/f/fe/Humming_birds_feeding_at_1500fps.webm", - "width": 864, - "height": 480, - "mime": "video/webm" }, "file_page": "https://commons.wikimedia.org/wiki/File:Humming_birds_feeding_at_1500fps.webm", "duration": 105.569, diff --git a/test/lib/media/media-test.js b/test/lib/media/media-test.js index da90f9c..ec61391 100644 --- a/test/lib/media/media-test.js +++ b/test/lib/media/media-test.js @@ -104,9 +104,10 @@ it('all expected derivative properties are present', () => { const result = media.getMediaItemInfoFromPage(videoWithDerivative)[0]; - const derivative = result.derivatives[0]; + const derivative = result.sources[0]; assert.deepEqual(derivative.source, 'https://example.com/Foo.ogv'); - assert.deepEqual(derivative.type, 'video/ogg; codecs="theora, vorbis"'); + assert.deepEqual(derivative.mime, 'video/ogg'); + assert.deepEqual(derivative.codecs, [ "theora", "vorbis" ]); assert.deepEqual(derivative.title, 'Foo'); assert.deepEqual(derivative.short_title, 'Foo'); assert.deepEqual(derivative.width, 120); -- To view, visit https://gerrit.wikimedia.org/r/395599 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I411925b4db1bcb698dc0e5198fac617eef54d65b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: Mholloway <mhollo...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits