From 0dc27d64157f74875c0cb1d47f05a3acd19e42d2 Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 2 Jan 2014 12:57:56 -0300 Subject: [PATCH 01/16] Added media types object Signed-off-by: Juan Martin Runge --- media_types.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 media_types.js diff --git a/media_types.js b/media_types.js new file mode 100644 index 0000000..a98392e --- /dev/null +++ b/media_types.js @@ -0,0 +1,31 @@ +var _ = require('underscore') +; +module.exports = { + types: [{ + type: 'image', + seconds: 0, + isMedia: function(filename) { + return filename.match(/\.(bmp|gif|jpg|png|yuv|pix|dpx|exr|jpeg|pam|pbm|pcx|pgm|pic|ppm|ptx|sgi|tif|tiff|webp|xbm|xwd)$/i); + } + }, + { + type: 'video', + seconds: 5, + isMedia: function(filename) { + return filename.match(/\.(webm|mp4|flv|avi|mpeg|mpeg2|mpg|mov|mkv|ogm|ogg)$/i); + } + }], + isMedia: function(filename) { + return _.some(this.types, function(type) { + return type.isMedia(filename); + }); + }, + getType: function(filename) { + return _.find(this.types, function(type) { + return type.isMedia(filename); + }); + }, + getSeconds: function(type) { + return _.findWhere(this.types, {type: type}).seconds; + } +}; \ No newline at end of file From 9e8577303d0881892b208221d7dd50699cb8129e Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 2 Jan 2014 12:58:23 -0300 Subject: [PATCH 02/16] Modified ffmpeg to use seconds for screenshot from options if set Signed-off-by: Juan Martin Runge --- ffmpeg/ffmpeg.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ffmpeg/ffmpeg.js b/ffmpeg/ffmpeg.js index 1680428..9ed9ebc 100644 --- a/ffmpeg/ffmpeg.js +++ b/ffmpeg/ffmpeg.js @@ -8,11 +8,17 @@ function FFMPEG (opts) { FFMPEG.prototype.run = function (orig, dest, opts, callback) { var stdout, stderr; + + var seconds; + if (opts.seconds === undefined) + seconds = 5; + else + seconds = opts.seconds; this.proc = _spawnProcess (['-i', orig, '-r', 1, - '-ss', 5, + '-ss', seconds, '-vcodec', 'mjpeg', '-vframes', '1', '-an', From 178e2e0cb0c6e894233ec4a1e21f0cbcd545bf22 Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 2 Jan 2014 12:59:03 -0300 Subject: [PATCH 03/16] Added support for handling image files on scrape Signed-off-by: Juan Martin Runge --- utils.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/utils.js b/utils.js index eb2cb93..f6ae611 100644 --- a/utils.js +++ b/utils.js @@ -6,6 +6,7 @@ var _ = require('underscore') , conf = mbc.config.Caspa , logger = mbc.logger().addLogger('caspa_util') , collections = mbc.config.Common.Collections +, media_types = require('./media_types.js') ; var _exists = fs.exists || require('path').exists; @@ -85,6 +86,7 @@ utils.prototype.sc_pool = new fp.Pool({size: 1}, function (media, callback, done var f = new ffmpeg(); f.run (media.file, dest, { size: '150x100', + seconds: media_types.getSeconds(media.type), onCodecData: function(metadata) { logger.info('here'); if (!callback) @@ -95,6 +97,7 @@ utils.prototype.sc_pool = new fp.Pool({size: 1}, function (media, callback, done metadata.file = media.file; metadata.stat = media.stat; metadata.checksum = media._id; + metadata.type = media.type; callback (metadata); } }, function(retcode, fds) { @@ -125,7 +128,7 @@ utils.prototype.parse_pool = function () { if (stat === item.stat) return (done(item)); else item.stat = stat; } else { - item = { _id: md5 , file: file, stat: stat}; + item = { _id: md5 , file: file, stat: stat, type: media_types.getType(file).type}; } return done(item); @@ -157,8 +160,9 @@ utils.prototype.scrape_files = function (path, callback) { .on('file', function (root, stat, next) { var file = root + '/' + stat.name; next(); - if (! stat.name.match(/\.(webm|mp4|flv|avi|mpeg|mpeg2|mpg|mov|mkv|ogm|ogg)$/i)) { - var error = new Error('file not a vid : ' + stat.name); + + if (!media_types.isMedia(stat.name)) { + var error = new Error('file type not supported: ' + stat.name); logger.error(error.toString()); return error; } @@ -169,7 +173,6 @@ utils.prototype.scrape_files = function (path, callback) { logger.debug('parsed: ' + stat.name, res); self.sc_pool.task(res, callback, function (err, res) {return res}); }); - }) .on('end', function () { logger.info("all done"); From 786a1be4c7af8f3106b19cc2fb3b9c5a58f6b2fb Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 9 Jan 2014 12:48:15 -0300 Subject: [PATCH 04/16] Show type on media attributes Signed-off-by: Juan Martin Runge --- views/templates/mediaview.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/templates/mediaview.jade b/views/templates/mediaview.jade index d7cd50c..51ac5ff 100644 --- a/views/templates/mediaview.jade +++ b/views/templates/mediaview.jade @@ -36,7 +36,7 @@ .row .span6 .control-group - - var items = {md5: _id, 'File Name': file, Duration: durationraw, Format: video.container, Audio: audio.codec, Video:video.codec} + - var items = {md5: _id, 'Type': type, 'File Name': file, Duration: durationraw, Format: video.container, Audio: audio.codec, Video:video.codec} each v, k in items - var Item = k.charAt(0).toUpperCase() + k.slice(1) From 02bb58c46872c33d8afadf99fac4244f719df90d Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 9 Jan 2014 12:49:12 -0300 Subject: [PATCH 05/16] Allow pieces to be clickable (so modal window with attrs to edit can be shown) Signed-off-by: Juan Martin Runge --- views/templates/medialist.jade | 2 ++ 1 file changed, 2 insertions(+) diff --git a/views/templates/medialist.jade b/views/templates/medialist.jade index d011a2c..7923520 100644 --- a/views/templates/medialist.jade +++ b/views/templates/medialist.jade @@ -86,6 +86,8 @@ block content td.center - if (!is_playlist) - var target = "attr:{href: '/media/'+checksum().split('-')[0]}"; + - else + - var target = "attr:{href: '#'}, click: $root.editItem, clickBubble: false"; a.plain(data-bind=target) img(width="150",height="100",data-bind="attr:{ src: checksum() ? '/sc/'+checksum().split('-')[0]+'.jpg' : '/pics/generic.jpg' }") td From 649db4c7af40684d4d0e6c023b5ee9b138d07ab8 Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 9 Jan 2014 12:50:08 -0300 Subject: [PATCH 06/16] Add type to attrs to show in row mode Signed-off-by: Juan Martin Runge --- views/templates/medialist.jade | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/views/templates/medialist.jade b/views/templates/medialist.jade index 7923520..2f6b218 100644 --- a/views/templates/medialist.jade +++ b/views/templates/medialist.jade @@ -95,6 +95,12 @@ block content button.close.remove-media(type='button', data-bind='click: $root.removeItem, clickBubble: false') × h5(data-bind="text: name") h5(data-bind="text: stat().name ? stat().name : file") + + span.label.type + + span(data-bind="text: 'TIPO'") + span=' ' + span.label.label-warning.format i.icon-time.icon-white span(data-bind="text: durationraw") From 08df79b19933c7f3cf1451301dcdccc11fd83354 Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 9 Jan 2014 12:50:34 -0300 Subject: [PATCH 07/16] Add modal target for showing modal dialogs Signed-off-by: Juan Martin Runge --- views/templates/medialist.jade | 2 ++ 1 file changed, 2 insertions(+) diff --git a/views/templates/medialist.jade b/views/templates/medialist.jade index 2f6b218..095167f 100644 --- a/views/templates/medialist.jade +++ b/views/templates/medialist.jade @@ -35,6 +35,8 @@ block content - var thumbnail = i18n.gettext('Thumbnail') - var media_info = i18n.gettext('Media info') +#modal + #media-list.infinit-panel - if (!fixed) button.close.kill-media-list(type='button', data-dismiss='alert') × From 29288042acb8c578e15c549b6b3f8b37415758ab Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 9 Jan 2014 12:51:00 -0300 Subject: [PATCH 08/16] Added image edit template Signed-off-by: Juan Martin Runge --- views/templates/imagepieceedit.jade | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 views/templates/imagepieceedit.jade diff --git a/views/templates/imagepieceedit.jade b/views/templates/imagepieceedit.jade new file mode 100644 index 0000000..2ffb644 --- /dev/null +++ b/views/templates/imagepieceedit.jade @@ -0,0 +1,12 @@ +- var submit = i18n.gettext("Submit") +- var cancel = i18n.gettext("Cancel") + +.bbm-modal__topbar + h3.bbm-modal__title= title +.bbm-modal__section + fieldset + legend.editor= duration + input#duration(type="text", style="width:200px") +.bbm-modal__bottombar + a.bbm-button.submit(href="#")= submit + a.bbm-button.cancel(href="#")= cancel From d98ab785674370099be21e6c421bedd9e66522e7 Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 9 Jan 2014 12:51:27 -0300 Subject: [PATCH 09/16] Export image edit template Signed-off-by: Juan Martin Runge --- routes/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routes/index.js b/routes/index.js index 1eff2da..e618b58 100644 --- a/routes/index.js +++ b/routes/index.js @@ -186,7 +186,8 @@ module.exports = function(app, everyauth) { 'emptyalert', 'timeinfo', 'nowplaying', - 'sourceinfo' + 'sourceinfo', + 'imagepieceedit' ]; var commonTemplates = ['editor', From f2e1345db0315a339c4f6401f23f27d3f54fe2e3 Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 9 Jan 2014 12:51:58 -0300 Subject: [PATCH 10/16] Added ImageEditPrompt Signed-off-by: Juan Martin Runge --- public/js/views/medialist.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/public/js/views/medialist.js b/public/js/views/medialist.js index 9ed9a90..2dbb64c 100644 --- a/public/js/views/medialist.js +++ b/public/js/views/medialist.js @@ -287,3 +287,29 @@ window.MediaListView = function(options){ }; } +var ImageEditPrompt = Backbone.Modal.extend({ + initialize: function (options) { + this.options = options || {}; + }, + template: function() { + var parse_tpl = template.imagepieceedit(this.options); + return _.template(parse_tpl); + }, + submitEl: '.submit', + cancelEl: '.cancel', + events: { + "click .submit" : "save", + "keypress input[id=textkey]" : "saveOnEnter", + "click .cancel" : "cancel" + }, + save: function () { + this.options.submitCallback($('#duration').val()); + }, + saveOnEnter: function (e) { + if (e.keyCode != 13) return; + this.save(); + }, + cancel: function() { + this.options.cancelCallback(); + } +}); From b19c3c1d8d5da7bd331eec35571fb598762fb44c Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 9 Jan 2014 12:52:52 -0300 Subject: [PATCH 11/16] Added imageEdit function Signed-off-by: Juan Martin Runge --- public/js/views/medialist.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/public/js/views/medialist.js b/public/js/views/medialist.js index 2dbb64c..b1e0c3d 100644 --- a/public/js/views/medialist.js +++ b/public/js/views/medialist.js @@ -179,6 +179,31 @@ window.MediaListView = function(options){ pieces.add(model, {at: arg.targetIndex}); } }, + + editImage: function(item) { + var self = this; + + var title = i18n.gettext('Image Edit'); + var duration = i18n.gettext('Duration (HH:mm:ss):'); + var prompt = new ImageEditPrompt( + { title: title, + duration: duration, + submitCallback: function (length) { + console.log("Selected YES"); + if(length) { + console.log("Changing length: ", length); + item.durationraw(length); + } else { + var description = i18n.gettext('You must enter length'); + self.alert(description); + } + }, + cancelCallback: function() { + return; + } }).render().el; + $('#modal').html(prompt); + window.scrollTo(0,0); + } }); this.search_view = new SearchView({ From 95d11c0e39b684102b6082e09192029c0d64d3d9 Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Thu, 9 Jan 2014 12:53:20 -0300 Subject: [PATCH 12/16] Added itemEdit target for editing Pieces Signed-off-by: Juan Martin Runge --- public/js/views/medialist.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/public/js/views/medialist.js b/public/js/views/medialist.js index b1e0c3d..638ad03 100644 --- a/public/js/views/medialist.js +++ b/public/js/views/medialist.js @@ -87,7 +87,13 @@ window.MediaListView = function(options){ self.collection.remove(item); self.filter(filters); } - + + this.editItem = function(item) { + console.log('Editing Piece', item); + /* TODO: Use it this way--> if (item.type() === 'image')*/ + if (item.model().attributes.type === 'image') + self.editImage(item); + } this.__filters = ko.observable(); this.filter = ko.computed({ From ec0eec8438c869e451d50550b87f7ac02facede6 Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Fri, 10 Jan 2014 13:47:08 -0300 Subject: [PATCH 13/16] Fixed missing type function, requires update from mbc-common Signed-off-by: Juan Martin Runge --- public/js/views/medialist.js | 3 +-- views/templates/medialist.jade | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/public/js/views/medialist.js b/public/js/views/medialist.js index 638ad03..2517f85 100644 --- a/public/js/views/medialist.js +++ b/public/js/views/medialist.js @@ -90,8 +90,7 @@ window.MediaListView = function(options){ this.editItem = function(item) { console.log('Editing Piece', item); - /* TODO: Use it this way--> if (item.type() === 'image')*/ - if (item.model().attributes.type === 'image') + if (item.type() === 'image') self.editImage(item); } diff --git a/views/templates/medialist.jade b/views/templates/medialist.jade index 095167f..a28db9f 100644 --- a/views/templates/medialist.jade +++ b/views/templates/medialist.jade @@ -100,7 +100,7 @@ block content span.label.type - span(data-bind="text: 'TIPO'") + span(data-bind="text: type") span=' ' span.label.label-warning.format From 4cc58807b0317f6721d52f6a379726ecdf9b359e Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Mon, 13 Jan 2014 10:41:49 -0300 Subject: [PATCH 14/16] Make Piece to show its length on edit prompt Signed-off-by: Juan Martin Runge --- public/js/views/medialist.js | 2 ++ views/templates/imagepieceedit.jade | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/public/js/views/medialist.js b/public/js/views/medialist.js index 2517f85..ffe40a7 100644 --- a/public/js/views/medialist.js +++ b/public/js/views/medialist.js @@ -190,9 +190,11 @@ window.MediaListView = function(options){ var title = i18n.gettext('Image Edit'); var duration = i18n.gettext('Duration (HH:mm:ss):'); + var duration_value = moment(item.durationraw(), 'HH:mm:ss.SSS').format('HH:mm:ss'); var prompt = new ImageEditPrompt( { title: title, duration: duration, + duration_value: duration_value, submitCallback: function (length) { console.log("Selected YES"); if(length) { diff --git a/views/templates/imagepieceedit.jade b/views/templates/imagepieceedit.jade index 2ffb644..870d6c6 100644 --- a/views/templates/imagepieceedit.jade +++ b/views/templates/imagepieceedit.jade @@ -6,7 +6,7 @@ .bbm-modal__section fieldset legend.editor= duration - input#duration(type="text", style="width:200px") + input#duration(type="text", style="width:200px", value=duration_value) .bbm-modal__bottombar a.bbm-button.submit(href="#")= submit a.bbm-button.cancel(href="#")= cancel From 81893e98a5fcc1195f50271e98dddd0e4e1c8b13 Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Mon, 13 Jan 2014 10:42:36 -0300 Subject: [PATCH 15/16] Add alert function Signed-off-by: Juan Martin Runge --- public/js/views/medialist.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/public/js/views/medialist.js b/public/js/views/medialist.js index ffe40a7..7c3f2fe 100644 --- a/public/js/views/medialist.js +++ b/public/js/views/medialist.js @@ -210,7 +210,13 @@ window.MediaListView = function(options){ } }).render().el; $('#modal').html(prompt); window.scrollTo(0,0); - } + }, + alert: function(description) { + var title = i18n.gettext('Alert'); + var description = description || i18n.gettext('Wait there was a problem'); + $('#modal').html(new ModalAlert({ title: title, description: description }).render().el); + window.scrollTo(0,0); + }, }); this.search_view = new SearchView({ @@ -345,3 +351,14 @@ var ImageEditPrompt = Backbone.Modal.extend({ this.options.cancelCallback(); } }); +var ModalAlert = Backbone.Modal.extend({ + initialize: function (options) { + this.options = options || {}; + }, + template: function() { + var parse_tpl = template.alert(this.options); + return _.template(parse_tpl); + }, + cancelEl: '.bbm-button' +}); + From 7acdcbed9a6e8131eb06f92f115124f3a84de089 Mon Sep 17 00:00:00 2001 From: Juan Martin Runge Date: Mon, 13 Jan 2014 10:44:25 -0300 Subject: [PATCH 16/16] Validate length input format Signed-off-by: Juan Martin Runge --- public/js/views/medialist.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/public/js/views/medialist.js b/public/js/views/medialist.js index 7c3f2fe..b78c658 100644 --- a/public/js/views/medialist.js +++ b/public/js/views/medialist.js @@ -198,8 +198,16 @@ window.MediaListView = function(options){ submitCallback: function (length) { console.log("Selected YES"); if(length) { - console.log("Changing length: ", length); - item.durationraw(length); + var l = length.match(/(\d{2}):(\d{2}):(\d{2})/); + if (l === null) { + var description = i18n.gettext('Wrong duration format'); + self.alert(description); + } else { + l.shift(); + var fmt_length = l[0] + ':' + l[1] + ':' + l[2] + '.00'; + console.log("Changing length: ", fmt_length); + item.durationraw(fmt_length); + } } else { var description = i18n.gettext('You must enter length'); self.alert(description);