forked from mamuso/acts_as_unvlogable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 59f16cd
Showing
12 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Videogrinder | ||
============ | ||
|
||
Starting up! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Install hook code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Uninstall hook code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |