Skip to content

Commit

Permalink
frist commit of the videogrinder
Browse files Browse the repository at this point in the history
  • Loading branch information
mamuso committed Dec 30, 2008
0 parents commit 59f16cd
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 0 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2008 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Videogrinder
============

Starting up!
22 changes: 22 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the videogrinder plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the videogrinder plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Videogrinder'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
9 changes: 9 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Main class
require 'videogrinder'

# Gems & other herbs
require 'open-uri'
require 'youtube'

# Video classes
require 'vg_youtube'
1 change: 1 addition & 0 deletions install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Install hook code here
49 changes: 49 additions & 0 deletions lib/vg_google.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# ----------------------------------------------
#
#
#
#
# ----------------------------------------------


class VgGoogle

def initialize(url=nil)
end

def title
end

def thumbnail
end

def embed_url
end

def embed_html(width=425, height=344, options={})
end

def flv
end

private

def parse_url(url)
uri = URI.parse(url)
args = uri.query
video_id = ''
if args and args.split('&').size <= 1
args.split('&').each do |arg|
k,v = arg.split('=')
video_id = v.to_i and break if k == 'docid'
end
raise unless video_id
else
raise
end
video_id
rescue
nil
end

end
65 changes: 65 additions & 0 deletions lib/vg_youtube.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# ----------------------------------------------
#
#
#
#
# ----------------------------------------------


class VgYoutube

def initialize(url=nil, key=nil)
# general settings
settings ||= YAML.load_file(RAILS_ROOT + '/config/videogrinder.yml') rescue {}
object = YouTube::Client.new(key.nil? ? settings['youtube_key'] : key) rescue {}

# objects to build
@url = url
@video_id = parse_url(url)
@details = object.video_details(@video_id)
end

def title
@details.title
end

def thumbnail
@details.thumbnail_url
end

def embed_url
"http://www.youtube.com/v/#{@video_id}" if @details.embed_allowed == true
end

def embed_html(width=425, height=344, options={})
"<object width='#{width}' height='#{height}'><param name='movie' value='http://www.youtube.com/v/#{@video_id}&fs=1'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/#{@video_id}&fs=1' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='#{width}' height='#{height}'></embed></object>" if @details.embed_allowed == true
end


def flv
doc = URI::parse(@url).read
t = doc.split("&t=")[1].split("&")[0]
"http://www.youtube.com/get_video.php?video_id=#{@video_id}&t=#{t}"
end

private

def parse_url(url)
uri = URI.parse(url)
args = uri.query
video_id = ''
if args and args.split('&').size >= 1
args.split('&').each do |arg|
k,v = arg.split('=')
video_id = v and break if k == 'v'
end
raise unless video_id
else
raise
end
video_id
rescue
nil
end

end
48 changes: 48 additions & 0 deletions lib/videogrinder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class Videogrinder

def initialize(url=nil)
@object ||= "vg_#{get_domain(url).downcase}".camelize.constantize.new(url) rescue {}
end

def title
@object.title rescue {}
end

def thumbnail
@object.thumbnail rescue {}
end

def embed_url
@object.embed_url rescue {}
end

def embed_html(width=425, height=344, options={})
@object.embed_html(width, height, options) rescue {}
end

def flv
@object.flv rescue {}
end

def video_details
{
:title => @object.title,
:thumbnail => @object.thumbnail,
:embed_url => @object.embed_url,
:embed_html => @object.embed_html,
:flv => @object.flv
}
end

private

def get_domain(url)
host = URI::parse(url).host.split(".")
unless host.size == 1
host[host.size-2]
else
host[0]
end
end

end
4 changes: 4 additions & 0 deletions tasks/videogrinder_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :videogrinder do
# # Task goes here
# end
8 changes: 8 additions & 0 deletions test/videogrinder_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test/unit'

class VideogrinderTest < Test::Unit::TestCase
# Replace this with your real tests.
def test_this_plugin
flunk
end
end
1 change: 1 addition & 0 deletions uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Uninstall hook code here
12 changes: 12 additions & 0 deletions videogrinder_sample.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# fill the gaps :)
#
#
# youtube
youtube_key:

# vimeo
vimeo_key:
vimeo_secret:

# flickr
flickr_key:

0 comments on commit 59f16cd

Please sign in to comment.