mcfearsome-viddler 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,91 @@
1
+ module Viddler
2
+ # This class wraps Viddler's video's information.
3
+ class Video
4
+
5
+ attr_accessor :id,
6
+ :url,
7
+ :title,
8
+ :description,
9
+ :tags,
10
+ :thumbnail_url,
11
+ :author,
12
+ :length_seconds,
13
+ :view_count,
14
+ :upload_time,
15
+ :comment_count,
16
+ :update_time,
17
+ :permissions,
18
+ :comments,
19
+ :width,
20
+ :height
21
+
22
+ def initialize(attributes={}) #:nodoc:
23
+ a = attributes
24
+ @id = a['id']
25
+ @title = a['title']
26
+ @description = a['description']
27
+ @tags = a['tags']
28
+ @url = a['url']
29
+ @thumbnail_url = a['thumbnail_url']
30
+ @author = a['author']
31
+ @length_seconds = a['length_seconds'].to_i
32
+ @view_count = a['view_count'].to_i
33
+ @comment_count = a['comment_count'].to_i
34
+ @update_time = a['update_time'] ? Time.at(a['update_time'].to_i) : nil
35
+ @permissions = a['permissions'] ? a['permissions'] : nil
36
+ @comments = a['comment_list'].values.flatten.collect do |comment|
37
+ Viddler::Comment.new(comment)
38
+ end if a['comment_list']
39
+ @width = a['width'].to_i
40
+ @height = a['height'].to_i
41
+ end
42
+
43
+ # Returns proper HTML code for embedding
44
+ #
45
+ # <tt>options</tt> hash could contain:
46
+ # * <tt>player_type:</tt> The type of player to embed, either "simple" or "player" (default is "player");
47
+ # * <tt>width:</tt> The width of the player (default is 437);
48
+ # * <tt>height:</tt> The height of the player (default is 370);
49
+ # * <tt>autoplay:</tt> Whether or not to autoplay the video, either "t" or "f" (default is "f");
50
+ # * <tt>playAll:</tt> Set to "true" to enable play all player (requires player_type to be "player");
51
+ #
52
+ # Any additional options passed to the method will be added as flashvars
53
+ #
54
+ # Example:
55
+ #
56
+ # @video.embed_code(:player_type => 'simple', :width => 300, :height => 300, autoplay => 't')
57
+ #
58
+ # Returns embed code for auto playing simple player with 300px width and height
59
+ #
60
+ def embed_code(options={})
61
+ options.reverse_merge! \
62
+ :player_type => 'player',
63
+ :width => 437,
64
+ :height => 370,
65
+ :autoplay => 'f',
66
+ :use_secret_url => false
67
+
68
+ # get non flashvars from options
69
+ player_type = options.delete(:player_type)
70
+ width = options.delete(:width)
71
+ height = options.delete(:height)
72
+ use_secret_url = options.delete(:use_secret_url)
73
+
74
+ flashvars = options.collect{|key,value| "#{key}=#{value}"}.join('&')
75
+
76
+ additional = use_secret_url ? "0/#{permissions['view']['secreturl']}/" : ''
77
+
78
+ html = <<CODE
79
+ <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="#{width}" height="#{height}" id="viddlerplayer-#{self.id}">
80
+ <param name="movie" value="http://www.viddler.com/#{player_type}/#{self.id}/#{additional}" />
81
+ <param name="allowScriptAccess" value="always" />
82
+ <param name="allowFullScreen" value="true" />
83
+ <param name="flashvars" value="#{flashvars}" />
84
+ <embed src="http://www.viddler.com/#{player_type}/#{self.id}/#{additional}" width="#{width}" height="#{height}" type="application/x-shockwave-flash" allowScriptAccess="always" flashvars="#{flashvars}" allowFullScreen="true" name="viddlerplayer-#{self.id}" >
85
+ </embed>
86
+ </object>
87
+ CODE
88
+ end
89
+
90
+ end
91
+ end
data/lib/viddler.rb ADDED
@@ -0,0 +1,21 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rubygems'
5
+ require 'active_support'
6
+ require 'ostruct'
7
+
8
+ require 'ext/open_struct'
9
+ require 'ext/hash'
10
+ require 'ext/array'
11
+ require 'viddler/api_spec'
12
+ require 'viddler/base'
13
+ require 'viddler/multipart_params'
14
+ require 'viddler/request'
15
+ require 'viddler/video'
16
+ require 'viddler/comment'
17
+ require 'viddler/user'
18
+
19
+ # Module to encapsule the Viddler API.
20
+ module Viddler
21
+ end
data/log/.gitignore ADDED
File without changes
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/viddler.rb'}"
9
+ puts "Loading viddler gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ begin
5
+ require 'newgem'
6
+ rescue LoadError
7
+ puts "\n\nGenerating the website requires the newgem RubyGem"
8
+ puts "Install: gem install newgem\n\n"
9
+ exit(1)
10
+ end
11
+ require 'redcloth'
12
+ require 'syntax/convertors/html'
13
+ require 'erb'
14
+ require File.dirname(__FILE__) + '/../lib/viddler/version.rb'
15
+
16
+ version = Viddler::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/viddler'
18
+
19
+ class Fixnum
20
+ def ordinal
21
+ # teens
22
+ return 'th' if (10..19).include?(self % 100)
23
+ # others
24
+ case self % 10
25
+ when 1: return 'st'
26
+ when 2: return 'nd'
27
+ when 3: return 'rd'
28
+ else return 'th'
29
+ end
30
+ end
31
+ end
32
+
33
+ class Time
34
+ def pretty
35
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
+ end
37
+ end
38
+
39
+ def convert_syntax(syntax, source)
40
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
+ end
42
+
43
+ if ARGV.length >= 1
44
+ src, template = ARGV
45
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
46
+
47
+ else
48
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
49
+ exit!
50
+ end
51
+
52
+ template = ERB.new(File.open(template).read)
53
+
54
+ title = nil
55
+ body = nil
56
+ File.open(src) do |fsrc|
57
+ title_text = fsrc.readline
58
+ body_text = fsrc.read
59
+ syntax_items = []
60
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
+ ident = syntax_items.length
62
+ element, syntax, source = $1, $2, $3
63
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
+ "syntax-temp-#{ident}"
65
+ }
66
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
+ body = RedCloth.new(body_text).to_html
68
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
+ end
70
+ stat = File.stat(src)
71
+ created = stat.ctime
72
+ modified = stat.mtime
73
+
74
+ $stdout << template.result(binding)