derobo-ofdb 0.0.1 → 0.0.2
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/lib/ofdb.rb +3 -2
- data/lib/ofdb/movie.rb +35 -9
- data/lib/ofdb/search.rb +10 -6
- metadata +1 -1
data/lib/ofdb.rb
CHANGED
data/lib/ofdb/movie.rb
CHANGED
@@ -3,10 +3,32 @@ module Ofdb
|
|
3
3
|
#This Class is Lazy-Load, means that the Pages are only loaded when needed. Also the data mining
|
4
4
|
#is only done when needed
|
5
5
|
class Movie
|
6
|
+
#holds the title of this movie
|
6
7
|
attr_reader :title
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
#holds the "ofdb-id"
|
9
|
+
attr_reader :name
|
10
|
+
#holds the url of the poster
|
11
|
+
attr_reader :poster
|
12
|
+
|
13
|
+
# Takes a IMDB-ID and call a serch with Ofdb::Search
|
14
|
+
# If the serch returns exactly 1 Movie then this Movie is return, else nil
|
15
|
+
def Movie.build_from_imdb(id)
|
16
|
+
search = Ofdb::Search.new(id, true)
|
17
|
+
return search.movies.first if search.movies.size == 1
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
# Take a link to a Ofdb-page of a Movie and builds the +Ofdb::Movie+
|
22
|
+
# The full link isn't require, e.g. for +"http://www.ofdb.de/film/1050,Pulp-Fiction"+ only
|
23
|
+
# +"1050,Pulp-Fiction"+ is required.
|
24
|
+
def initialize(ofdb_link)
|
25
|
+
if ofdb_link =~ /http:\/\/www.ofdb.de\/film/
|
26
|
+
@name = ofdb_link.gsub("http:\/\/www.ofdb.de\/film")
|
27
|
+
@url = ofdb_link
|
28
|
+
else
|
29
|
+
@name = ofdb_link
|
30
|
+
@url = "http://www.ofdb.de/film/#{@name}"
|
31
|
+
end
|
10
32
|
@title = /\d,/.match(name).post_match.gsub("---","§§§").gsub("-", " ").gsub("§§§", " - ")
|
11
33
|
end
|
12
34
|
|
@@ -32,10 +54,15 @@ module Ofdb
|
|
32
54
|
#Returns a URL to the Poster
|
33
55
|
def poster
|
34
56
|
document.search('img[@src^="http://img.ofdb.de/film/"]').each do |x|
|
35
|
-
return x.get_attribute("src").to_s
|
57
|
+
return @poster = x.get_attribute("src").to_s
|
36
58
|
end
|
37
59
|
end
|
38
60
|
|
61
|
+
#Sets the poster to a URL
|
62
|
+
def poster=(poster)
|
63
|
+
@poster = poster
|
64
|
+
end
|
65
|
+
|
39
66
|
#Returns a Array containg the Genres
|
40
67
|
def genre
|
41
68
|
get_viewphp("page=genre&Genre=").map {|x| x.innerHTML }
|
@@ -54,9 +81,11 @@ module Ofdb
|
|
54
81
|
private
|
55
82
|
# Returns a new Hpricot document for parsing.
|
56
83
|
def document
|
57
|
-
@document ||= Hpricot(
|
84
|
+
@document ||= Hpricot(open(@url))
|
58
85
|
end
|
59
86
|
|
87
|
+
# Returns a php snipped for a link to "view.php?..." as an Array
|
88
|
+
# The Result-Array is only filled with links matching the filter
|
60
89
|
def get_viewphp(filter=nil)
|
61
90
|
rsl = Array.new
|
62
91
|
document.search('font.Daten a[@href^="view.php"').each do |x|
|
@@ -65,9 +94,6 @@ module Ofdb
|
|
65
94
|
end
|
66
95
|
rsl
|
67
96
|
end
|
68
|
-
|
69
|
-
def self.find_by_id(url)
|
70
|
-
open(url)
|
71
|
-
end
|
97
|
+
|
72
98
|
end
|
73
99
|
end
|
data/lib/ofdb/search.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module Ofdb
|
2
2
|
class Search
|
3
|
+
require 'cgi'
|
4
|
+
# holds the current search String
|
3
5
|
attr_reader :query
|
4
6
|
#Uses query as Searchstring
|
5
7
|
#
|
6
|
-
# search = Ofdb::Search.new("
|
8
|
+
# search = Ofdb::Search.new("The Matrix")
|
7
9
|
#
|
8
10
|
# Ofdb::Search ist lazy loading.
|
9
11
|
def initialize(query, is_imdb_id=false)
|
@@ -11,23 +13,23 @@ module Ofdb
|
|
11
13
|
@query = query
|
12
14
|
end
|
13
15
|
|
14
|
-
# Returns the
|
15
|
-
#* :link => Url in Ofdb.de of that movie
|
16
|
-
#* :title => String like: $Germantitle / $OrignialTitle ($Year)
|
17
|
-
#* :poster => Url of the Poster, nil if not found
|
16
|
+
# Returns the Result of the Search as an Array of Ofdb::Movie
|
18
17
|
def movies
|
19
18
|
@movies ||= parse_movies
|
20
19
|
end
|
21
20
|
|
22
21
|
private
|
22
|
+
# Returns the Hpricot::Document of the Website
|
23
23
|
def document
|
24
24
|
@document ||= Hpricot(Ofdb::Search.query(@query, @is_imdb))
|
25
25
|
end
|
26
26
|
|
27
|
+
# Does the query an the ofdb.de an returns the results html
|
27
28
|
def self.query(query, imdb=false)
|
28
29
|
open("http://www.ofdb.de/view.php?page=suchergebnis&SText=#{CGI::escape(query)}#{"&Kat=IMDb" if imdb}")
|
29
30
|
end
|
30
31
|
|
32
|
+
# extracts all the results
|
31
33
|
def parse_movies
|
32
34
|
return @movies if @movies
|
33
35
|
@movies = Array.new
|
@@ -36,7 +38,9 @@ module Ofdb
|
|
36
38
|
title = element.innerHTML.imdb_strip_tags
|
37
39
|
poster = /images\/film\/.*"\sw/.match(element.get_attribute('onmouseover')).to_s.gsub("\" w","").gsub("images/film/", "")
|
38
40
|
poster = nil if poster =="na.gif"
|
39
|
-
|
41
|
+
mov = Ofdb::Movie.new(link)
|
42
|
+
mov.poster = poster if poster
|
43
|
+
@movies << mov
|
40
44
|
end
|
41
45
|
@movies
|
42
46
|
end
|