myimdb 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/bin/myimdb-catalogue +70 -33
  3. data/myimdb.gemspec +1 -1
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
data/bin/myimdb-catalogue CHANGED
@@ -4,6 +4,22 @@ require 'open-uri'
4
4
  require 'optparse'
5
5
  require 'myimdb'
6
6
 
7
+ class Platform
8
+ class << self
9
+ def windows?
10
+ RUBY_PLATFORM =~ /mswin|windows/i
11
+ end
12
+
13
+ def mac?
14
+ RUBY_PLATFORM =~ /darwin/i
15
+ end
16
+
17
+ def linux?
18
+ RUBY_PLATFORM =~ /linux/i
19
+ end
20
+ end
21
+ end
22
+
7
23
  options = {}
8
24
 
9
25
  OptionParser.new do |opts|
@@ -22,9 +38,15 @@ OptionParser.new do |opts|
22
38
  options[:metadata] = true
23
39
  end
24
40
 
25
- opts.on("-i", "--images", "Generates images (only applies to windows)") do
41
+ opts.on("-i", "--images", "Generates images (works properly only on windows)") do
26
42
  options[:images] = true
27
43
  end
44
+
45
+ if Platform.windows?
46
+ opts.on("-r", "--rebuild-permissions", "Rebuilds permissions (useful if the icons have been changed manually)") do
47
+ options[:'rebuild-permissions'] = true
48
+ end
49
+ end
28
50
 
29
51
  begin
30
52
  opts.parse!(ARGV)
@@ -43,47 +65,65 @@ if ARGV.empty?
43
65
  abort "Source directory required - exiting"
44
66
  end
45
67
 
46
- class Platform
47
- class << self
48
- def windows?
49
- RUBY_PLATFORM =~ /mswin|windows/i
50
- end
51
-
52
- def mac?
53
- RUBY_PLATFORM =~ /darwin/i
54
- end
55
-
56
- def linux?
57
- RUBY_PLATFORM =~ /linux/i
58
- end
68
+ file_paths = Dir["#{ARGV[0]}/*"]
69
+
70
+
71
+ # helper methods
72
+ def conf_file_name
73
+ 'desktop.ini'
74
+ end
75
+
76
+ def icon_file_path
77
+ if Platform.windows?
78
+ 'movie.ico'
79
+ else
80
+ 'movie.png'
59
81
  end
60
82
  end
61
83
 
62
- file_paths = Dir["#{ARGV[0]}/*"]
84
+ def filtered_movie_name(name)
85
+ name.gsub(/\[.*?\]/,'').strip
86
+ end
87
+
88
+ def filtered_movie_year(name)
89
+ name.scan(/\[(\d+)\]/).flatten.first
90
+ end
91
+ # helper methods - end
92
+
93
+ def repair_permissions_for(target_dir)
94
+ conf_file_path = File.join(target_dir, conf_file_name)
95
+ File.delete(conf_file_path) if File.exists?(conf_file_path)
96
+
97
+ File.open(conf_file_path, 'wb') do |conf|
98
+ conf.puts "[.ShellClassInfo]"
99
+ conf.puts "IconResource=movie.ico,0"
100
+ end
101
+
102
+ `attrib -s +h "#{conf_file_path}"`
103
+ `attrib -r "#{target_dir}"`
104
+ `attrib +r "#{target_dir}"`
105
+ end
106
+
107
+ def convert_to_icon(image_file_path, icon_file_path)
108
+ `convert "#{image_file_path}" -thumbnail 256x256 -gravity center -crop 256x256+0+0! -background transparent -flatten "#{File.join(target_dir, '#{icon_file_path}')}"`
109
+ end
63
110
 
64
111
  def save_image(target_dir, name, image_index=0)
65
112
  image_data = Myimdb::Search::Google.search_images(name, :size=> 'medium')[image_index]
66
113
  image_url = image_data["url"] if image_data
114
+
67
115
  if image_url
68
116
  image_file_path = File.join(target_dir, 'movie.jpg')
69
- conf_file_path = File.join(target_dir, 'desktop.ini')
70
117
  open(image_url) do |file|
71
118
  File.open(image_file_path, 'wb') do |image_file|
72
119
  image_file.puts file.read
73
120
  end
74
121
  end
75
122
 
76
- `convert "#{image_file_path}" -thumbnail 256x256 -gravity center -crop 256x256+0+0! -background transparent -flatten "#{File.join(target_dir, 'movie.ico')}"`
123
+ convert_to_icon(image_file_path, icon_file_path)
77
124
 
78
125
  if Platform.windows?
79
- File.delete(conf_file_path) if File.exists?(conf_file_path)
80
- File.open(conf_file_path, 'wb') do |conf|
81
- conf.puts "[.ShellClassInfo]"
82
- conf.puts "IconResource=movie.ico,0"
83
- end
84
- `attrib -s +h "#{conf_file_path}"`
85
- `attrib -r "#{target_dir}"`
86
- `attrib +r "#{target_dir}"`
126
+ repair_permissions_for(target_dir)
87
127
  end
88
128
 
89
129
  File.delete(image_file_path)
@@ -103,14 +143,6 @@ def generate_metadata(path, name)
103
143
  new_path
104
144
  end
105
145
 
106
- def filtered_movie_name(name)
107
- name.gsub(/\[.*?\]/,'').strip
108
- end
109
-
110
- def filtered_movie_year(name)
111
- name.scan(/\[(\d+)\]/).flatten.first
112
- end
113
-
114
146
 
115
147
  image_retry_limit = 2
116
148
 
@@ -119,6 +151,7 @@ file_paths.each do |path|
119
151
  metadata_present = false
120
152
 
121
153
  next if !File.directory?(path)
154
+
122
155
  begin
123
156
  name = File.basename(path)
124
157
 
@@ -145,6 +178,10 @@ file_paths.each do |path|
145
178
  retry_count < image_retry_limit ? retry : raise
146
179
  end
147
180
  end
181
+
182
+ if options[:'rebuild-permissions']
183
+ repair_permissions_for(path)
184
+ end
148
185
  rescue
149
186
  p "Unable to fetch details for: #{name}"
150
187
  end
data/myimdb.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{myimdb}
8
- s.version = "0.3.5"
8
+ s.version = "0.3.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gaurav"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myimdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaurav