impawards 0.1.0
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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.textile +23 -0
- data/Rakefile +56 -0
- data/lib/impawards.rb +60 -0
- data/test/impawards_test.rb +46 -0
- data/test/test_helper.rb +10 -0
- metadata +83 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jon Maddox
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
h1. IMPAwards!
|
2
|
+
|
3
|
+
h2. What?
|
4
|
+
|
5
|
+
A simple library to get nice posters from IMPAwards:http://impawards.com
|
6
|
+
|
7
|
+
h2. How?
|
8
|
+
|
9
|
+
require 'impawards'
|
10
|
+
include IMPAwards
|
11
|
+
|
12
|
+
<pre>
|
13
|
+
<code>IMPAwards.search_posters("The Dark Knight").first</code>
|
14
|
+
=> {:xlg=>"http://www.impawards.com/2008/posters/dark_knight_xlg.jpg",
|
15
|
+
:thumb=>"http://www.impawards.com/2008/posters/dark_knight.jpg",
|
16
|
+
:tiny=>"http://www.impawards.com/2008/thumbs/imp_dark_knight.jpg"}
|
17
|
+
</pre>
|
18
|
+
|
19
|
+
h2. Installation
|
20
|
+
|
21
|
+
gem install impawards
|
22
|
+
|
23
|
+
gem hosted at Gemcutter
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "impawards"
|
8
|
+
gem.summary = %Q{Simple library to find high quality posters for movies}
|
9
|
+
gem.description = %Q{Simple library to find high quality posters for movies}
|
10
|
+
gem.email = "jon@mustacheinc.com"
|
11
|
+
gem.homepage = "http://github.com/maddox/impawards"
|
12
|
+
gem.authors = ["Jon Maddox"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda"
|
14
|
+
gem.add_dependency "hpricot"
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
if File.exist?('VERSION')
|
47
|
+
version = File.read('VERSION')
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "impawards #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/lib/impawards.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hpricot'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'pathname'
|
5
|
+
require 'cgi'
|
6
|
+
|
7
|
+
module IMPAwards
|
8
|
+
class IMPAwards
|
9
|
+
|
10
|
+
def self.search_posters(query)
|
11
|
+
results_url = "http://www.google.com/cse?cx=partner-pub-6811780361519631%3A48v46vdqqnk&cof=FORID%3A9&ie=ISO-8859-1&q=#{CGI.escape(query)}&sa=Search&ad=w9&num=10&rurl=http%3A%2F%2Fwww.impawards.com%2Fgooglesearch.html%3Fcx%3Dpartner-pub-6811780361519631%253A48v46vdqqnk%26cof%3DFORID%253A9%26ie%3DISO-8859-1%26q%3Doverboard%2B1987%26sa%3DSearch"
|
12
|
+
doc = Hpricot open(results_url)
|
13
|
+
movie_urls = (doc/"div.g h2.r a")
|
14
|
+
|
15
|
+
movie_urls.delete_if{|movie_url| movie_url.inner_text !~ /Poster - Internet/i}
|
16
|
+
|
17
|
+
if movie_urls.size > 0
|
18
|
+
posters_for_url(movie_urls.first['href'])
|
19
|
+
else
|
20
|
+
[]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.posters_for_url(url)
|
25
|
+
posters = []
|
26
|
+
url_path = Pathname.new(url)
|
27
|
+
|
28
|
+
doc = Hpricot markup_for_movie_url(url)
|
29
|
+
|
30
|
+
(doc/"#altdesigns img").each do |element|
|
31
|
+
posters << get_poster_hash(url_path.dirname.to_s + '/' + element['src'])
|
32
|
+
end
|
33
|
+
|
34
|
+
# if no posters were found at the bottom use the one on the page
|
35
|
+
posters << get_poster_hash(url_path.dirname.to_s + '/' + doc.at("#left_half img")['src']) if posters.size == 0
|
36
|
+
posters
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def self.markup_for_movie_url(url)
|
41
|
+
markup = open(url).read
|
42
|
+
if markup.match(/URL=\.\.(\/.*\/.*.html)/)
|
43
|
+
markup_for_movie_url("http://impawards.com#{$1}")
|
44
|
+
else
|
45
|
+
markup
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.get_poster_hash(poster_path)
|
50
|
+
tiny_path = poster_path
|
51
|
+
thumb_path = poster_path.gsub('thumbs', 'posters').gsub('imp_', '')
|
52
|
+
xlg_path = poster_path.gsub('thumbs', 'posters').gsub('imp_', '').gsub('.jpg', '_xlg.jpg')
|
53
|
+
|
54
|
+
poster_hash = { :tiny => tiny_path,
|
55
|
+
:thumb => thumb_path,
|
56
|
+
:xlg => xlg_path}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ImpawardsTest < Test::Unit::TestCase
|
4
|
+
context "IMPAwards" do
|
5
|
+
|
6
|
+
context "searching for posters by title" do
|
7
|
+
setup do
|
8
|
+
@results = IMPAwards::IMPAwards.search_posters("The Dark Knight")
|
9
|
+
end
|
10
|
+
|
11
|
+
should "return an array" do
|
12
|
+
assert_equal Array, @results.class
|
13
|
+
end
|
14
|
+
|
15
|
+
should "return an array of hashes" do
|
16
|
+
assert_equal Hash, @results.first.class
|
17
|
+
end
|
18
|
+
|
19
|
+
context "returned poster" do
|
20
|
+
setup do
|
21
|
+
@result = @results.first
|
22
|
+
end
|
23
|
+
|
24
|
+
should "have 3 sizes" do
|
25
|
+
assert_equal 3, @result.keys.size
|
26
|
+
end
|
27
|
+
|
28
|
+
should "have xlg url" do
|
29
|
+
assert_match /http.*xlg/, @result[:xlg]
|
30
|
+
end
|
31
|
+
|
32
|
+
should "have thumb url" do
|
33
|
+
assert_match /http.*/, @result[:thumb]
|
34
|
+
end
|
35
|
+
|
36
|
+
should "have tiny url" do
|
37
|
+
assert_match /http.*/, @result[:tiny]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: impawards
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Maddox
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-09 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hpricot
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: Simple library to find high quality posters for movies
|
36
|
+
email: jon@mustacheinc.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.textile
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.textile
|
49
|
+
- Rakefile
|
50
|
+
- lib/impawards.rb
|
51
|
+
- test/impawards_test.rb
|
52
|
+
- test/test_helper.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/maddox/impawards
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options:
|
59
|
+
- --charset=UTF-8
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Simple library to find high quality posters for movies
|
81
|
+
test_files:
|
82
|
+
- test/impawards_test.rb
|
83
|
+
- test/test_helper.rb
|