nokaya 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 829ce1f0a2fb95b1457d4468404cfdd2d8182d79
4
- data.tar.gz: 4557e163eaf1a75d5ca16b278d86c78a49a825a9
3
+ metadata.gz: d57534b0d6d2649c4953b4870d6e274e1b509429
4
+ data.tar.gz: b622d24ff01c28a194b7abf542e102c38bcc28e0
5
5
  SHA512:
6
- metadata.gz: 66c8937d7a0068491ba9b5e9222c56ebe2129de35f90d2adddb80adbc71af428fe304e6f43f53df78971a07acb0f7bcd1d7dcb2f1aaeabb6e2b37bb4e91231fb
7
- data.tar.gz: 1439a5f81f8f8de3b9c321e394a4345d233d1138a9c7803e44cf2b6e76dce307a9433989ba864c61db68b1021ef9b53eb22c40be647f5e5a49f9ba63dc944fec
6
+ metadata.gz: e403602b37f9e7caf9ae3143f14c43b5131b1c8503ef8649982355211b7827f9cc88ea753e43f526206fd42dd5dceff17f1c82e5716fe97141cd524b3e799ec4
7
+ data.tar.gz: 6e680cc80edaee91cabf1cc07ef8c431db9cb029cc093c3abfc9c7c54e9ff96ce1a97d988503983c7aed17dc7fa77471c612e37d108dfb6757ec54b30e6acf7e
@@ -1,3 +1,9 @@
1
+ # 0.1.3
2
+
3
+ - Global option: `--no-verbose`
4
+ - Error handling
5
+ - Logger
6
+
1
7
  # 0.1.2
2
8
 
3
9
  - New: appstore. Download icons + screenshots for an app name. Default: OSX, option for iOS.
data/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  # Nokaya
4
4
 
5
- CLI to download photos from several online services including Instagram, Imgur albums, Flickr albums, App.net, Tumblr pages, Photo.net, Deviantart, etc.
6
-
7
- Mac OS X only for the time being.
5
+ CLI to download photos from several online services including Instagram, Imgur albums, Flickr albums, App.net, Tumblr pages, Photo.net, Deviantart, movies, apps, songs, etc.
8
6
 
9
7
  ## Installation
10
8
 
@@ -24,27 +22,61 @@ Example:
24
22
 
25
23
  `nokaya -i http://ift.tt/1m2Nvz8`
26
24
 
27
- ### Tumblr post
25
+ ### Movie
28
26
 
29
- `nokaya -tu url`
27
+ Downloads a movie poster given (part of) a movie title.
28
+
29
+ `nokaya movie title`
30
30
 
31
31
  Example:
32
32
 
33
- `nokaya -tu http://spacequest.tumblr.com/post/83560738152/sexycomics-carlos-valenzuela`
33
+ `nokaya movie the dark knight`
34
34
 
35
- ### Tumblr page
35
+ Use option `-a` to get an alternative.
36
+
37
+ This is useful for remakes:
38
+
39
+ `nokaya -m solaris`
40
+
41
+ (gives the 2002 version)
42
+
43
+ `nokaya -m -a solaris`
44
+
45
+ (gives the 1972 version)
46
+
47
+ ### App store
36
48
 
37
- Due to the various themes and layouts existing for Tumblr galleries, this feature may not work perfectly...
49
+ Downloads a set of icons and screenshots for a given app name.
38
50
 
39
- Nokaya will try several techniques to extract the image links, then will fallback to scraping all available links if failing at properly detecting photos.
51
+ Defaults for Mac OSX, use option `-i` for iOS.
40
52
 
41
- `nokaya -tal url`
53
+ `nokaya appstore name`
42
54
 
43
- Example:
55
+ Examples:
44
56
 
45
- `nokaya -tal http://brekninger.tumblr.com`
57
+ `nokaya -as marked`
46
58
 
47
- Downloads all images in the visible page.
59
+ `nokaya -as -i chimp app.net`
60
+
61
+ ### Music store
62
+
63
+ Downloads available art for an iTunes Store song.
64
+
65
+ Works better if you embed separate elements between quotes.
66
+
67
+ `nokaya music 'song'`
68
+
69
+ `nokaya music 'song' 'artist' 'album'`
70
+
71
+ Examples:
72
+
73
+ `nokaya -z 'stairway to heaven'`
74
+
75
+ `nokaya -z 'stairway to heaven' 'led zeppelin'`
76
+
77
+ Use the `--album` option to find an album intead of a song:
78
+
79
+ `nokaya -z --album 'calamari tuesday'`
48
80
 
49
81
  ### Imgur album
50
82
 
@@ -66,6 +98,28 @@ Example:
66
98
 
67
99
  Downloads all images in the album (visible page).
68
100
 
101
+ ### Tumblr post
102
+
103
+ `nokaya -tu url`
104
+
105
+ Example:
106
+
107
+ `nokaya -tu http://spacequest.tumblr.com/post/83560738152/sexycomics-carlos-valenzuela`
108
+
109
+ ### Tumblr page
110
+
111
+ Due to the various themes and layouts existing for Tumblr galleries, this feature may not work perfectly...
112
+
113
+ Nokaya will try several techniques to extract the image links, then will fallback to scraping all available links if failing at properly detecting photos.
114
+
115
+ `nokaya -tal url`
116
+
117
+ Example:
118
+
119
+ `nokaya -tal http://brekninger.tumblr.com`
120
+
121
+ Downloads all images in the visible page.
122
+
69
123
  ### Photo.net page
70
124
 
71
125
  `nokaya -pnet url`
@@ -94,7 +148,9 @@ Example:
94
148
 
95
149
  `nokaya -ishu https://imageshack.com/user/ToddGilbert`
96
150
 
97
- Downloads all images in the user gallery (visible page).
151
+ Downloads all images in the user gallery (visible page).
152
+
153
+ If the URL or user is invalid, will download images from the home page.
98
154
 
99
155
  ### Favd
100
156
 
@@ -112,73 +168,25 @@ Example:
112
168
 
113
169
  `nokaya adn https://photos.app.net/30055986/1`
114
170
 
115
- ### Movie
116
-
117
- Downloads a movie poster given (part of) a movie title.
118
-
119
- `nokaya movie title`
120
-
121
- Example:
122
-
123
- `nokaya movie the dark knight`
124
-
125
- Use option `-a` to get an alternative.
126
-
127
- This is useful for remakes:
128
-
129
- `nokaya -m solaris`
130
-
131
- (gives the 2002 version)
132
-
133
- `nokaya -m -a solaris`
134
-
135
- (gives the 1972 version)
136
-
137
- ### App store
138
-
139
- Downloads a set of icons and screenshots for a given app name.
140
-
141
- Defaults for Mac OSX, use option `-i` for iOS.
142
-
143
- `nokaya appstore name`
144
-
145
- Examples:
146
-
147
- `nokaya -as marked`
148
-
149
- `nokaya -as -i chimp app.net`
150
-
151
- ### Music store
152
-
153
- Downloads available art for an iTunes Store song.
154
-
155
- Works better if you embed separate elements between quotes.
156
-
157
- `nokaya music 'song'`
158
-
159
- `nokaya music 'song' 'artist' 'album'`
160
-
161
- Examples:
171
+ ## Options
162
172
 
163
- `nokaya -z 'stairway to heaven'`
173
+ ### Silent
164
174
 
165
- `nokaya -z 'stairway to heaven' 'led zeppelin'`
175
+ `--no-verbose`
166
176
 
167
- Use the `--album` option to find an album intead of a song:
177
+ Don't display current state on the screen.
168
178
 
169
- `nokaya -z --album 'calamari tuesday'`
179
+ ```
180
+ nokaya -i --no-verbose http://instagram.com/p/noANAfjJ7B/
181
+ ```
170
182
 
171
- ## Options
172
-
173
183
  ### Name
174
184
 
175
185
  `--name` or `-n`
176
186
 
177
187
  Specify a name (without extension).
178
188
 
179
- `nokaya -i http://instagram.com/p/noANAfjJ7B/ -n happy_dog`
180
-
181
- `nokaya -i http://instagram.com/p/noANAfjJ7B/ -n 'happy dog'`
189
+ `nokaya -i http://instagram.com/p/noANAfjJ7B/ -n happy_dog.jpg`
182
190
 
183
191
  ### Output
184
192
 
@@ -194,7 +202,7 @@ The picture(s) will be downloaded in '~/Downloads' if no output specified.
194
202
 
195
203
  Specify both.
196
204
 
197
- `nokaya -i http://instagram.com/p/noANAfjJ7B/ -o ~/Pics -n happy_dog`
205
+ `nokaya -i http://instagram.com/p/noANAfjJ7B/ -o ~/Pics -n happy_dog.jpg`
198
206
 
199
207
  ## Using Nokaya in a script or irb
200
208
 
@@ -208,7 +216,7 @@ result = Nokaya::Movie.new ['terminator']
208
216
  result.save
209
217
  ```
210
218
 
211
- ![Nokaya object](http://dl.dropboxusercontent.com/s/4ix4j16a004iwvd/nokaya-object.png)
219
+ ![Nokaya object](http://dl.dropboxusercontent.com/s/sh8orfyuljv1jux/nokaya-object-chimp.png)
212
220
 
213
221
 
214
222
  The argument(s) for the movie/music/app/url - for the request - *have* to be in an array.
@@ -4,5 +4,6 @@ require 'open-uri'
4
4
  require 'nokogiri'
5
5
  require 'cgi'
6
6
  require 'json'
7
+ require 'logger'
7
8
  require_relative 'nokaya/version'
8
9
  require_relative 'nokaya/app'
@@ -8,27 +8,28 @@ module Nokaya
8
8
  def initialize args, options = {}
9
9
  super(args, options)
10
10
  @type = :adn
11
- parsed = self.parse(args[0])
12
- @image_url = [self.get_basic(parsed)]
11
+ parsed = parse(args[0])
12
+ @urls = [get_basic(parsed)].compact
13
13
  @author = author(parsed)
14
- @file_name = [name()]
14
+ @filenames = name_files()
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def author page
20
- page.css('.p-nickname')[0].text
20
+ page.css('.p-nickname')[0].text unless page.nil?
21
21
  end
22
22
 
23
23
  def post_id args
24
24
  /\d+{2}/.match(args[0])
25
25
  end
26
26
 
27
- def name
28
- unless @name.nil?
29
- "#{@type.to_s}-#{@name}"
27
+ def name_files
28
+ unless @urls.empty?
29
+ @name ||= @workers.sanitize(@author)
30
+ ["#{@type.to_s}-#{@name}-#{post_id(args)}.jpg"]
30
31
  else
31
- "#{@type.to_s}-#{@workers.sanitize(@author)}-#{post_id(args)}.jpg"
32
+ []
32
33
  end
33
34
  end
34
35
 
@@ -5,7 +5,9 @@ module Nokaya
5
5
 
6
6
  package_name "Nokaya"
7
7
 
8
- %w{basic status movie workers instagram favd adn tumblr tumblr_album imgur_album flickr_album photonet deviantart imageshack_user apple appstore musicstore}.each {|file| require_relative "#{file}"}
8
+ %w{basic status movie workers instagram favd adn tumblr tumblr_album imgur_album flickr_album photonet deviantart imageshack_user apple appstore musicstore logs}.each {|file| require_relative "#{file}"}
9
+
10
+ class_option :verbose, aliases: '-V', type: :boolean, default: true, desc: 'Enable verbose mode'
9
11
 
10
12
  desc "movie TITLE", "Get the movie poster from IMDb (nokaya -m title)"
11
13
  map "-m" => :movie
@@ -13,10 +15,10 @@ module Nokaya
13
15
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
14
16
  option :alt, aliases: "-a", type: :boolean, desc: "Find an alternative response"
15
17
  def movie *args
16
- puts Status.wait
18
+ puts Status.wait if options['verbose']
17
19
  image = Movie.new(args, options)
18
20
  image.save
19
- puts Status.saved(image)
21
+ puts Status.saved(image) if options['verbose']
20
22
  end
21
23
 
22
24
  desc "appstore NAME", "Get a set of icons and screenshots for Apple apps (nokaya -as name)"
@@ -24,21 +26,21 @@ module Nokaya
24
26
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
25
27
  option :ios, aliases: "-i", type: :boolean, desc: "Search iOS apps instead of Mac OSX apps"
26
28
  def appstore *args
27
- puts Status.wait
29
+ puts Status.wait if options['verbose']
28
30
  image = AppStore.new(args, options)
29
31
  image.save
30
- puts Status.saved_album(image)
32
+ puts Status.saved_album(image) if options['verbose']
31
33
  end
32
34
 
33
- desc "music NAME", "Get available art for an iTunes Store song (nokaya -z name)"
35
+ desc "music TITLE", "Get available art for an iTunes Store song (nokaya -z title)"
34
36
  map "-z" => :music
35
37
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
36
38
  option :album, type: :boolean, desc: "Find an album instead of a track"
37
39
  def music *args
38
- puts Status.wait
40
+ puts Status.wait if options['verbose']
39
41
  image = MusicStore.new(args, options)
40
42
  image.save
41
- puts Status.saved_album(image)
43
+ puts Status.saved_album(image) if options['verbose']
42
44
  end
43
45
 
44
46
  desc "instagram URL", "Get the original picture from an Instagram page (nokaya -i url)"
@@ -46,30 +48,30 @@ module Nokaya
46
48
  option :name, aliases: "-n", type: :string, desc: "Specify a file name without extension"
47
49
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
48
50
  def instagram *args
49
- puts Status.wait
51
+ puts Status.wait if options['verbose']
50
52
  image = Instagram.new(args, options)
51
53
  image.save
52
- puts Status.saved(image)
54
+ puts Status.saved(image) if options['verbose']
53
55
  end
54
56
 
55
57
  desc "favd URL", 'Get the picture from a Favd page (nokaya favd url)'
56
58
  option :name, aliases: "-n", type: :string, desc: "Specify a file name without extension"
57
59
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
58
60
  def favd *args
59
- puts Status.wait
61
+ puts Status.wait if options['verbose']
60
62
  image = Favd.new(args, options)
61
63
  image.save
62
- puts Status.saved(image)
64
+ puts Status.saved(image) if options['verbose']
63
65
  end
64
66
 
65
- desc "adn URL", "Get the picture from a photos.app.net page (nokaya adn url)"
67
+ desc "adn URL", "Get the picture from an app.net page (nokaya adn url)"
66
68
  option :name, aliases: "-n", type: :string, desc: "Specify a file name without extension"
67
69
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
68
70
  def adn *args
69
- puts Status.wait
71
+ puts Status.wait if options['verbose']
70
72
  image = ADN.new(args, options)
71
73
  image.save
72
- puts Status.saved(image)
74
+ puts Status.saved(image) if options['verbose']
73
75
  end
74
76
 
75
77
  desc "tumblr URL", "Get the picture from a Tumblr post (nokaya -tu url)"
@@ -77,70 +79,70 @@ module Nokaya
77
79
  option :name, aliases: "-n", type: :string, desc: "Specify a file name without extension"
78
80
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
79
81
  def tumblr *args
80
- puts Status.wait
82
+ puts Status.wait if options['verbose']
81
83
  image = Tumblr.new(args, options)
82
84
  image.save
83
- puts Status.saved(image)
85
+ puts Status.saved(image) if options['verbose']
84
86
  end
85
87
 
86
88
  desc "tumblr_album URL", "Get all pictures from a Tumblr page (nokaya -tal url)"
87
89
  map "-tal" => :tumblr_album
88
90
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
89
91
  def tumblr_album *args
90
- puts Status.wait
92
+ puts Status.wait if options['verbose']
91
93
  image = TumblrAlbum.new(args, options)
92
94
  image.save
93
- puts Status.saved_album(image)
95
+ puts Status.saved_album(image) if options['verbose']
94
96
  end
95
97
 
96
98
  desc "imgur_album URL", "Get all pictures from an Imgur album (nokaya -ial url)"
97
99
  map "-ial" => :imgur_album
98
100
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
99
101
  def imgur_album *args
100
- puts Status.wait
102
+ puts Status.wait if options['verbose']
101
103
  image = ImgurAlbum.new(args, options)
102
104
  image.save
103
- puts Status.saved_album(image)
105
+ puts Status.saved_album(image) if options['verbose']
104
106
  end
105
107
 
106
108
  desc "flickr_album URL", "Get all pictures from a Flickr album (nokaya -fal url)"
107
109
  map "-fal" => :flickr_album
108
110
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
109
111
  def flickr_album *args
110
- puts Status.wait
112
+ puts Status.wait if options['verbose']
111
113
  image = FlickrAlbum.new(args, options)
112
114
  image.save
113
- puts Status.saved_album(image)
115
+ puts Status.saved_album(image) if options['verbose']
114
116
  end
115
117
 
116
118
  desc "photonet URL", "Get all pictures from a Photo.net page (nokaya -pnet url)"
117
119
  map "-pnet" => :photonet
118
120
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
119
121
  def photonet *args
120
- puts Status.wait
122
+ puts Status.wait if options['verbose']
121
123
  image = Photonet.new(args, options)
122
124
  image.save
123
- puts Status.saved_album(image)
125
+ puts Status.saved_album(image) if options['verbose']
124
126
  end
125
127
 
126
128
  desc "deviantart URL", "Get all pictures from a Deviantart gallery (nokaya -dart url)"
127
129
  map "-dart" => :deviantart
128
130
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
129
131
  def deviantart *args
130
- puts Status.wait
132
+ puts Status.wait if options['verbose']
131
133
  image = Deviantart.new(args, options)
132
134
  image.save
133
- puts Status.saved_album(image)
135
+ puts Status.saved_album(image) if options['verbose']
134
136
  end
135
137
 
136
138
  desc "imageshack_user URL", "Get all pictures from an Imageshack user gallery (nokaya -ishu url)"
137
139
  map "-ishu" => :imageshack_user
138
140
  option :output, aliases: "-o", type: :string, desc: "Specify an output path"
139
141
  def imageshack_user *args
140
- puts Status.wait
142
+ puts Status.wait if options['verbose']
141
143
  image = ImageshackUser.new(args, options)
142
144
  image.save
143
- puts Status.saved_album(image)
145
+ puts Status.saved_album(image) if options['verbose']
144
146
  end
145
147
 
146
148
  desc "version", "Displays version number and informations"
@@ -11,29 +11,34 @@ module Nokaya
11
11
  super(args, options)
12
12
  @type = :appstore
13
13
  @appname = @workers.sanitize(args.join('_'))
14
- @image_url = [grab_small(args), grab_big(args)].compact
14
+ @urls = [grab_small(args), grab_big(args)].compact
15
15
  find_screenshots(args)
16
16
  @path = "#{@path}/appstore-#{@appname}-#{@workers.timed}"
17
- @file_name = name()
17
+ @filenames = name_files()
18
18
  remove_instance_variable(:@res)
19
19
  end
20
20
 
21
21
  private
22
22
 
23
- def name
24
- @image_url.map.with_index do |url, index|
23
+ def name_files
24
+ @urls.map.with_index do |url, index|
25
25
  "#{@type.to_s}-#{@appname}-#{'%02d' % index}-#{File.basename(url).gsub('ApplicationIcon.', '')}"
26
26
  end
27
27
  end
28
28
 
29
29
  def find_icon terms
30
- itunes_url = self.create_url(terms)
31
- @res = open(itunes_url).read
30
+ itunes_url = create_url(terms)
31
+ begin
32
+ @res = open(itunes_url).read
33
+ rescue SocketError
34
+ Logs.rec.error 'No connexion'
35
+ @res = {}.to_json
36
+ end
32
37
  match = @res.match(/"#{@icon_size}":"(.*?)",/)
33
38
  unless match.nil?
34
39
  return match[1]
35
40
  else
36
- return false
41
+ return nil
37
42
  end
38
43
  end
39
44
 
@@ -49,7 +54,9 @@ module Nokaya
49
54
 
50
55
  def find_screenshots terms
51
56
  res = JSON.parse(@res)
52
- res['results'][0]['screenshotUrls'].each {|link| @image_url << link}
57
+ unless res.empty? || res['results'].empty?
58
+ res['results'][0]['screenshotUrls'].each {|link| @urls << link}
59
+ end
53
60
  end
54
61
 
55
62
  end
@@ -3,15 +3,16 @@ module Nokaya
3
3
 
4
4
  class Basic
5
5
 
6
- attr_reader :options, :args, :file_name, :type, :name, :path
7
- attr_accessor :image_url
6
+ attr_reader :options, :args, :filenames, :type, :name, :path
7
+ attr_accessor :urls
8
8
 
9
9
  def initialize args, options
10
+ Logs.create_logger
10
11
  @options = options
11
12
  @workers = Workers.new(options)
12
- @args = @workers.check_args(args)
13
- @file_name = []
14
- @image_url = []
13
+ @args = args
14
+ @filenames = []
15
+ @urls = []
15
16
  @path = @workers.path
16
17
  @type = :basic
17
18
  @name = options['name'] if options['name']
@@ -19,16 +20,36 @@ module Nokaya
19
20
  end
20
21
 
21
22
  def get_basic page
22
- page.xpath("//meta[@property='og:image']/@content").first.value
23
+ page.xpath("//meta[@property='og:image']/@content").first.value unless page.nil?
23
24
  end
24
25
 
25
26
  def parse url
26
- Nokogiri::HTML(open url)
27
+ begin
28
+ Nokogiri::HTML(open url)
29
+ rescue Errno::ENOENT => e
30
+ Logs.rec.error e
31
+ puts Status.no_url if options['verbose']
32
+ return nil
33
+ rescue OpenURI::HTTPError => e
34
+ Logs.rec.error e
35
+ puts Status.no_can_do if options['verbose']
36
+ return nil
37
+ rescue Exception => e
38
+ Logs.rec.error e
39
+ puts Status.error if options['verbose']
40
+ return nil
41
+ end
27
42
  end
28
43
 
29
44
  def save
30
45
  @workers.save(self)
31
46
  end
32
47
 
48
+ def name_files
49
+ @urls.map do |url|
50
+ "#{@type.to_s}-#{@author}-#{File.basename(url)}"
51
+ end
52
+ end
53
+
33
54
  end
34
55
  end
@@ -6,11 +6,11 @@ module Nokaya
6
6
  def initialize args, options = {}
7
7
  super(args, options)
8
8
  @type = :deviantart
9
- parsed = self.parse(args[0])
10
- @image_url = album(parsed).compact
9
+ parsed = parse(args[0])
10
+ @urls = album(parsed).compact
11
11
  @author = author()
12
12
  @path = "#{@path}/deviantart-#{@author}-#{@workers.timed}"
13
- @file_name = name()
13
+ @filenames = name_files()
14
14
  end
15
15
 
16
16
  private
@@ -20,15 +20,10 @@ module Nokaya
20
20
  end
21
21
 
22
22
  def album page
23
+ return [] if page.nil?
23
24
  refs = page.css('a.thumb')
24
25
  refs.map {|li| li['data-super-img']}
25
26
  end
26
27
 
27
- def name
28
- @image_url.map do |url|
29
- "#{@type.to_s}-#{File.basename(url)}"
30
- end
31
- end
32
-
33
28
  end
34
29
  end
@@ -8,27 +8,30 @@ module Nokaya
8
8
  def initialize args, options = {}
9
9
  super(args, options)
10
10
  @type = :favd
11
- parsed = self.parse(args[0])
12
- @image_url = [get_favd(parsed)]
11
+ parsed = parse(args[0])
12
+ @urls = get_favd(parsed).compact
13
13
  @author = author(parsed)
14
- @file_name = [name()]
14
+ @filenames = name_files()
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def author page
20
- page.css('.username')[0].text
20
+ username = page.css('.username')
21
+ username.empty? ? [] : username[0].text
21
22
  end
22
23
 
23
24
  def get_favd page
24
- page.css('#largeImage')[0]['src']
25
+ img = page.css('#largeImage')
26
+ img.empty? ? [] : [img[0]['src']]
25
27
  end
26
28
 
27
- def name
28
- unless @name.nil?
29
- "#{@type.to_s}-#{@name}"
29
+ def name_files
30
+ unless @urls.empty?
31
+ @name ||= @workers.sanitize(@author)
32
+ ["#{@type.to_s}-#{@name}-#{@workers.timed}.jpg"]
30
33
  else
31
- "#{@type.to_s}-#{@workers.sanitize(@author)}-#{@workers.timed}.jpg"
34
+ []
32
35
  end
33
36
  end
34
37
 
@@ -8,30 +8,25 @@ module Nokaya
8
8
  def initialize args, options = {}
9
9
  super(args, options)
10
10
  @type = :flickr
11
- parsed = self.parse(args[0])
11
+ parsed = parse(args[0])
12
12
  @author = author()
13
- @image_url = album(parsed)
13
+ @urls = album(parsed).compact
14
14
  @path = "#{@path}/flickr-#{@author}-#{title(parsed)}-#{@workers.timed}"
15
- @file_name = name()
15
+ @filenames = name_files()
16
16
  end
17
17
 
18
18
  private
19
19
 
20
20
  def title page
21
- @workers.sanitize(page.css('.set-title')[0].text)
21
+ @workers.sanitize(page.css('.set-title')[0].text) unless page.nil?
22
22
  end
23
23
 
24
24
  def album page
25
+ return [] if page.nil?
25
26
  refs = page.css('.pc_img')
26
27
  refs.map {|l| l['data-defer-src']}
27
28
  end
28
29
 
29
- def name
30
- @image_url.map do |url|
31
- "#{@type.to_s}-#{@author}-#{File.basename(url)}"
32
- end
33
- end
34
-
35
30
  def author
36
31
  /photos\/\w+/.match(@args[0]).to_s.split('/')[1]
37
32
  end
@@ -6,11 +6,11 @@ module Nokaya
6
6
  def initialize args, options = {}
7
7
  super(args, options)
8
8
  @type = :imageshack
9
- parsed = self.parse(args[0])
10
- @image_url = album(parsed)
9
+ parsed = parse(args[0])
10
+ @urls = album(parsed).compact
11
11
  @author = author()
12
12
  @path = "#{@path}/imageshack-#{@author}-#{@workers.timed}"
13
- @file_name = name()
13
+ @filenames = name_files()
14
14
  end
15
15
 
16
16
  private
@@ -20,21 +20,16 @@ module Nokaya
20
20
  end
21
21
 
22
22
  def album page
23
+ return [] if page.nil?
23
24
  refs = page.css('a.hero-wrapper')
24
25
  temp = refs.map {|li| "https://imageshack.com#{li['href']}"}
25
- puts Status.toresolve(temp.length)
26
+ puts Status.toresolve(temp.length) if options['verbose']
26
27
  temp.map do |p|
27
- puts Status.resolving(p)
28
- ref = self.parse(p).css('figure.image img')
28
+ puts Status.resolving(p) if options['verbose']
29
+ ref = parse(p).css('figure.image img')
29
30
  "http:#{ref[0]['src']}"
30
31
  end
31
32
  end
32
33
 
33
- def name
34
- @image_url.map do |url|
35
- "#{@type.to_s}-#{@author}-#{File.basename(url)}"
36
- end
37
- end
38
-
39
34
  end
40
35
  end
@@ -8,27 +8,23 @@ module Nokaya
8
8
  def initialize args, options = {}
9
9
  super(args, options)
10
10
  @type = :imgur
11
- parsed = self.parse(args[0])
11
+ parsed = parse(args[0])
12
12
  @author = author(parsed)
13
- @image_url = album(parsed)
13
+ @urls = album(parsed)
14
14
  @path = "#{@path}/imgur-#{@author}-#{@workers.timed}"
15
- @file_name = name()
15
+ @filenames = name_files()
16
16
  end
17
17
 
18
18
  private
19
19
 
20
20
  def album page
21
+ return [] if page.nil?
21
22
  refs = page.css('#imagelist .posts .post a')
22
23
  refs.map {|l| "http:#{l['href']}"}
23
24
  end
24
25
 
25
- def name
26
- @image_url.map do |url|
27
- "#{@type.to_s}-#{@author}-#{File.basename(url)}"
28
- end
29
- end
30
-
31
26
  def author page
27
+ return [] if page.nil?
32
28
  res = page.css('.description')[0].children[1].children.text
33
29
  @workers.sanitize(res)
34
30
  end
@@ -8,23 +8,25 @@ module Nokaya
8
8
  def initialize args, options = {}
9
9
  super(args, options)
10
10
  @type = :instagram
11
- parsed = self.parse(args[0])
12
- @image_url = [self.get_basic(parsed)]
11
+ parsed = parse(args[0])
12
+ @urls = [get_basic(parsed)].compact
13
13
  @author = author(parsed)
14
- @file_name = [name()]
14
+ @filenames = name_files()
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def author page
20
+ return [] if page.nil?
20
21
  page.xpath("//meta[@property='instapp:owner_user_id']/@content")[0].value
21
22
  end
22
23
 
23
- def name
24
- unless @name.nil?
25
- "#{@type.to_s}-#{@name}"
24
+ def name_files
25
+ unless @urls.empty?
26
+ @name ||= @workers.sanitize(@author)
27
+ ["#{@type.to_s}-#{@workers.sanitize(@author)}-#{@workers.timed}.jpg"]
26
28
  else
27
- "#{@type.to_s}-#{@workers.sanitize(@author)}-#{@workers.timed}.jpg"
29
+ []
28
30
  end
29
31
  end
30
32
 
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+
4
+ class Logs
5
+
6
+ class << self
7
+ attr_accessor :rec
8
+ end
9
+
10
+ def self.create_logger
11
+ home = "#{Dir.home}/.nokaya"
12
+ Dir.mkdir(home) unless Dir.exist?(home)
13
+ @rec = Logger.new(home + "/log", 'monthly')
14
+ @rec.formatter = proc do |severity, datetime, progname, msg|
15
+ "#{datetime} (#{VERSION}) #{severity} * #{msg}\n"
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -10,23 +10,25 @@ module Nokaya
10
10
  def initialize args, options = {}
11
11
  super(args, options)
12
12
  @type = :movie
13
- resp = Spotlite::Movie.find(@args.join(' '))
13
+ begin
14
+ resp = Spotlite::Movie.find(@args.join(' '))
15
+ rescue SocketError
16
+ Logs.rec.error 'No connexion'
17
+ return nil
18
+ end
14
19
  @options['alt'] ? res = resp[1] : res = resp[0]
15
20
  @title = res.title
16
21
  @ref_url = res.url
17
22
  @year = res.year
18
- @image_url = [res.poster_url]
19
- @file_name = [name()]
23
+ @urls = [res.poster_url]
24
+ @filenames = [name_files()]
20
25
  end
21
26
 
22
27
  private
23
28
 
24
- def name
25
- unless @name.nil?
26
- "#{@type.to_s}-#{@name}"
27
- else
28
- "#{@type.to_s}-#{@workers.sanitize(@title)}.jpg"
29
- end
29
+ def name_files
30
+ @name ||= @workers.sanitize(@title)
31
+ "#{@type.to_s}-#{@name}"
30
32
  end
31
33
 
32
34
  end
@@ -20,14 +20,19 @@ module Nokaya
20
20
  data['results'].each do |obj|
21
21
  next if obj['collectionName'].nil?
22
22
  link = obj['artworkUrl100'].gsub('100x100', '1200x1200')
23
- next if @image_url.include?(link)
24
- @image_url << link
25
- @file_name << "#{@workers.sanitize(obj['collectionName'])}.jpg"
23
+ next if @urls.include?(link)
24
+ @urls << link
25
+ @filenames << "#{@workers.sanitize(obj['collectionName'])}.jpg"
26
26
  end
27
27
  end
28
28
 
29
29
  def get url
30
- JSON.parse(open(url).read)
30
+ begin
31
+ JSON.parse(open(url).read)
32
+ rescue SocketError
33
+ Logs.rec.error 'No connexion'
34
+ return {'results' => []}
35
+ end
31
36
  end
32
37
 
33
38
  end
@@ -6,23 +6,24 @@ module Nokaya
6
6
  def initialize args, options = {}
7
7
  super(args, options)
8
8
  @type = :photonet
9
- parsed = self.parse(args[0])
10
- @image_url = album(parsed)
9
+ parsed = parse(args[0])
10
+ @urls = album(parsed)
11
11
  @path = "#{@path}/photonet-#{@workers.timed}"
12
- @file_name = name()
12
+ @filenames = name_files()
13
13
  end
14
14
 
15
15
  private
16
16
 
17
17
  def album page
18
+ return [] if page.nil?
18
19
  refs = page.css('.trp-top a')
19
20
  refs.map do |lin|
20
21
  "http://gallery.photo.net/photo/#{lin['href'].split("=").last}-lg.jpg"
21
22
  end
22
23
  end
23
24
 
24
- def name
25
- @image_url.map do |url|
25
+ def name_files
26
+ @urls.map do |url|
26
27
  "#{@type.to_s}-#{File.basename(url).gsub('-lg', '')}"
27
28
  end
28
29
  end
@@ -5,23 +5,20 @@ module Nokaya
5
5
  def initialize args, options = {}
6
6
  super(args, options)
7
7
  @type = :tumblr
8
- parsed = self.parse(args[0])
9
- @image_url = [self.get_basic(parsed)]
10
- @file_name = [name()]
8
+ parsed = parse(args[0])
9
+ @urls = [get_basic(parsed)] unless parsed.nil?
10
+ @filenames = [name_files()]
11
11
  end
12
12
 
13
13
  private
14
14
 
15
- def name
16
- unless @name.nil?
17
- "#{@type.to_s}-#{@name}"
18
- else
19
- "#{@type.to_s}-#{base()}"
20
- end
15
+ def name_files
16
+ @name ||= base()
17
+ "#{@type.to_s}-#{@name}"
21
18
  end
22
19
 
23
20
  def base
24
- File.basename(@image_url[0]).gsub('tumblr_', '')
21
+ File.basename(@urls[0]).gsub('tumblr_', '') unless @urls.empty?
25
22
  end
26
23
 
27
24
  end
@@ -6,15 +6,16 @@ module Nokaya
6
6
  def initialize args, options = {}
7
7
  super(args, options)
8
8
  @type = :tumblr
9
- parsed = self.parse(args[0])
10
- @image_url = album(parsed)
11
- @file_name = name()
9
+ parsed = parse(args[0])
10
+ @urls = album(parsed)
11
+ @filenames = name_files()
12
12
  @path = "#{@path}/tumblr-#{@workers.timed}"
13
13
  end
14
14
 
15
15
  private
16
16
 
17
17
  def album page
18
+ return [] if page.nil?
18
19
  refs = []
19
20
  queries = ['img.photo', '.post .photo a img', '.entry img', 'article img', '.image img', '.item_content img', 'img.post-image', '.box img', '#allposts img', '.media img', '.wide img', '.big img', '.large img', '.gallery img', '.photos img', '.content img', 'img']
20
21
  queries.each do |query|
@@ -29,11 +30,11 @@ module Nokaya
29
30
  links << target
30
31
  end
31
32
  end
32
- links
33
+ links.compact
33
34
  end
34
35
 
35
- def name
36
- @image_url.map do |url|
36
+ def name_files
37
+ @urls.map do |url|
37
38
  "#{@type.to_s}-#{File.basename(url).gsub('tumblr_', '')}"
38
39
  end
39
40
  end
@@ -1,3 +1,3 @@
1
1
  module Nokaya
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -9,7 +9,7 @@ module Nokaya
9
9
  end
10
10
 
11
11
  def save object
12
- if object.image_url.empty?
12
+ if object.urls.empty?
13
13
  abort(Status.no_can_do)
14
14
  else
15
15
  save_images(object)
@@ -17,24 +17,12 @@ module Nokaya
17
17
  end
18
18
 
19
19
  def save_images object
20
- # if object.file_name.empty?
21
- # save_files(object)
22
- # else
23
- save_tuples(object)
24
- # end
20
+ save_tuples(object)
25
21
  end
26
22
 
27
- # def save_files object
28
- # object.image_url.each do |url|
29
- # f = File.new("#{object.path}/#{file_name(object)}", "wb")
30
- # f.puts(get_image(url))
31
- # f.close
32
- # end
33
- # end
34
-
35
23
  def save_tuples object
36
24
  begin
37
- tuples = object.image_url.zip(object.file_name)
25
+ tuples = object.urls.zip(object.filenames)
38
26
  Dir.mkdir(object.path) unless Dir.exist?(object.path)
39
27
  tuples.each do |url, name|
40
28
  f = File.new("#{object.path}/#{name}", "wb")
@@ -66,12 +54,7 @@ module Nokaya
66
54
 
67
55
  def sanitize str
68
56
  reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/
69
- str.downcase.strip.gsub(reg, '_').split(' ').join('_').squeeze('_')
70
- end
71
-
72
- def check_args args
73
- abort Status.no_url if args.empty?
74
- return args
57
+ str.downcase.strip.gsub(reg, '_').split(' ').join('_').squeeze('_') unless str.nil? || str.empty?
75
58
  end
76
59
 
77
60
  def timed
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokaya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dejonckheere
@@ -151,6 +151,7 @@ files:
151
151
  - lib/nokaya/imageshack_user.rb
152
152
  - lib/nokaya/imgur_album.rb
153
153
  - lib/nokaya/instagram.rb
154
+ - lib/nokaya/logs.rb
154
155
  - lib/nokaya/movie.rb
155
156
  - lib/nokaya/musicstore.rb
156
157
  - lib/nokaya/photonet.rb