nokaya 0.0.8 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+
4
+ class Basic
5
+
6
+ attr_reader :options, :args, :image_url, :path, :file_name, :type, :name
7
+
8
+ def initialize args, options
9
+ @options = options
10
+ @workers = Workers.new(options)
11
+ @args = @workers.check_args(args)
12
+ @file_name = []
13
+ @image_url = []
14
+ @path = @workers.path
15
+ @type = :basic
16
+ @name = options['name'] if options['name']
17
+ end
18
+
19
+ def get_basic page
20
+ page.xpath("//meta[@property='og:image']/@content").first.value
21
+ end
22
+
23
+ def parse url
24
+ Nokogiri::HTML(open url)
25
+ end
26
+
27
+ def save
28
+ @workers.save(self)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+
4
+ class Deviantart < Basic
5
+
6
+ def initialize args, options
7
+ super(args, options)
8
+ @type = :deviantart
9
+ parsed = self.parse(args[0])
10
+ @image_url = album(parsed).compact
11
+ @author = author()
12
+ @path = "#{@path}/deviantart-#{@author}-#{@workers.timed}"
13
+ @file_name = name()
14
+ end
15
+
16
+ private
17
+
18
+ def author
19
+ @workers.sanitize(@args[0].split('.com/')[1].chomp('/'))
20
+ end
21
+
22
+ def album page
23
+ refs = page.css('a.thumb')
24
+ refs.map {|li| li['data-super-img']}
25
+ end
26
+
27
+ def name
28
+ @image_url.map do |url|
29
+ "#{@type.to_s}-#{File.basename(url)}"
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+ class Favd < Basic
4
+
5
+ attr_reader :author
6
+
7
+ def initialize args, options
8
+ super(args, options)
9
+ @type = :favd
10
+ parsed = self.parse(args[0])
11
+ @image_url = [get_favd(parsed)]
12
+ @author = author(parsed)
13
+ @file_name = [name()]
14
+ end
15
+
16
+ private
17
+
18
+ def author page
19
+ page.css('.username')[0].text
20
+ end
21
+
22
+ def get_favd page
23
+ page.css('#largeImage')[0]['src']
24
+ end
25
+
26
+ def name
27
+ unless @name.nil?
28
+ "#{@type.to_s}-#{@name}"
29
+ else
30
+ "#{@type.to_s}-#{@workers.sanitize(@author)}-#{@workers.timed}.jpg"
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+
4
+ class FlickrAlbum < Basic
5
+
6
+ attr_reader :author
7
+
8
+ def initialize args, options
9
+ super(args, options)
10
+ @type = :flickr
11
+ parsed = self.parse(args[0])
12
+ @author = author()
13
+ @image_url = album(parsed)
14
+ @path = "#{@path}/flickr-#{@author}-#{title(parsed)}-#{@workers.timed}"
15
+ @file_name = name()
16
+ end
17
+
18
+ private
19
+
20
+ def title page
21
+ @workers.sanitize(page.css('.set-title')[0].text)
22
+ end
23
+
24
+ def album page
25
+ refs = page.css('.pc_img')
26
+ refs.map {|l| l['data-defer-src']}
27
+ end
28
+
29
+ def name
30
+ @image_url.map do |url|
31
+ "#{@type.to_s}-#{@author}-#{File.basename(url)}"
32
+ end
33
+ end
34
+
35
+ def author
36
+ /photos\/\w+/.match(@args[0]).to_s.split('/')[1]
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+
4
+ class ImageshackUser < Basic
5
+
6
+ def initialize args, options
7
+ super(args, options)
8
+ @type = :imageshack
9
+ parsed = self.parse(args[0])
10
+ @image_url = album(parsed)
11
+ @author = author()
12
+ @path = "#{@path}/imageshack-#{@author}-#{@workers.timed}"
13
+ @file_name = name()
14
+ end
15
+
16
+ private
17
+
18
+ def author
19
+ @args[0].split('/').last.chomp('/')
20
+ end
21
+
22
+ def album page
23
+ refs = page.css('a.hero-wrapper')
24
+ temp = refs.map {|li| "https://imageshack.com#{li['href']}"}
25
+ puts Status.toresolve(temp.length)
26
+ temp.map do |p|
27
+ puts Status.resolving(p)
28
+ ref = self.parse(p).css('figure.image img')
29
+ "http:#{ref[0]['src']}"
30
+ end
31
+ end
32
+
33
+ def name
34
+ @image_url.map do |url|
35
+ "#{@type.to_s}-#{@author}-#{File.basename(url)}"
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+
4
+ class ImgurAlbum < Basic
5
+
6
+ attr_reader :author
7
+
8
+ def initialize args, options
9
+ super(args, options)
10
+ @type = :imgur
11
+ parsed = self.parse(args[0])
12
+ @author = author(parsed)
13
+ @image_url = album(parsed)
14
+ @path = "#{@path}/imgur-#{@author}-#{@workers.timed}"
15
+ @file_name = name()
16
+ end
17
+
18
+ private
19
+
20
+ def album page
21
+ refs = page.css('#imagelist .posts .post a')
22
+ refs.map {|l| "http:#{l['href']}"}
23
+ end
24
+
25
+ def name
26
+ @image_url.map do |url|
27
+ "#{@type.to_s}-#{@author}-#{File.basename(url)}"
28
+ end
29
+ end
30
+
31
+ def author page
32
+ res = page.css('.description')[0].children[1].children.text
33
+ @workers.sanitize(res)
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+
4
+ class Instagram < Basic
5
+
6
+ attr_reader :author
7
+
8
+ def initialize args, options
9
+ super(args, options)
10
+ @type = :instagram
11
+ parsed = self.parse(args[0])
12
+ @image_url = [self.get_basic(parsed)]
13
+ @author = author(parsed)
14
+ @file_name = [name()]
15
+ end
16
+
17
+ private
18
+
19
+ def author page
20
+ page.xpath("//meta[@property='instapp:owner_user_id']/@content")[0].value
21
+ end
22
+
23
+ def name
24
+ unless @name.nil?
25
+ "#{@type.to_s}-#{@name}"
26
+ else
27
+ "#{@type.to_s}-#{@workers.sanitize(@author)}-#{@workers.timed}.jpg"
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+
4
+ class Movie < Basic
5
+
6
+ require 'spotlite'
7
+
8
+ attr_reader :title, :ref_url, :year
9
+
10
+ def initialize args, options
11
+ super(args, options)
12
+ @type = :movie
13
+ resp = Spotlite::Movie.find(@args.join(' '))
14
+ @options['alt'] ? res = resp[1] : res = resp[0]
15
+ @title = res.title
16
+ @ref_url = res.url
17
+ @year = res.year
18
+ @image_url = [res.poster_url]
19
+ @file_name = [name()]
20
+ end
21
+
22
+ private
23
+
24
+ def name
25
+ unless @name.nil?
26
+ "#{@type.to_s}-#{@name}"
27
+ else
28
+ "#{@type.to_s}-#{@workers.sanitize(@title)}.jpg"
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+
4
+ class Photonet < Basic
5
+
6
+ def initialize args, options
7
+ super(args, options)
8
+ @type = :photonet
9
+ parsed = self.parse(args[0])
10
+ @image_url = album(parsed)
11
+ @path = "#{@path}/photonet-#{@workers.timed}"
12
+ @file_name = name()
13
+ end
14
+
15
+ private
16
+
17
+ def album page
18
+ refs = page.css('.trp-top a')
19
+ refs.map do |lin|
20
+ "http://gallery.photo.net/photo/#{lin['href'].split("=").last}-lg.jpg"
21
+ end
22
+ end
23
+
24
+ def name
25
+ @image_url.map do |url|
26
+ "#{@type.to_s}-#{File.basename(url).gsub('-lg', '')}"
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -4,12 +4,18 @@ module Nokaya
4
4
  def self.downloading img_link
5
5
  "\nDownloading #{img_link}, please wait...\n\n"
6
6
  end
7
- def self.saved path
8
- "Image saved in #{path}\n\n"
7
+ def self.saved object
8
+ "Image saved in #{object.path}\n\n"
9
+ end
10
+ def self.saved_album object
11
+ "Album saved in #{object.path}\n\n"
9
12
  end
10
13
  def self.no_can_do
11
14
  "Canceled: unable to get the page contents.\n\n"
12
15
  end
16
+ def self.no_cnx
17
+ "Canceled: connexion error.\n\n"
18
+ end
13
19
  def self.no_url
14
20
  "\nYou have to specify a page URL.\n\n"
15
21
  end
@@ -25,8 +31,8 @@ module Nokaya
25
31
  def self.done
26
32
  "\nDone.\n\n"
27
33
  end
28
- def self.downloading_album dir
29
- "\nDownloading album at #{dir}/...\n\n"
34
+ def self.downloading_album
35
+ "Downloading album, please wait...\n\n"
30
36
  end
31
37
  def self.toresolve number
32
38
  "\n#{number} links to resolve.\n\n"
@@ -34,5 +40,17 @@ module Nokaya
34
40
  def self.resolving p
35
41
  "Resolving #{p}...\n"
36
42
  end
43
+ def self.searching
44
+ "\nSearching infos, please wait...\n\n"
45
+ end
46
+ def self.wait
47
+ "\nScraping the page. Downloads will start automatically. Please wait...\n\n"
48
+ end
49
+ def self.album_done
50
+ "\nAlbum downloaded.\n\n"
51
+ end
52
+ def self.no_access
53
+ "Error: can't write the file.\n\n"
54
+ end
37
55
  end
38
56
  end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+ class Tumblr < Basic
4
+
5
+ def initialize args, options
6
+ super(args, options)
7
+ @type = :tumblr
8
+ parsed = self.parse(args[0])
9
+ @image_url = [self.get_basic(parsed)]
10
+ @file_name = [name()]
11
+ end
12
+
13
+ private
14
+
15
+ def name
16
+ unless @name.nil?
17
+ "#{@type.to_s}-#{@name}"
18
+ else
19
+ "#{@type.to_s}-#{base()}"
20
+ end
21
+ end
22
+
23
+ def base
24
+ File.basename(@image_url[0]).gsub('tumblr_', '')
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+
4
+ class TumblrAlbum < Basic
5
+
6
+ def initialize args, options
7
+ super(args, options)
8
+ @type = :tumblr
9
+ parsed = self.parse(args[0])
10
+ @image_url = album(parsed)
11
+ @file_name = name()
12
+ @path = "#{@path}/tumblr-#{@workers.timed}"
13
+ end
14
+
15
+ private
16
+
17
+ def album page
18
+ refs = []
19
+ 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
+ queries.each do |query|
21
+ refs = page.css query
22
+ next if refs.empty?
23
+ break
24
+ end
25
+ links = []
26
+ refs.each do |l|
27
+ target = l['src']
28
+ unless (target == 'reblog.png' || target =~ /statcounter/ || target =~ /impixu/ || target =~ /quantserve/ || target == 'like.png')
29
+ links << target
30
+ end
31
+ end
32
+ links
33
+ end
34
+
35
+ def name
36
+ @image_url.map do |url|
37
+ "#{@type.to_s}-#{File.basename(url).gsub('tumblr_', '')}"
38
+ end
39
+ end
40
+
41
+ end
42
+ end