[Git][noosfero/noosfero][master] 4 commits: video_plugin: return data for video block in api_content

Victor Costa gitlab at mg.gitlab.com
Thu Dec 22 11:02:23 BRST 2016


Victor Costa pushed to branch master at Noosfero / noosfero


Commits:
4e1a1834 by Marcelo Júnior at 2016-12-22T09:22:59-03:00
video_plugin: return data for video block in api_content

- - - - -
70cd7f6e by Marcelo Júnior at 2016-12-22T09:24:05-03:00
video_plugin: update unit tests

- - - - -
b8404e91 by Leandro Nunes dos Santos at 2016-12-22T09:24:16-03:00
video_plugin: refator api_content method of video block

- - - - -
20476324 by Victor Costa at 2016-12-22T13:02:17+00:00
Merge branch 'video-plugin' into 'master'

Video plugin

See merge request !1070
- - - - -


4 changed files:

- plugins/video/lib/video_plugin/video.rb
- plugins/video/lib/video_plugin/video_block.rb
- plugins/video/test/unit/video_block_test.rb
- plugins/video/test/unit/video_test.rb


Changes:

=====================================
plugins/video/lib/video_plugin/video.rb
=====================================
--- a/plugins/video/lib/video_plugin/video.rb
+++ b/plugins/video/lib/video_plugin/video.rb
@@ -112,6 +112,20 @@ class VideoPlugin::Video < Article
     vimeo_match[1] unless vimeo_match.nil?
   end
 
+  def self.mime_type(video_url)
+    video_type = 'video/unknown'
+
+    if /.mp4/i =~ video_url or /.mov/i =~ video_url
+      video_type='video/mp4'
+    elsif /.webm/i =~ video_url
+      video_type='video/webm'
+    elsif /.og[vg]/i =~ video_url
+      video_type='video/ogg'
+    end
+
+    video_type
+  end
+
   private
 
   YOUTUBE_ID_FORMAT = '\w-'
@@ -122,7 +136,7 @@ class VideoPlugin::Video < Article
     elsif is_vimeo?
       fill_vimeo_video_properties
     elsif true
-      self.video_format = detect_file_format
+      self.video_format = mime_type
       self.video_provider = 'file'
     end
   end
@@ -156,16 +170,8 @@ class VideoPlugin::Video < Article
     self.video_thumbnail_height = 360
   end
 
-  def detect_file_format
-   video_type = 'video/unknown'
-   if /.mp4/i =~ self.video_url or /.mov/i =~ self.video_url
-    video_type='video/mp4'
-   elsif /.webm/i =~ self.video_url
-    video_type='video/webm'
-   elsif /.og[vg]/i =~ self.video_url
-    video_type='video/ogg'
-   end
-   video_type
+  def mime_type
+    VideoPlugin::Video.mime_type(self.video_url)
   end
 
   def extract_youtube_id


=====================================
plugins/video/lib/video_plugin/video_block.rb
=====================================
--- a/plugins/video/lib/video_plugin/video_block.rb
+++ b/plugins/video/lib/video_plugin/video_block.rb
@@ -36,6 +36,16 @@ class VideoPlugin::VideoBlock < Block
     _('This block presents a video from youtube, vimeo and some video formats (mp4, ogg, ogv and webm)')
   end
 
+  def api_content
+    content = {:url => self.url}
+    content[:mime_type] = VideoPlugin::Video.mime_type(self.url) if VideoPlugin::Video.is_video_file?(self.url)
+    content
+  end
+
+  def display_api_content_by_default?
+    true
+  end
+
   private
 
   def extract_youtube_id


=====================================
plugins/video/test/unit/video_block_test.rb
=====================================
--- a/plugins/video/test/unit/video_block_test.rb
+++ b/plugins/video/test/unit/video_block_test.rb
@@ -1,8 +1,20 @@
 require_relative '../test_helper'
 class VideoBlockTest < ActiveSupport::TestCase
 
+  should "display api_content enabled by default" do
+    block = VideoPlugin::VideoBlock.new
+    assert block.display_api_content_by_default?
+  end
+
   ### Tests for YouTube
 
+  should "api_content no contains mime-type if platform is youtube" do
+    block = VideoPlugin::VideoBlock.new
+    block.url = "https://youtube.com/?v=XXXXX"
+    assert_includes block.api_content, :url
+    refute_includes block.api_content, :mime_type
+  end
+
   should "is_youtube return true when the url contains http://youtube.com" do
     block = VideoPlugin::VideoBlock.new
     block.url = "http://youtube.com/?v=XXXXX"
@@ -92,6 +104,13 @@ class VideoBlockTest < ActiveSupport::TestCase
 
   #### Tests for Vimeo Videos
 
+  should "api_content no contains mime-type if platform is vimeo" do
+    block = VideoPlugin::VideoBlock.new
+    block.url = "http://vimeo.com/98979"
+    assert_includes block.api_content, :url
+    refute_includes block.api_content, :mime_type
+  end
+
   should "is_vimeo return true when the url contains http://vimeo.com" do
     block = VideoPlugin::VideoBlock.new
     block.url = "http://vimeo.com/98979"
@@ -172,6 +191,14 @@ class VideoBlockTest < ActiveSupport::TestCase
   end
 
   # Other video formats
+
+  should "api_content contains plaform and mime-type if platform is \'file\'" do
+    block = VideoPlugin::VideoBlock.new
+    block.url = "http://www.vmsd.com/98979.mp4"
+    assert_includes block.api_content, :url
+    assert_includes block.api_content, :mime_type
+  end
+
   should "is_video return true if url ends with mp4" do
     block = VideoPlugin::VideoBlock.new
     block.url = "http://www.vmsd.com/98979.mp4"


=====================================
plugins/video/test/unit/video_test.rb
=====================================
--- a/plugins/video/test/unit/video_test.rb
+++ b/plugins/video/test/unit/video_test.rb
@@ -90,6 +90,29 @@ class VideoTest < ActiveSupport::TestCase
     assert @video.is_vimeo?
   end
 
+  should "mime-type return video/webm if url ends with webm" do
+    url = "http://www.vmsd.com/98979.webm"
+    assert_equal 'video/webm', @video.class.mime_type(url)
+  end
+
+  should "mime-type return video/ogg if url ends with ogg" do
+    url = "http://www.vmsd.com/98979.ogg"
+    assert_equal 'video/ogg', @video.class.mime_type(url)
+  end
+
+  should "mime-type return video/unknown if platform is youtube" do
+    url = "https://youtube.com/?v=XXXXX"
+    assert_equal 'video/unknown', @video.class.mime_type(url)
+  end
+
+  should "mime-type return video/unknown if platform is vimeo" do
+    url = "http://vimeo.com/98979"
+    assert_equal 'video/unknown', @video.class.mime_type(url)
+  end
 
+  should "mime-type return video/mp4 if url ends with mp4" do
+    url = "http://www.vmsd.com/98979.mp4"
+    assert_equal 'video/mp4', @video.class.mime_type(url)
+  end
 
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/3f3c5e2afc30c801fd3f9e04c0ee0c1631c2fc8d...204763243a541f18d9d0037beffb0e2e2d8c3715
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20161222/4b7855e5/attachment-0001.html>


More information about the Noosfero-dev mailing list