gimdb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/gimdb.gemspec ADDED
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gimdb}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Enrico Pilotto"]
12
+ s.date = %q{2010-05-08}
13
+ s.default_executable = %q{gimdb}
14
+ s.description = %q{GTK graphical interface for Internet Movie DataBase. You can create users and save for each of them the movies to see, movies seen and favourites movies in a sqlite3 database.}
15
+ s.email = %q{enrico@megiston.it}
16
+ s.executables = ["gimdb"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bin/gimdb",
28
+ "data/gimdb.glade",
29
+ "data/icons/favourites.png",
30
+ "data/icons/imdb.png",
31
+ "data/icons/imdb_icon.png",
32
+ "data/icons/no_poster.png",
33
+ "data/icons/seen.png",
34
+ "data/icons/spinner16x16.gif",
35
+ "data/icons/to_see.png",
36
+ "data/icons/users.png",
37
+ "data/icons/users_edit.png",
38
+ "data/locale/it/LC_MESSAGES/gimdb.mo",
39
+ "gimdb.gemspec",
40
+ "lib/imdb.rb",
41
+ "po/gimdb.pot",
42
+ "po/it/gimdb.po",
43
+ "src/controller.rb",
44
+ "src/gimdb.rb",
45
+ "src/model.rb",
46
+ "src/movie_box.rb"
47
+ ]
48
+ s.homepage = %q{http://github.com/pioz/gimdb}
49
+ s.rdoc_options = ["--charset=UTF-8"]
50
+ s.require_paths = ["lib"]
51
+ s.rubygems_version = %q{1.3.5}
52
+ s.summary = %q{GTK graphical interface for Internet Movie DataBase}
53
+
54
+ if s.respond_to? :specification_version then
55
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
60
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
61
+ s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 0"])
62
+ else
63
+ s.add_dependency(%q<nokogiri>, [">= 0"])
64
+ s.add_dependency(%q<activerecord>, [">= 0"])
65
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<nokogiri>, [">= 0"])
69
+ s.add_dependency(%q<activerecord>, [">= 0"])
70
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
71
+ end
72
+ end
73
+
data/lib/imdb.rb ADDED
@@ -0,0 +1,104 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'net/http'
5
+
6
+
7
+ class IMDB
8
+
9
+ @@URL = 'http://www.imdb.com/search/title/'
10
+ @@BASE_URL = 'www.imdb.com'
11
+ @@PATH_URL = '/search/title/'
12
+
13
+
14
+ module StringStripper
15
+ def stripper
16
+ self.strip.squeeze(' ').gsub(/[\302\240]+/,'').gsub('&', '&amp;')
17
+ end
18
+ end
19
+ String.send(:include, StringStripper)
20
+
21
+
22
+ def get_list(options = {})
23
+ @start = options[:start] || 1
24
+ set_request(options)
25
+ return perform_list_search { |step, max, text| yield(step, max, text) if block_given? }
26
+ end
27
+
28
+
29
+ def next
30
+ return {} if @params.nil?
31
+ @start = @start + 50
32
+ return perform_list_search { |step, max, text| yield(step, max, text) if block_given? }
33
+ end
34
+
35
+
36
+ def get_image(url, path, x = 160)
37
+ # http://ia.media-imdb.com/images/*.jpg
38
+ if url.match(/^http:\/\/ia\.media-imdb\.com\/images\/.*\.jpg/)
39
+ base = url.split('._V1._')[0]
40
+ style = "._V1._SX#{160}_.jpg"
41
+ final = base + style
42
+ begin
43
+ File.open(path, 'w') do |f|
44
+ open(final) { |stream| f << stream.read }
45
+ end
46
+ return true
47
+ rescue
48
+ File.delete(path)
49
+ puts "Error to save image at '#{final}'"
50
+ return false
51
+ end
52
+ end
53
+ return false
54
+ end
55
+
56
+
57
+ private
58
+
59
+
60
+ def set_request(options = {})
61
+ @params = '?title_type=feature'
62
+ @params += "&title=#{options[:title].gsub(' ','%20')}" if options[:title]
63
+ @params += "&release_date=#{options[:release_date]}" if options[:release_date]
64
+ @params += "&user_rating=#{options[:user_rating]}" if options[:user_rating]
65
+ @params += "&num_votes=#{options[:num_votes]}" if options[:num_votes]
66
+ @params += "&genres=#{options[:genres]}" if options[:genres]
67
+ @params += "&my_ratings=#{options[:my_ratings]}" if options[:my_ratings]
68
+ @params += "&sort=#{options[:sort]}" if options[:sort]
69
+ return @params
70
+ end
71
+
72
+
73
+ def perform_list_search
74
+ list = {}
75
+ doc = Nokogiri::HTML(open(@@URL + @params + "&start=#{@start}",
76
+ :content_length_proc => lambda do |t|
77
+ if block_given?
78
+ @max = t
79
+ yield(0, @max, 'Downloading movies info')
80
+ end
81
+ end,
82
+ :progress_proc => lambda do |s|
83
+ yield(s, @max) if block_given?
84
+ end))
85
+ yield(@max, @max) if block_given?
86
+ doc.css('table.results tr.detailed').each do |movie|
87
+ info = {}
88
+ number = movie.css('td.number').first.content.stripper.to_i
89
+ info[:code] = movie.css('td.title > a').first[:href].split('/')[2] rescue nil
90
+ info[:title] = movie.css('td.title > a').first.content.stripper rescue nil
91
+ info[:image_url] = movie.css('td.image img').first[:src].stripper rescue nil
92
+ info[:year] = movie.css('td.title > span.year_type').first.content.stripper[1..-2] rescue nil
93
+ info[:votes] = movie.css('td.title > div.user_rating').first[:title].stripper.gsub(',','') rescue nil
94
+ info[:rating] = movie.css('td.title > div.user_rating').first.content.stripper rescue nil
95
+ info[:outline] = movie.css('td.title > span.outline').first.content.stripper rescue nil
96
+ info[:credit] = movie.css('td.title > span.credit').first.content.stripper rescue nil
97
+ info[:genre] = movie.css('td.title > span.genre').first.content.stripper rescue nil
98
+ info[:runtime] = movie.css('td.title > span.runtime').first.content.stripper rescue nil
99
+ list[number] = info
100
+ end
101
+ return list
102
+ end
103
+
104
+ end
data/po/gimdb.pot ADDED
@@ -0,0 +1,217 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: gimdb\n"
10
+ "POT-Creation-Date: 2010-05-08 16:42+0200\n"
11
+ "PO-Revision-Date: 2010-05-06 01:50+0200\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=UTF-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18
+
19
+ #: movie_box.rb:53
20
+ msgid "Genres"
21
+ msgstr ""
22
+
23
+ #: movie_box.rb:75
24
+ msgid "<b>To see</b>"
25
+ msgstr ""
26
+
27
+ #: movie_box.rb:76
28
+ msgid "<b>Seen</b>"
29
+ msgstr ""
30
+
31
+ #: movie_box.rb:77
32
+ msgid "<b>Favourites</b>"
33
+ msgstr ""
34
+
35
+ #: gimdb.rb:158
36
+ msgid "Searching"
37
+ msgstr ""
38
+
39
+ #: gimdb.rb:345
40
+ msgid "New user added"
41
+ msgstr ""
42
+
43
+ #: gimdb.rb:362
44
+ msgid "User deleted"
45
+ msgstr ""
46
+
47
+ msgid "Downloading movie posters"
48
+ msgstr ""
49
+
50
+ msgid "Building movie boxes"
51
+ msgstr ""
52
+
53
+ msgid "Downloading movies info"
54
+ msgstr ""
55
+
56
+ msgid "GIMDB"
57
+ msgstr ""
58
+
59
+ msgid "_File"
60
+ msgstr ""
61
+
62
+ msgid "Show movies to see"
63
+ msgstr ""
64
+
65
+ msgid "Show movies seen"
66
+ msgstr ""
67
+
68
+ msgid "Show favourites movies"
69
+ msgstr ""
70
+
71
+ msgid "Work offline"
72
+ msgstr ""
73
+
74
+ msgid "_View"
75
+ msgstr ""
76
+
77
+ msgid "Select users to manage"
78
+ msgstr ""
79
+
80
+ msgid "Select users"
81
+ msgstr ""
82
+
83
+ msgid "Edit users"
84
+ msgstr ""
85
+
86
+ msgid "Add or remove users"
87
+ msgstr ""
88
+
89
+ msgid "Show sidebar"
90
+ msgstr ""
91
+
92
+ msgid "_Help"
93
+ msgstr ""
94
+
95
+ msgid ""
96
+ "1\n"
97
+ "2\n"
98
+ "3\n"
99
+ "4\n"
100
+ "5\n"
101
+ "6\n"
102
+ "7\n"
103
+ "8\n"
104
+ "9\n"
105
+ "10"
106
+ msgstr ""
107
+
108
+ msgid "Year "
109
+ msgstr ""
110
+
111
+ msgid " to "
112
+ msgstr ""
113
+
114
+ msgid "Vote "
115
+ msgstr ""
116
+
117
+ msgid "All"
118
+ msgstr ""
119
+
120
+ msgid "Action"
121
+ msgstr ""
122
+
123
+ msgid "Adventure"
124
+ msgstr ""
125
+
126
+ msgid "Animation"
127
+ msgstr ""
128
+
129
+ msgid "Biography"
130
+ msgstr ""
131
+
132
+ msgid "Comedy"
133
+ msgstr ""
134
+
135
+ msgid "Crime"
136
+ msgstr ""
137
+
138
+ msgid "Documentary"
139
+ msgstr ""
140
+
141
+ msgid "Drama"
142
+ msgstr ""
143
+
144
+ msgid "Family"
145
+ msgstr ""
146
+
147
+ msgid "Fantasy"
148
+ msgstr ""
149
+
150
+ msgid "Film-noir"
151
+ msgstr ""
152
+
153
+ msgid "Game-show"
154
+ msgstr ""
155
+
156
+ msgid "History"
157
+ msgstr ""
158
+
159
+ msgid "Horror"
160
+ msgstr ""
161
+
162
+ msgid "Music"
163
+ msgstr ""
164
+
165
+ msgid "Musical"
166
+ msgstr ""
167
+
168
+ msgid "Mystery"
169
+ msgstr ""
170
+
171
+ msgid "News"
172
+ msgstr ""
173
+
174
+ msgid "Romance"
175
+ msgstr ""
176
+
177
+ msgid "Sci-Fi"
178
+ msgstr ""
179
+
180
+ msgid "Sport"
181
+ msgstr ""
182
+
183
+ msgid "Thriller"
184
+ msgstr ""
185
+
186
+ msgid "War"
187
+ msgstr ""
188
+
189
+ msgid "Western"
190
+ msgstr ""
191
+
192
+ msgid "Sort "
193
+ msgstr ""
194
+
195
+ msgid ""
196
+ "Movie meter\n"
197
+ "A-Z\n"
198
+ "Rating\n"
199
+ "Number of votes\n"
200
+ "Runtime\n"
201
+ "Year"
202
+ msgstr ""
203
+
204
+ msgid "DESC"
205
+ msgstr ""
206
+
207
+ msgid "Hide seen"
208
+ msgstr ""
209
+
210
+ msgid "Show only to see"
211
+ msgstr ""
212
+
213
+ msgid "Manage users"
214
+ msgstr ""
215
+
216
+ msgid "Select all users"
217
+ msgstr ""
data/po/it/gimdb.po ADDED
@@ -0,0 +1,233 @@
1
+ # Italian translations for PACKAGE package
2
+ # Traduzioni italiane per il pacchetto PACKAGE..
3
+ # Copyright (C) 2010 THE PACKAGE'S COPYRIGHT HOLDER
4
+ # This file is distributed under the same license as the PACKAGE package.
5
+ # pioz <enrico@megiston.it>, 2010.
6
+ #
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: gimdb\n"
10
+ "POT-Creation-Date: 2010-05-08 16:42+0200\n"
11
+ "PO-Revision-Date: 2010-05-06 01:52+0200\n"
12
+ "Last-Translator: pioz <enrico@megiston.it>\n"
13
+ "Language-Team: Italian\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=UTF-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
18
+
19
+ #: movie_box.rb:53
20
+ msgid "Genres"
21
+ msgstr "Generi"
22
+
23
+ #: movie_box.rb:75
24
+ msgid "<b>To see</b>"
25
+ msgstr "<b>Da vedere</b>"
26
+
27
+ #: movie_box.rb:76
28
+ msgid "<b>Seen</b>"
29
+ msgstr "<b>Visto</b>"
30
+
31
+ #: movie_box.rb:77
32
+ msgid "<b>Favourites</b>"
33
+ msgstr "<b>Preferito</b>"
34
+
35
+ #: gimdb.rb:158
36
+ msgid "Searching"
37
+ msgstr "Ricerca in corso"
38
+
39
+ #: gimdb.rb:345
40
+ msgid "New user added"
41
+ msgstr "Nuovo utente aggiunto"
42
+
43
+ #: gimdb.rb:362
44
+ msgid "User deleted"
45
+ msgstr "Utente cancellato"
46
+
47
+ msgid "Downloading movie posters"
48
+ msgstr "Scarico le locandine dei film"
49
+
50
+ msgid "Building movie boxes"
51
+ msgstr "Costruisco i box dei film"
52
+
53
+ msgid "Downloading movies info"
54
+ msgstr "Scarico le informazioni dei film"
55
+
56
+ msgid "GIMDB"
57
+ msgstr "GIMDB"
58
+
59
+ msgid "_File"
60
+ msgstr "_File"
61
+
62
+ msgid "Show movies to see"
63
+ msgstr "Mostra i film da vedere"
64
+
65
+ msgid "Show movies seen"
66
+ msgstr "Mostra i film visti"
67
+
68
+ msgid "Show favourites movies"
69
+ msgstr "Mostra i film preferiti"
70
+
71
+ msgid "Work offline"
72
+ msgstr "Lavora scollegato"
73
+
74
+ msgid "_View"
75
+ msgstr "_Visualizza"
76
+
77
+ msgid "Select users to manage"
78
+ msgstr "Seleziona utenti da controllare"
79
+
80
+ msgid "Select users"
81
+ msgstr "Seleziona utenti"
82
+
83
+ msgid "Edit users"
84
+ msgstr "Modifica utenti"
85
+
86
+ msgid "Add or remove users"
87
+ msgstr "Aggiungi o rimuovi utenti"
88
+
89
+ msgid "Show sidebar"
90
+ msgstr "Mostra barra laterale"
91
+
92
+ msgid "_Help"
93
+ msgstr "A_iuto"
94
+
95
+ msgid ""
96
+ "1\n"
97
+ "2\n"
98
+ "3\n"
99
+ "4\n"
100
+ "5\n"
101
+ "6\n"
102
+ "7\n"
103
+ "8\n"
104
+ "9\n"
105
+ "10"
106
+ msgstr ""
107
+ "1\n"
108
+ "2\n"
109
+ "3\n"
110
+ "4\n"
111
+ "5\n"
112
+ "6\n"
113
+ "7\n"
114
+ "8\n"
115
+ "9\n"
116
+ "10"
117
+
118
+ msgid "Year "
119
+ msgstr "Anno "
120
+
121
+ msgid " to "
122
+ msgstr " a "
123
+
124
+ msgid "Vote "
125
+ msgstr "Voti "
126
+
127
+ msgid "All"
128
+ msgstr "Tutti"
129
+
130
+ msgid "Action"
131
+ msgstr "Azione"
132
+
133
+ msgid "Adventure"
134
+ msgstr "Avventura"
135
+
136
+ msgid "Animation"
137
+ msgstr "Animazione"
138
+
139
+ msgid "Biography"
140
+ msgstr "Biografia"
141
+
142
+ msgid "Comedy"
143
+ msgstr "Commedia"
144
+
145
+ msgid "Crime"
146
+ msgstr "Crimine"
147
+
148
+ msgid "Documentary"
149
+ msgstr "Documentario"
150
+
151
+ msgid "Drama"
152
+ msgstr "Dramma"
153
+
154
+ msgid "Family"
155
+ msgstr "Famiglia"
156
+
157
+ msgid "Fantasy"
158
+ msgstr "Fantasy"
159
+
160
+ msgid "Film-noir"
161
+ msgstr "Film-noir"
162
+
163
+ msgid "Game-show"
164
+ msgstr "Game-show"
165
+
166
+ msgid "History"
167
+ msgstr "Storico"
168
+
169
+ msgid "Horror"
170
+ msgstr "Horror"
171
+
172
+ msgid "Music"
173
+ msgstr "Musica"
174
+
175
+ msgid "Musical"
176
+ msgstr "Musical"
177
+
178
+ msgid "Mystery"
179
+ msgstr "Mistero"
180
+
181
+ msgid "News"
182
+ msgstr "News"
183
+
184
+ msgid "Romance"
185
+ msgstr "Romanzo"
186
+
187
+ msgid "Sci-Fi"
188
+ msgstr "Sci-Fi"
189
+
190
+ msgid "Sport"
191
+ msgstr "Sport"
192
+
193
+ msgid "Thriller"
194
+ msgstr "Thriller"
195
+
196
+ msgid "War"
197
+ msgstr "Guerra"
198
+
199
+ msgid "Western"
200
+ msgstr "Western"
201
+
202
+ msgid "Sort "
203
+ msgstr "Ordina "
204
+
205
+ msgid ""
206
+ "Movie meter\n"
207
+ "A-Z\n"
208
+ "Rating\n"
209
+ "Number of votes\n"
210
+ "Runtime\n"
211
+ "Year"
212
+ msgstr ""
213
+ "Movie meter\n"
214
+ "A-Z\n"
215
+ "Votazione\n"
216
+ "Numero di voti\n"
217
+ "Durata\n"
218
+ "Anno"
219
+
220
+ msgid "DESC"
221
+ msgstr "Inverso"
222
+
223
+ msgid "Hide seen"
224
+ msgstr "Nascondi film visti"
225
+
226
+ msgid "Show only to see"
227
+ msgstr "Mostra solo film da vedere"
228
+
229
+ msgid "Manage users"
230
+ msgstr "Gestisci utenti"
231
+
232
+ msgid "Select all users"
233
+ msgstr "Seleziona tutti gli utenti"
data/src/controller.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'lib/imdb'
2
+ require 'src/model'
3
+
4
+
5
+ module Controller
6
+
7
+ def self.process_info(imdb, options = {})
8
+ if options[:offline]
9
+ unless options[:next]
10
+ return Movie.get_list(options)
11
+ else
12
+ return Movie.next
13
+ end
14
+ else
15
+ movies = []
16
+ unless options[:next]
17
+ res = imdb.get_list(options) { |step, max, text| yield(step, max, text) if block_given? }
18
+ else
19
+ res = imdb.next { |step, max, text| yield(step, max, text) if block_given? }
20
+ end
21
+ i = 0
22
+ res.sort{|x,y| x[0] <=> y[0]}.each do |k,v|
23
+ if block_given?
24
+ yield(i, res.size, 'Downloading movie posters')
25
+ i = i + 1
26
+ end
27
+ record = Movie.find(:first, :conditions => "code = '#{v[:code]}'")
28
+ if record.nil?
29
+ record = Movie.new(v)
30
+ options[:path] ||= "#{$GIMDB_PATH}/posters/"
31
+ image_path = "#{options[:path]}#{record.code}.jpg"
32
+ if imdb.get_image(record.image_url, image_path)
33
+ record.image_path = image_path
34
+ end
35
+ record.save!
36
+ else
37
+ imdb.get_image(record.image_url, record.image_path) if !record.image_path.nil? && !File.exists?(record.image_path)
38
+ if (Time.now - record.updated_at) > 1.day
39
+ record.update_attributes(v.merge(:updated_at => Time.now))
40
+ record.save!
41
+ end
42
+ end
43
+ movies << record
44
+ end
45
+ yield(res.size, res.size) if block_given?
46
+ return movies
47
+ end
48
+ end
49
+
50
+ end