trailers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in trailers.gemspec
4
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,20 @@
1
+ ## Trailers - a Ruby gem engineered to find movie trailers for you.
2
+ Currently it relies on the public API offered by [TrailerAddict](traileraddict.com)
3
+
4
+ It's really simple to use:
5
+
6
+ require 'rubygems'
7
+ require 'trailers'
8
+
9
+ movie_trailer = Trailers::TrailerAddict.get_embed_code_for("Saw vii")
10
+
11
+ - - -
12
+ *Special thanks to [Aaron Gough](http://github.com/aarongough) for his original idea.*
13
+
14
+ - - -
15
+ TODO:
16
+
17
+ * Include more trailers sites
18
+ * Allow the user to choose between Flash or HTML5 videos
19
+
20
+ Enjoy
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/lib/trailers.rb ADDED
@@ -0,0 +1,67 @@
1
+ module Trailers
2
+ class TrailerAddict
3
+
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'nokogiri'
7
+
8
+ @base_url = "http://www.traileraddict.com/search.php?q="
9
+ @api_url = "http://api.traileraddict.com/"
10
+
11
+ # Return a response object from a given URL
12
+ def self.get_url(uri_str, limit = 10)
13
+ return false if limit == 0
14
+
15
+ begin
16
+ response = Net::HTTP.get_response(URI.parse(uri_str))
17
+ rescue SocketError, Errno::ENETDOWN
18
+ response = Net::HTTPBadRequest.new( '404', 404, "Not Found" )
19
+ return response
20
+ end
21
+
22
+ case response
23
+ when Net::HTTPSuccess then response
24
+ when Net::HTTPRedirection then self.get_url(response['location'], limit - 1)
25
+ else
26
+ Net::HTTPBadRequest.new( '404', 404, "Not Found" )
27
+ end
28
+ end
29
+
30
+ def self.get_tag_for(movie)
31
+ response = self.get_url(@base_url + URI.escape(movie))
32
+ return nil if(response.code != '200')
33
+
34
+ search_page_object = Nokogiri( response.body )
35
+ return nil if(search_page_object.search(".leftcolumn .searchthumb:first a")[0].nil? )
36
+ tag = search_page_object.search(".leftcolumn .searchthumb:first a")[0]['href'].gsub("/tags", '')
37
+ end
38
+
39
+ def self.api_call(movie_tag, options={})
40
+ raise ArgumentError, "movie_tag must be a string" unless(movie_tag.is_a?(String))
41
+
42
+ options = {
43
+ :count => 1,
44
+ :trailers => :yes,
45
+ :film => movie_tag
46
+ # :width => 480
47
+ }.merge(options)
48
+ option_string = "?" + URI.escape(options.to_a.map{|x| x[0].to_s + "=" + x[1].to_s}.join("&"))
49
+ response = self.get_url(@api_url + option_string)
50
+
51
+ if(response.code == '200')
52
+ return response.body
53
+ else
54
+ return ''
55
+ end
56
+ end
57
+
58
+ def self.get_embed_code_for(movie)
59
+ # movie_tag = self.get_tag_for(movie)
60
+ api_response = self.api_call(movie)
61
+ xml = Nokogiri::XML( api_response )
62
+ embed_code = xml.css('embed').inner_text
63
+ return nil if ( embed_code.length < 20 )
64
+ return embed_code
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Trailers
2
+ VERSION = "0.0.1"
3
+ end
data/trailers.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "trailers/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "trailers"
7
+ s.version = Trailers::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Fabio Basile"]
10
+ s.email = ["fabio@cosmicmission.com"]
11
+ s.homepage = "http://rubygems.org/gems/trailers"
12
+ s.summary = %q{Trailers - engineered to find movie trailers for you.}
13
+ s.description = %q{Currently it interfaces with the Traileraddict API, future versions will support HTML5 videos.}
14
+
15
+ s.rubyforge_project = "trailers"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "nokogiri", ">= 1.4.3.1"
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trailers
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Fabio Basile
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-29 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nokogiri
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 4
31
+ - 3
32
+ - 1
33
+ version: 1.4.3.1
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Currently it interfaces with the Traileraddict API, future versions will support HTML5 videos.
37
+ email:
38
+ - fabio@cosmicmission.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - README.markdown
49
+ - Rakefile
50
+ - lib/trailers.rb
51
+ - lib/trailers/version.rb
52
+ - trailers.gemspec
53
+ has_rdoc: true
54
+ homepage: http://rubygems.org/gems/trailers
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project: trailers
81
+ rubygems_version: 1.3.7
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Trailers - engineered to find movie trailers for you.
85
+ test_files: []
86
+