image_puller 0.2.1 → 0.2.2

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
  SHA256:
3
- metadata.gz: d133a19581ee2fb6f89e4e3a5bc2817ac506ebb0c6f44d318c72a6dc47e51201
4
- data.tar.gz: 290ea3e4333c5661c12ac71a72572ca8aff7d9028d74e9c982cabebb8d818f5b
3
+ metadata.gz: f4d6f8b3aa69adcf0996129eaf61997b38c572a8790a28b073b9b57ed443a4cf
4
+ data.tar.gz: 89bc1c0fcacaf36278147e4a99500b89b318efc2b5103fc107ab05254f80e387
5
5
  SHA512:
6
- metadata.gz: c48c85d593d022257c28e755792a8c8f95df4453ad576e74ff6c8c55e94c16484eff75a7ced5aa2f68e7dfa62adf3fca98a28847f6a29afcc087e06c99c33450
7
- data.tar.gz: 43195582ea12aeea215168901cf986a4bfe81e3bdf21be8b2b7bfa97ac87f845d77fab39027d7273f1533161104c3209edf68239c8251ead4771e06caa0e565d
6
+ metadata.gz: afabc83d0bd69cd3ca1ee343a792e94d3f968c4373efec8c754a1075a7521518b11ee4ed387ce690a0f72bf92a9bd0bc37ab171a3a2bb9053303f0cd5ead9236
7
+ data.tar.gz: 7258cc5690096c4bab21ee6a76e087cf1ece5cc0874dbdf69d4d6a985e948a44621bcfac22143d1618a5ee0b408ef122f5fc7963fd8254d030cd50efab54b04e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- image_puller (0.2.1)
4
+ image_puller (0.2.2)
5
5
  activesupport (~> 5.2)
6
6
  flickraw
7
7
  ruby-progressbar (~> 1.10)
data/README.md CHANGED
@@ -39,7 +39,6 @@ Example settings file
39
39
  "OUTPUT_PATH": "path to export to",
40
40
  "FLICKR_USER_ID": "https://www.flickr.com/services/api/explore/?method=flickr.people.getInfo under 'Your User ID'",
41
41
  "PHOTO": "false",
42
- "VIDEO": "true",
43
42
  "PULLER_TYPE": "flickr",
44
43
  "FLICKR_STARTING_PAGE": 0
45
44
  }
data/failed items ADDED
@@ -0,0 +1,18 @@
1
+ cannot download https://www.flickr.com/photos/105860661@N02/24198129478/play/orig/c8e5749bc2/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/MK_TSHOLIDAY_20171013_8109792074.jpg error: 404 Not Found |
2
+ cannot download https://www.flickr.com/photos/105860661@N02/24198129478/play/orig/c8e5749bc2/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/MK_TSHOLIDAY_20171013_8109792074.jpg error: 404 Not Found |
3
+ cannot download https://www.flickr.com/photos/105860661@N02/38051132251/play/orig/d70bbe8237/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/EPCOT_ECENTR1_20171019_8112946569.jpg error: 404 Not Found |
4
+ Page 8/14: |================================================================================================================================================================================================================================|
5
+ cannot download https://www.flickr.com/photos/105860661@N02/26244735229/play/orig/cc9b2d2a58/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171026-WA0001.jpg error: 404 Not Found |
6
+ cannot download https://www.flickr.com/photos/105860661@N02/37989896432/play/orig/6c446f28d3/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171026-WA0002.jpg error: 404 Not Found |
7
+ cannot download https://www.flickr.com/photos/105860661@N02/37311335954/play/orig/661f938092/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171027-WA0012.jpg error: 404 Not Found |
8
+ cannot download https://www.flickr.com/photos/105860661@N02/24168590038/play/orig/c5e4c14c31/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171029-WA0000.jpg error: 404 Not Found |
9
+ cannot download https://www.flickr.com/photos/105860661@N02/37966724626/play/orig/4f13cc1315/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171029-WA0001.jpg error: 404 Not Found |
10
+ cannot download https://www.flickr.com/photos/105860661@N02/37310930364/play/orig/dee2bc3f6a/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171029-WA0002.jpg error: 404 Not Found |
11
+ cannot download https://www.flickr.com/photos/105860661@N02/37924109381/play/orig/5d218dfd58/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171016-WA0000.jpg error: 404 Not Found |
12
+ cannot download https://www.flickr.com/photos/105860661@N02/26244735229/play/orig/cc9b2d2a58/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171026-WA0001.jpg error: 404 Not Found |
13
+ cannot download https://www.flickr.com/photos/105860661@N02/37989896432/play/orig/6c446f28d3/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171026-WA0002.jpg error: 404 Not Found |
14
+ cannot download https://www.flickr.com/photos/105860661@N02/37311335954/play/orig/661f938092/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171027-WA0012.jpg error: 404 Not Found |
15
+ cannot download https://www.flickr.com/photos/105860661@N02/24168590038/play/orig/c5e4c14c31/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171029-WA0000.jpg error: 404 Not Found |
16
+ cannot download https://www.flickr.com/photos/105860661@N02/37966724626/play/orig/4f13cc1315/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171029-WA0001.jpg error: 404 Not Found |
17
+ cannot download https://www.flickr.com/photos/105860661@N02/37310930364/play/orig/dee2bc3f6a/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171029-WA0002.jpg error: 404 Not Found |
18
+ cannot download https://www.flickr.com/photos/105860661@N02/37924109381/play/orig/5d218dfd58/ to /Users/nicklongmore/Pictures/flickr_backup_2//Wedding & Florida & Mexico/VID-20171016-WA0000.jpg error: 404 Not Found
data/image_puller.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'image_puller'
3
- spec.version = '0.2.1'
3
+ spec.version = '0.2.2'
4
4
  spec.authors = ['Nick Longmore']
5
5
  spec.email = ['neeko99@gmail.com']
6
6
  spec.summary = 'Pulls all images from Flickr under photostreams '
@@ -6,79 +6,74 @@ module Flickr
6
6
  end
7
7
 
8
8
  MAX_RETRIES = 10
9
+ PER_PAGE = 500
10
+
9
11
 
10
12
  def download
11
13
  page = ENV['FLICKR_STARTING_PAGE'].to_i
12
- per_page = 100
13
14
 
14
15
  loop do
15
16
  page += 1
16
17
 
17
18
  begin
18
19
  retry_count ||= 0
19
- images = @flickr.people.getPhotos(user_id: ENV['FLICKR_USER_ID'], page: page, per_page: per_page)
20
+ images = @flickr.people.getPhotos(user_id: ENV['FLICKR_USER_ID'], page: page, per_page: PER_PAGE)
20
21
 
21
- pb = ProgressBar.create(title: "Images Page #{page}")
22
- images.each do |photoset|
23
- get_photo(photoset['id'])
24
- pb.increment
25
- end
22
+ pb = ProgressBar.create(title: "Page #{page}/#{images['pages']}", total: PER_PAGE)
23
+ images.each { |photoset| get_photo(photoset['id']); pb.increment }
26
24
  rescue StandardError => e
27
- puts "Failed on #{page} exception: #{e.message}" if retry_count.zero?
28
-
29
25
  retry_count += 1
30
- sleep(1.minute)
31
- puts "Retry retry #{retry_count}/#{MAX_RETRIES}"
26
+ sleep(30.seconds)
32
27
  retry unless retry_count == MAX_RETRIES
28
+
29
+ puts "Failure on page #{page}"
33
30
  end
34
31
 
35
- break if images.nil? || images.size < per_page
32
+ break if images.nil? || images.size < PER_PAGE
36
33
  end
37
34
  end
38
35
 
39
36
  private
40
37
 
41
38
  def get_photo(id)
42
- # transform to json and then back to a hash so we can use hash methods
43
- photoset_details = JSON.parse(@flickr.photos.getAllContexts(photo_id: id).to_json)
44
- album_title = photoset_details.dig('set', 0, 'title') || 'misc'
45
-
46
39
  info = @flickr.photos.getInfo(photo_id: id)
47
40
 
48
- filename = "#{info['title']}.#{info['originalformat']}"
49
-
50
41
  case info['media']
51
42
  when 'photo'
52
43
  return unless ENV['PHOTO'] == 'true'
53
44
 
54
45
  url = FlickRaw.url_o(info)
55
- when 'video'
56
- return unless ENV['VIDEO'] == 'true'
57
- return unless original_video = @flickr.photos.getSizes(photo_id: id).detect{ |size| size['label'] == 'Video Original' }
58
-
59
- url = original_video['source']
46
+ filename = url.split('/')[-1]
47
+ #TODO: add support for video
60
48
  end
61
49
 
62
50
  return unless url
63
51
 
64
- url_download(url, album_title, filename)
65
-
52
+ url_download(url, path(album_title(id), filename))
66
53
  end
67
54
 
68
- def url_download(url, album_title, filename)
55
+ def url_download(url, path)
69
56
  retry_count ||= 0
70
- open(url) do |image|
71
- path = "#{ENV['OUTPUT_PATH']}/#{album_title}/#{filename}"
72
57
 
58
+ open(url) do |image|
73
59
  FileUtils.mkdir_p(File.dirname(path))
74
60
  open(path, 'wb') { |file| file.write(image.read) }
75
61
  end
76
62
  rescue StandardError => e
77
- puts "cannot download #{url} error: #{e.message}" if retry_count.zero?
78
-
79
63
  retry_count += 1
80
- puts "Retry #{retry_count}/#{MAX_RETRIES}"
81
64
  retry unless retry_count == MAX_RETRIES
65
+
66
+ puts "cannot download #{url} to #{path} error: #{e.message}"
67
+ end
68
+
69
+ def album_title(id)
70
+ # transform to json and then back to a hash so we can use hash methods
71
+ photoset_details = JSON.parse(@flickr.photos.getAllContexts(photo_id: id).to_json)
72
+ photoset_details.dig('set', 0, 'title') || 'misc'
73
+ end
74
+
75
+ def path(album_title, filename)
76
+ "#{ENV['OUTPUT_PATH']}/#{album_title}/#{filename}"
82
77
  end
83
78
  end
84
79
  end
data/lib/image_puller.rb CHANGED
@@ -29,7 +29,7 @@ class ImagePuller
29
29
  end
30
30
 
31
31
  settings = JSON.parse(File.read(settings_file_path))
32
- settings.each { |key, value| ENV[key] = value }
32
+ settings.each { |key, value| ENV[key] = value.to_s }
33
33
 
34
34
  true
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_puller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Longmore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-15 00:00:00.000000000 Z
11
+ date: 2020-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug
@@ -99,6 +99,7 @@ files:
99
99
  - bin/image_puller
100
100
  - bin/setup
101
101
  - example.json
102
+ - failed items
102
103
  - image_puller.gemspec
103
104
  - lib/flickr/authenticator.rb
104
105
  - lib/flickr/downloader.rb