[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Media endpoint output tweaks, pt. 2: derivatives

2017-12-06 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
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'
* Rename 'title' and 'short_title' to 'name' and 'short_name'

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, 135 insertions(+), 93 deletions(-)

Approvals:
  BearND: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/media.js b/lib/media.js
index 7bf9c20..dce92e6 100644
--- a/lib/media.js
+++ b/lib/media.js
@@ -69,7 +69,7 @@
 let endTime;
 let thumbTime;
 let audioType;
-let derivatives;
+let sources;
 if (mediaType === Video) {
 const dataMw = JSON.parse(elem.getAttribute('data-mw'));
 if (dataMw) {
@@ -77,19 +77,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(', '),
+name: source.getAttribute('data-title'),
+short_name: 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) {
@@ -110,7 +110,7 @@
 end_time: endTime,
 thumb_time: thumbTime,
 audio_type: audioType,
-derivatives
+sources
 };
 });
 }
@@ -163,7 +163,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 32c97ee..aabb1dc 100644
--- a/spec.yaml
+++ b/spec.yaml
@@ -597,11 +597,6 @@
 width: /.+/
 height: /.+/
 mime: /.+/
-  original:
-source: /.+/
-width: /.+/
-height: /.+/
-mime: /.+/
   license: /.+/
 
   # from routes/definition.js
@@ -1315,7 +1310,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 

[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Media endpoint output tweaks, pt. 2: derivatives

2017-12-05 Thread Mholloway (Code Review)
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:
@@