acts_as_unvlogable_2 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ # This removes the activesupport dependency
2
+
3
+ class Object
4
+ def blank?
5
+ respond_to?(:empty?) ? empty? : !self
6
+ end
7
+
8
+ def instance_values #:nodoc:
9
+ instance_variables.inject({}) do |values, name|
10
+ values[name.to_s[1..-1]] = instance_variable_get(name)
11
+ values
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,24 @@
1
+ # This removes the activesupport dependency
2
+
3
+ class String
4
+ def camelize(first_letter_in_uppercase = true)
5
+ if first_letter_in_uppercase
6
+ self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
7
+ else
8
+ self.first + camelize(self)[1..-1]
9
+ end
10
+ end
11
+
12
+ def constantize
13
+ camel_cased_word = self
14
+ unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
15
+ raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
16
+ end
17
+
18
+ Object.module_eval("::#{$1}", __FILE__, __LINE__)
19
+ end
20
+
21
+ def humanize
22
+ self.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class String
3
+ def query_param(param_name)
4
+ raise ArgumentError.new("param name can't be nil") if param_name.blank?
5
+ uri = URI.parse(self)
6
+ (CGI::parse(uri.query)[param_name].first.to_s if uri.query) || nil
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module ActsAsUnvlogable
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,48 @@
1
+ # ----------------------------------------------
2
+ # Class for 11870 (11870.com)
3
+ # http://11870.com/pro/chic-basic-born/media/b606abfe
4
+ # ----------------------------------------------
5
+
6
+
7
+ class Vg11870
8
+
9
+ def initialize(url=nil, options={})
10
+ @url = url
11
+ @page = Hpricot(open(url))
12
+ @flashvars = CGI::parse(@page.to_s.split("flashvars="")[1].split(""")[0])
13
+ end
14
+
15
+ def title
16
+ CGI::unescapeHTML @page.search("//h1[@class='fn name']/a").first.inner_html
17
+ end
18
+
19
+ def thumbnail
20
+ @flashvars['image']
21
+ end
22
+
23
+ def duration
24
+ nil
25
+ end
26
+
27
+ def embed_url
28
+ query = @flashvars.map {|k,v| "&#{k}=#{v}"}
29
+ "http://11870.com/multimedia/flvplayer.swf?#{query}"
30
+ end
31
+
32
+ def embed_html(width=425, height=344, options={}, params={})
33
+ "<object width='#{width}' height='#{height}' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'> <param name='movie' value='#{embed_url}' /> <param name='quality' value='high' /><embed src='#{embed_url}' width='#{width}' height='#{height}' quality='high' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'/></object>"
34
+ end
35
+
36
+ def flv
37
+ @flashvars['file']
38
+ end
39
+
40
+ def download_url
41
+ nil
42
+ end
43
+
44
+ def service
45
+ "11870.com"
46
+ end
47
+
48
+ end
@@ -0,0 +1,48 @@
1
+ # ----------------------------------------------
2
+ # Class for BlipTv (blip.tv)
3
+ # http://blip.tv/file/678407/
4
+ # ----------------------------------------------
5
+
6
+
7
+ class VgBlip
8
+
9
+ def initialize(url=nil, options={})
10
+ @url = url.split("?").first if url
11
+ res = Net::HTTP.get(URI.parse("#{url}?skin=rss"))
12
+ @feed = REXML::Document.new(res)
13
+ end
14
+
15
+ def title
16
+ CGI::unescape REXML::XPath.first(@feed, "//media:title")[0].to_s
17
+ end
18
+
19
+ def thumbnail
20
+ REXML::XPath.first(@feed, "//blip:smallThumbnail")[0].to_s
21
+ end
22
+
23
+ def duration
24
+ nil
25
+ end
26
+
27
+ def embed_url
28
+ emb = REXML::XPath.first(@feed, "//media:player")[0].to_s
29
+ emb.split("src=\"")[1].split("\"")[0]
30
+ end
31
+
32
+ def embed_html(width=425, height=344, options={}, params={})
33
+ "<embed src='#{embed_url}' type='application/x-shockwave-flash' width='#{width}' height='#{height}' allowscriptaccess='always' allowfullscreen='true'></embed>"
34
+ end
35
+
36
+ def flv
37
+ REXML::XPath.first(@feed, "//enclosure").attributes['url']
38
+ end
39
+
40
+ def download_url
41
+ nil
42
+ end
43
+
44
+ def service
45
+ "Blip.tv"
46
+ end
47
+
48
+ end
@@ -0,0 +1,58 @@
1
+ # ----------------------------------------------
2
+ # Class for Collegehumor (www.collegehumor.com)
3
+ # http://www.collegehumor.com/video:1781938
4
+ # ----------------------------------------------
5
+
6
+
7
+ class VgCollegehumor
8
+
9
+ def initialize(url=nil, options={})
10
+ @url = url
11
+ @video_id = parse_url(url)
12
+ res = Net::HTTP.get(URI.parse("http://www.collegehumor.com/moogaloop/video/#{@video_id}"))
13
+ @feed = REXML::Document.new(res)
14
+ end
15
+
16
+ def title
17
+ REXML::XPath.first(@feed, "//video/caption")[0].to_s
18
+ end
19
+
20
+ def thumbnail
21
+ REXML::XPath.first(@feed, "//video/thumbnail")[0]
22
+ end
23
+
24
+ def embed_url
25
+ "http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=#{@video_id}&fullscreen=1"
26
+ end
27
+
28
+ def embed_html(width=425, height=344, options={}, params={})
29
+ "<object type='application/x-shockwave-flash' data='#{embed_url}' width='#{width}' height='#{height}'><param name='allowfullscreen' value='true'/><param name='wmode' value='transparent'/><param name='AllowScriptAccess' value='true'/><param name='movie' quality='best' value='#{embed_url}'/><embed src='#{embed_url}' type='application/x-shockwave-flash' wmode='transparent' width='#{width}' height='#{height}' allowScriptAccess='always'></embed></object>"
30
+ end
31
+
32
+ def flv
33
+ REXML::XPath.first(@feed, "//video/file")[0]
34
+ end
35
+
36
+ def download_url
37
+ nil
38
+ end
39
+
40
+ def duration
41
+ nil
42
+ end
43
+
44
+ def service
45
+ "CollegeHumor"
46
+ end
47
+
48
+ private
49
+
50
+ def parse_url(url)
51
+ uri = URI.parse(url)
52
+ path = uri.path
53
+ videoargs = path.split("/")
54
+ raise unless videoargs.size > 0 && videoargs[1] == 'video'
55
+ videoargs[2]
56
+ end
57
+
58
+ end
@@ -0,0 +1,67 @@
1
+ # ----------------------------------------------
2
+ # Class for Dailymotion (www.dailymotion.com)
3
+ # http://www.dailymotion.com/visited-week/lang/es/video/x7u5kn_parkour-dayyy_sport
4
+ # ----------------------------------------------
5
+
6
+
7
+ class VgDailymotion
8
+
9
+ def initialize(url=nil, options={})
10
+ @url = url
11
+ @video_id = parse_url(url)
12
+ res = Net::HTTP.get(URI.parse("http://www.dailymotion.com/rss/video/#{@video_id}"))
13
+ @feed = REXML::Document.new(res)
14
+ end
15
+
16
+ def title
17
+ REXML::XPath.first(@feed, "//item/title")[0].to_s
18
+ end
19
+
20
+ def thumbnail
21
+ REXML::XPath.first(@feed, "//media:thumbnail").attributes['url'].gsub("preview_large", "preview_medium")
22
+ end
23
+
24
+ def embed_url
25
+ REXML::XPath.first(@feed, "//media:content[@type='application/x-shockwave-flash']").attributes['url']
26
+ end
27
+
28
+ def embed_html(width=425, height=344, options={}, params={})
29
+ "<object width='#{width}' height='#{height}'><param name='movie' value='#{embed_url}&related=1'></param><param name='allowFullScreen' value='true'></param><param name='allowScriptAccess' value='always'></param><embed src='#{embed_url}&related=1' type='application/x-shockwave-flash' width='#{width}' height='#{height}' allowFullScreen='true' allowScriptAccess='always'></embed></object>"
30
+ end
31
+
32
+ def flv
33
+ doc = URI::parse("http://dailymotion.com/embed/video/#{@video_id}").read
34
+ doc = URI::parse("#{doc.split("stream_h264_url\":\"")[1].split("\"")[0].gsub("\\", "")}&redirect=0").read
35
+ end
36
+
37
+ def download_url
38
+ nil
39
+ end
40
+
41
+ def duration
42
+ nil
43
+ end
44
+
45
+ def service
46
+ "Dailymotion"
47
+ end
48
+
49
+ private
50
+
51
+ def parse_url(url)
52
+ uri = URI.parse(url)
53
+ path = uri.path
54
+ videoargs = ''
55
+ if path
56
+ videoargs = path.split('/video/')[1].split("/")[0]
57
+ raise unless videoargs.size > 0
58
+ else
59
+ raise
60
+ end
61
+ videoargs
62
+ rescue
63
+ nil
64
+ end
65
+
66
+
67
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+ # ----------------------------------------------
3
+ # Class for dalealplay (dalealplay.com)
4
+ # http://www.dalealplay.com/informaciondecontenido.php?con=80280
5
+ #
6
+ # Crappy without api
7
+ # ----------------------------------------------
8
+
9
+
10
+ class VgDalealplay
11
+
12
+ def initialize(url=nil, options={})
13
+ @url = url
14
+ @video_id = @url.query_param('con')
15
+ @page = open(url) {|f| Hpricot(f.read.encode("UTF-8")) }
16
+ end
17
+
18
+ def title
19
+ @page.search("//title").inner_html.split(" - Vídeo Online")[0].to_s
20
+ end
21
+
22
+ def thumbnail
23
+ "http://images-00.dalealplay.com/contenidos2/#{@video_id}/captura.jpg"
24
+ end
25
+
26
+ def embed_url
27
+ @page.search("//link[@rel='video_src']").first.attributes["href"].sub("autoStart=true", "autoStart=false")
28
+ end
29
+
30
+ def duration
31
+ nil
32
+ end
33
+
34
+ def embed_html(width=425, height=344, options={}, params={})
35
+ "<object type='application/x-shockwave-flash' width='#{width}' height='#{height}' data='#{embed_url}'><param name='quality' value='best' /> <param name='allowfullscreen' value='true' /><param name='scale' value='showAll' /><param name='movie' value='http#{embed_url}' /></object>"
36
+ end
37
+
38
+ def flv
39
+ "http://videos.dalealplay.com/contenidos3/#{CGI::parse(URI::parse(embed_url).query)['file']}"
40
+ end
41
+
42
+ def download_url
43
+ nil
44
+ end
45
+
46
+ def service
47
+ "dalealplay"
48
+ end
49
+
50
+ end
@@ -0,0 +1,70 @@
1
+ # ----------------------------------------------
2
+ # Class for Flickr (flickr.com)
3
+ # http://www.flickr.com/photos/andina/3158762127/in/photostream/
4
+ # ----------------------------------------------
5
+
6
+
7
+ class VgFlickr
8
+
9
+ def initialize(url=nil, options={})
10
+ # general settings
11
+ @url = url
12
+ @video_id = parse_url(url)
13
+ settings ||= YAML.load_file(RAILS_ROOT + '/config/unvlogable.yml') rescue {}
14
+ @details = Flickr::Photo.new(@video_id, options.nil? || options[:key].nil? ? settings['flickr_key'] : options[:key])
15
+ raise if @details.media != "video"
16
+ end
17
+
18
+ def title
19
+ @details.title
20
+ end
21
+
22
+ def thumbnail
23
+ @details.source('Small')
24
+ end
25
+
26
+ def embed_url
27
+ "http://www.flickr.com/apps/video/stewart.swf?v=63881&intl_lang=en-us&photo_secret=#{@details.secret}&photo_id=#{@video_id}"
28
+ end
29
+
30
+ def embed_html(width=425, height=344, options={}, params={})
31
+ "<object type='application/x-shockwave-flash' width='#{width}' height='#{height}' data='http://www.flickr.com/apps/video/stewart.swf?v=63881' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'><param name='movie' value='#{embed_url}'></param> <param name='bgcolor' value='#000000'></param> <param name='allowFullScreen' value='true'></param><embed type='application/x-shockwave-flash' src='#{embed_url}' bgcolor='#000000' allowfullscreen='true' width='#{width}' height='#{height}'></embed></object>"
32
+ end
33
+
34
+
35
+ def flv
36
+ player_feed = "http://www.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=#{@video_id}&secret=#{@details.secret}&olang=en-us&noBuffer=null&bitrate=700&target=_blank"
37
+ res = Net::HTTP.get(URI::parse(player_feed))
38
+ player_feed_xml = REXML::Document.new(res)
39
+ data_id = REXML::XPath.first(player_feed_xml, "//Data/Item[@id='id']")[0].to_s
40
+
41
+ video_feed = "http://www.flickr.com/video_playlist.gne?node_id=#{data_id}&tech=flash&mode=playlist&lq=j2CW2jbpqCLKRy_s4bTylH&bitrate=700&secret=#{@details.secret}&rd=video.yahoo.com-offsite&noad=1"
42
+ res = Net::HTTP.get(URI::parse(video_feed))
43
+ video_feed_xml = REXML::Document.new(res)
44
+ stream = REXML::XPath.first(video_feed_xml, "//DATA/SEQUENCE-ITEM/STREAM")
45
+ "#{stream.attributes['APP']}#{stream.attributes['FULLPATH']}"
46
+ end
47
+
48
+ def download_url
49
+ nil
50
+ end
51
+
52
+ def duration
53
+ nil
54
+ end
55
+
56
+ def service
57
+ "Flickr"
58
+ end
59
+
60
+ private
61
+
62
+ def parse_url(url)
63
+ video_id = URI::parse(url).path.split("/")[3]
64
+ raise unless video_id
65
+ video_id
66
+ rescue
67
+ nil
68
+ end
69
+
70
+ end
@@ -0,0 +1,48 @@
1
+ # ----------------------------------------------
2
+ # Class for Marca.tv (www.marca.tv)
3
+ # http://www.marca.com/tv/?v=DN23wG8c1Rj
4
+ # ----------------------------------------------
5
+
6
+
7
+ class VgMarca
8
+
9
+ def initialize(url=nil, options={})
10
+ @url = url
11
+ @video_id = @url.query_param('v')
12
+ res = Net::HTTP.get(URI.parse("http://estaticos.marca.com/consolamultimedia/marcaTV/elementos/#{@video_id[0,1]}/#{@video_id[1,1]}/#{@video_id[2,100]}.xml"))
13
+ @feed = REXML::Document.new(res)
14
+ end
15
+
16
+ def title
17
+ REXML::XPath.first( @feed, "//titulo" )[0].to_s
18
+ end
19
+
20
+ def thumbnail
21
+ REXML::XPath.first( @feed, "//foto" )[0].to_s
22
+ end
23
+
24
+ def duration
25
+ nil
26
+ end
27
+
28
+ def embed_url
29
+ "http://www.marca.com/componentes/flash/embed.swf?ba=0&cvol=1&bt=1&lg=1&vID=#{@video_id}&ba=1"
30
+ end
31
+
32
+ def embed_html(width=425, height=344, options={}, params={})
33
+ "<embed width='#{width}' height='#{height}' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' allowfullscreen='true' quality='high' src='#{embed_url}'/>"
34
+ end
35
+
36
+ def flv
37
+ REXML::XPath.first(@feed, "//media")[0].to_s
38
+ end
39
+
40
+ def download_url
41
+ nil
42
+ end
43
+
44
+ def service
45
+ "Marca.tv"
46
+ end
47
+
48
+ end