myimdb 0.3.2 → 0.3.3
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/VERSION +1 -1
- data/bin/myimdb +53 -11
- data/bin/myimdb-catalogue +33 -33
- data/lib/myimdb/scraper/string_extensions.rb +11 -0
- data/myimdb.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
data/bin/myimdb
CHANGED
@@ -1,20 +1,62 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'optparse'
|
4
|
+
require 'myimdb'
|
4
5
|
|
5
|
-
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: #{File.basename($0)} [movie name]"
|
10
|
+
|
11
|
+
opts.on("-h", "--help", "Displays this help info") do
|
12
|
+
puts opts
|
13
|
+
exit 0
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on("-r", "--rottentomatoes", "Generates data from Rotten Tomatoes") do
|
17
|
+
options[:rottentomatoes] = true
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-m", "--metacritic", "Generates data from Metacritic") do
|
21
|
+
options[:metacritic] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("-i", "--imdb", "Generates data from Imdb") do
|
25
|
+
options[:imdb] = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
opts.parse!(ARGV)
|
30
|
+
rescue OptionParser::ParseError => e
|
31
|
+
warn e.message
|
32
|
+
puts opts
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# add imdb as default
|
38
|
+
options.merge!(:imdb=> true) if options.empty?
|
6
39
|
|
7
|
-
|
8
|
-
|
9
|
-
|
40
|
+
# need a movie name
|
41
|
+
if ARGV.empty?
|
42
|
+
abort "Movie name required - exiting"
|
10
43
|
end
|
11
44
|
|
12
|
-
|
45
|
+
name = ARGV.join(' ')
|
13
46
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
47
|
+
def details(klass_name, name)
|
48
|
+
search_scope = "#{klass_name.downcase}.com"
|
49
|
+
|
50
|
+
search_result = Myimdb::Search::Google.search_text(name, :restrict_to=> search_scope)[0]
|
51
|
+
site = "Myimdb::Scraper::#{klass_name}".constantize.new(search_result["url"])
|
52
|
+
print "====================================================\n"
|
53
|
+
print "#{klass_name} details for: #{name}\n"
|
54
|
+
print "====================================================\n"
|
55
|
+
print "#{site.summary}\n"
|
18
56
|
rescue
|
19
|
-
p "Unable to fetch details for: #{name}"
|
57
|
+
p "Unable to fetch #{klass_name} details for: #{name}"
|
20
58
|
end
|
59
|
+
|
60
|
+
['Imdb', 'RottenTomatoes', 'Metacritic'].each do |site|
|
61
|
+
details(site, name) if options[site.downcase.to_sym]
|
62
|
+
end
|
data/bin/myimdb-catalogue
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# point this file to a folder and all the folder inside it will be renamed
|
4
|
-
require 'myimdb.rb'
|
5
|
-
|
6
|
-
unless ARGV[0]
|
7
|
-
p "Source directory required - exiting"
|
8
|
-
exit(0)
|
9
|
-
end
|
10
|
-
|
11
|
-
file_paths = Dir["#{ARGV[0]}/*"]
|
12
|
-
search_scope = "imdb.com"
|
13
|
-
|
14
|
-
file_paths.each do |path|
|
15
|
-
next if !File.directory?(path)
|
16
|
-
p "============================================"
|
17
|
-
name = File.basename(path)
|
18
|
-
if name.scan(/\[.*?\]/).size == 3
|
19
|
-
p "Skipping: #{name}"
|
20
|
-
else
|
21
|
-
p "Fetching details for: #{name}"
|
22
|
-
begin
|
23
|
-
search_result = Myimdb::Search::Google.search_text(name, search_scope)[0]
|
24
|
-
imdb = Myimdb::Scraper::Imdb.new(search_result["url"])
|
25
|
-
new_name = name.gsub(/\[\S+\]/, "").strip
|
26
|
-
new_name << " [#{imdb.year}] [#{imdb.rating},#{imdb.votes}] [#{imdb.directors.join(',')}]"
|
27
|
-
p "Renaming: #{name} to: #{new_name}"
|
28
|
-
new_path = File.join(File.dirname(path), new_name)
|
29
|
-
File.rename(path, new_path)
|
30
|
-
rescue
|
31
|
-
p "Unable to fetch details for: #{name}"
|
32
|
-
end
|
33
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# point this file to a folder and all the folder inside it will be renamed
|
4
|
+
require 'myimdb.rb'
|
5
|
+
|
6
|
+
unless ARGV[0]
|
7
|
+
p "Source directory required - exiting"
|
8
|
+
exit(0)
|
9
|
+
end
|
10
|
+
|
11
|
+
file_paths = Dir["#{ARGV[0]}/*"]
|
12
|
+
search_scope = "imdb.com"
|
13
|
+
|
14
|
+
file_paths.each do |path|
|
15
|
+
next if !File.directory?(path)
|
16
|
+
p "============================================"
|
17
|
+
name = File.basename(path)
|
18
|
+
if name.scan(/\[.*?\]/).size == 3
|
19
|
+
p "Skipping: #{name}"
|
20
|
+
else
|
21
|
+
p "Fetching details for: #{name}"
|
22
|
+
begin
|
23
|
+
search_result = Myimdb::Search::Google.search_text(name, :restrict_to=> search_scope)[0]
|
24
|
+
imdb = Myimdb::Scraper::Imdb.new(search_result["url"])
|
25
|
+
new_name = name.gsub(/\[\S+\]/, "").strip
|
26
|
+
new_name << " [#{imdb.year}] [#{imdb.rating},#{imdb.votes}] [#{imdb.directors.join(',')}]"
|
27
|
+
p "Renaming: #{name} to: #{new_name}"
|
28
|
+
new_path = File.join(File.dirname(path), new_name)
|
29
|
+
File.rename(path, new_path)
|
30
|
+
rescue
|
31
|
+
p "Unable to fetch details for: #{name}"
|
32
|
+
end
|
33
|
+
end
|
34
34
|
end
|
@@ -23,6 +23,17 @@ module Myimdb
|
|
23
23
|
def humanize
|
24
24
|
gsub(/_/, " ").capitalize
|
25
25
|
end
|
26
|
+
|
27
|
+
def constantize
|
28
|
+
names = self.split('::')
|
29
|
+
names.shift if names.empty? || names.first.empty?
|
30
|
+
|
31
|
+
constant = Object
|
32
|
+
names.each do |name|
|
33
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
34
|
+
end
|
35
|
+
constant
|
36
|
+
end
|
26
37
|
end
|
27
38
|
end
|
28
39
|
end
|
data/myimdb.gemspec
CHANGED