flickr_offline_gallery 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/bin/flickr_offline_gallery +9 -5
- data/erb/photo.html.erb +66 -8
- data/erb/photoset.html.erb +12 -4
- data/flickr_offline_gallery.gemspec +1 -1
- data/lib/flickr_offline_gallery.rb +6 -4
- data/lib/flickr_offline_gallery/photo.rb +7 -1
- data/lib/flickr_offline_gallery/photo_size.rb +4 -0
- data/lib/flickr_offline_gallery/photo_sizes.rb +4 -1
- data/lib/flickr_offline_gallery/photoset.rb +3 -2
- data/lib/flickr_offline_gallery/photoset_downloader.rb +2 -1
- data/lib/flickr_offline_gallery/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a580d31666a5ee5d84f2b08dc630443b36da3f6
|
4
|
+
data.tar.gz: a545a7e7bef7d3f5e1ba4f3f5dc981563845d9d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6ac5c2eed4dcf6bf7f961e8dcd0d978ab0d145ade7d9ef560e5d3f4e5448368fdbdd25d10874692eafe8c8eb91646b199e366cc0bc64723a5083661e12dc3e0
|
7
|
+
data.tar.gz: 1d997dac1dba5737959984232b8130c3c5eb3ff0eef1cc95e6cfc795baef0843223cfbdf9124bb48081fa05f5a6e445b26a93aa4ea69249ba9de833e943d27cf
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# FlickrOfflineGallery
|
2
2
|
|
3
3
|
A tool to cache an offline copy of a flickr photoset, complete with all the html
|
4
|
-
embed
|
4
|
+
embed snippets for all available sizes, allowing you to pick out photos for
|
5
5
|
blog posts/etc even without an internet connection.
|
6
6
|
|
7
7
|
## Installation
|
@@ -10,7 +10,7 @@ blog posts/etc even without an internet connection.
|
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
13
|
-
$ flickr_offline_gallery <Flickr photoset id>
|
13
|
+
$ FLICKR_API_KEY='<api_key>' FLICKR_SHARED_SECRET='<shared_secret>' flickr_offline_gallery <Flickr photoset id>
|
14
14
|
|
15
15
|
In a url like
|
16
16
|
`http://www.flickr.com/photos/83213379@N00/sets/72157636831703404/`, the
|
data/bin/flickr_offline_gallery
CHANGED
@@ -5,14 +5,18 @@ require 'flickr_offline_gallery'
|
|
5
5
|
FlickRaw.api_key = "#{ENV["FLICKR_API_KEY"]}"
|
6
6
|
FlickRaw.shared_secret = "#{ENV["FLICKR_SHARED_SECRET"]}"
|
7
7
|
|
8
|
-
if ARGV.size
|
8
|
+
if ARGV.size == 0
|
9
9
|
puts "FlickrOfflineGallery"
|
10
10
|
puts "--------------------"
|
11
|
-
puts "Create a local mirror of a Flickr photoset, complete with html embed
|
11
|
+
puts "Create a local mirror of a Flickr photoset, complete with html embed snippets"
|
12
|
+
puts ""
|
12
13
|
puts "\tUsage:"
|
13
|
-
puts "
|
14
|
+
puts ""
|
15
|
+
puts "\t\tFLICKR_API_KEY='<api_key>' FLICKR_SHARED_SECRET='<shared_secret>' flickr_offline_gallery <Flickr photoset id> [size to download]"
|
16
|
+
puts ""
|
17
|
+
puts "\t- size is optional, and defaults to medium_800. Available sizes depend on the Photoset"
|
14
18
|
exit
|
15
19
|
end
|
16
20
|
|
17
|
-
photoset = FlickrOfflineGallery::Photoset.new(ARGV
|
18
|
-
FlickrOfflineGallery.render_photoset(photoset)
|
21
|
+
photoset = FlickrOfflineGallery::Photoset.new(ARGV[0])
|
22
|
+
FlickrOfflineGallery.render_photoset(photoset, ARGV[1] || "medium_800")
|
data/erb/photo.html.erb
CHANGED
@@ -1,13 +1,71 @@
|
|
1
1
|
<html>
|
2
|
-
<head
|
2
|
+
<head>
|
3
|
+
<style>
|
4
|
+
body {
|
5
|
+
background-color: dimgrey;
|
6
|
+
}
|
7
|
+
textarea {
|
8
|
+
height: 200px;
|
9
|
+
width:500px;
|
10
|
+
}
|
11
|
+
h4 {
|
12
|
+
text-align: center;
|
13
|
+
margin: 5 0 5 0;
|
14
|
+
}
|
15
|
+
.right-panel {
|
16
|
+
display: inline-block;
|
17
|
+
vertical-align: top;
|
18
|
+
width:500px;
|
19
|
+
}
|
20
|
+
.html-snippets {
|
21
|
+
display: inherit;
|
22
|
+
}
|
23
|
+
.selectors {
|
24
|
+
display: inherit;
|
25
|
+
margin-top: 10px
|
26
|
+
}
|
27
|
+
</style>
|
28
|
+
</head>
|
3
29
|
<body>
|
4
|
-
<img src="<%= source %>" />
|
5
|
-
|
6
|
-
<
|
7
|
-
|
8
|
-
<
|
9
|
-
|
10
|
-
|
30
|
+
<img src="<%= source %>" />
|
31
|
+
<span class="right-panel">
|
32
|
+
<span class="html-snippets">
|
33
|
+
<% sizes.each do |size| %>
|
34
|
+
<span class="snippet" id="<%= size.key %>">
|
35
|
+
<h4><%= size.label %></h4>
|
36
|
+
<textarea><a href="<%= photo_url %>" title="<%= title %> by <%= author %>, on Flickr"><img src="<%= size.source %>" width="<%= size.width %>" height="<%= size.height %>" alt="<%= title %>"></a></textarea>
|
37
|
+
</span>
|
38
|
+
<% end %>
|
39
|
+
</span>
|
40
|
+
|
41
|
+
<span class="selectors">
|
42
|
+
<% sizes.each do |size| %>
|
43
|
+
<button onclick="script:showId('<%= size.key %>');"><%= size.label %> </button>
|
44
|
+
<% end %>
|
45
|
+
</span>
|
46
|
+
</span>
|
47
|
+
<script>
|
48
|
+
function hideSnippets() {
|
49
|
+
var tags = document.getElementsByClassName('snippet'),
|
50
|
+
i = tags.length;
|
51
|
+
while(i--)
|
52
|
+
{
|
53
|
+
tags[i].style.display = "none";
|
54
|
+
}
|
55
|
+
};
|
56
|
+
|
57
|
+
function showId(id) {
|
58
|
+
hideSnippets();
|
59
|
+
var section = document.getElementById(id);
|
60
|
+
section.style.display = "";
|
61
|
+
section.getElementsByTagName("textarea")[0].select();
|
62
|
+
};
|
63
|
+
<% if sizes["medium_800"].nil? %>
|
64
|
+
showId("original");
|
65
|
+
<% else %>
|
66
|
+
showId("medium_800");
|
67
|
+
<% end %>
|
68
|
+
</script>
|
11
69
|
</body>
|
12
70
|
</html>
|
13
71
|
|
data/erb/photoset.html.erb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
<html>
|
2
|
-
<head
|
2
|
+
<head>
|
3
|
+
<style>
|
4
|
+
body { background-color: dimgrey; }
|
5
|
+
img {
|
6
|
+
height: 200px;
|
7
|
+
padding: 0px;
|
8
|
+
margin: 0px;
|
9
|
+
border: 1px solid black;
|
10
|
+
}
|
11
|
+
</style>
|
12
|
+
</head>
|
3
13
|
<body>
|
4
|
-
|
14
|
+
<h1><%= photoset.title %> by <%= photoset.username %></h1>
|
5
15
|
<% photos.each do |photo| %>
|
6
16
|
<a href="<%= photo.local_html_path %>"><img src="<%= photo.local_jpg_path %>"
|
7
|
-
width="<%= photo.sizes[size].width %>"
|
8
|
-
height="<%= photo.sizes[size].height %>"
|
9
17
|
/></a>
|
10
18
|
<% end %>
|
11
19
|
</body>
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Lucas Parry"]
|
10
10
|
spec.email = ["lparry@gmail.com"]
|
11
11
|
spec.summary = %q{Build a local copy of a flickr photoset}
|
12
|
-
spec.description = %q{Build a local copy of a flickr photoset, including html embed
|
12
|
+
spec.description = %q{Build a local copy of a flickr photoset, including html embed snippets for all image sizes, for the purpose off picking photos for your blog even when there's no internet}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT, unless you're the NSA"
|
15
15
|
|
@@ -16,12 +16,12 @@ module FlickrOfflineGallery
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.download(photoset)
|
20
|
-
PhotosetDownloader.new(photoset).download
|
19
|
+
def self.download(photoset, size = "medium_800")
|
20
|
+
PhotosetDownloader.new(photoset, size).download
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.render_photoset(photoset)
|
24
|
-
download(photoset)
|
23
|
+
def self.render_photoset(photoset, size)
|
24
|
+
download(photoset, size)
|
25
25
|
render_photo_pages(photoset)
|
26
26
|
render_photoset_index_page(photoset)
|
27
27
|
end
|
@@ -30,6 +30,7 @@ module FlickrOfflineGallery
|
|
30
30
|
File.open("#{photoset.slug}.html", "w") do |f|
|
31
31
|
f.write render_erb("photoset", :photoset => photoset, :photos => photoset.photos, :size => "medium")
|
32
32
|
end
|
33
|
+
puts "#{photoset.slug}.html"
|
33
34
|
end
|
34
35
|
|
35
36
|
def self.render_photo_pages(photoset)
|
@@ -42,6 +43,7 @@ module FlickrOfflineGallery
|
|
42
43
|
File.open(photo.local_html_path, "w") do |f|
|
43
44
|
f.write render_erb("photo", :source => photo.img_filename, :sizes => photo.sizes, :photo_url => photo.url, :title => photo.title, :author => photo.author)
|
44
45
|
end
|
46
|
+
puts "Rendered #{photo.local_html_path}"
|
45
47
|
end
|
46
48
|
|
47
49
|
def self.render_erb(template, locals)
|
@@ -7,7 +7,8 @@ module FlickrOfflineGallery
|
|
7
7
|
@id = horrible_flickraw_response_junk["id"]
|
8
8
|
@secret = horrible_flickraw_response_junk["secret"]
|
9
9
|
@set = photoset_id
|
10
|
-
|
10
|
+
eager_load
|
11
|
+
puts "Fetched data about photo #{title}"
|
11
12
|
end
|
12
13
|
|
13
14
|
def title
|
@@ -52,6 +53,11 @@ module FlickrOfflineGallery
|
|
52
53
|
|
53
54
|
private
|
54
55
|
|
56
|
+
def eager_load
|
57
|
+
info
|
58
|
+
raw_sizes
|
59
|
+
end
|
60
|
+
|
55
61
|
def info
|
56
62
|
@info ||= OpenStruct.new(flickr.photos.getInfo(:photo_id => @id).to_hash)
|
57
63
|
end
|
@@ -2,7 +2,10 @@ module FlickrOfflineGallery
|
|
2
2
|
class PhotoSizes < OpenStruct
|
3
3
|
# commont attrs: large large_1600 large_2048 large_square medium medium_640 medium_800 original small small_320 square thumbnail
|
4
4
|
def initialize(raw_sizes)
|
5
|
-
super Hash[raw_sizes.map
|
5
|
+
super Hash[raw_sizes.map do |s|
|
6
|
+
size = PhotoSize.new(s)
|
7
|
+
[size.key, size]
|
8
|
+
end]
|
6
9
|
end
|
7
10
|
|
8
11
|
def each
|
@@ -6,7 +6,7 @@ module FlickrOfflineGallery
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def username
|
9
|
-
info.
|
9
|
+
info.ownername
|
10
10
|
end
|
11
11
|
|
12
12
|
def title
|
@@ -19,7 +19,8 @@ module FlickrOfflineGallery
|
|
19
19
|
|
20
20
|
def photos
|
21
21
|
raise "photoset has more than 500 images and I'm too lazy to handle that right now" if info.pages > 1
|
22
|
-
|
22
|
+
puts "Initializing photoset... " unless @photos
|
23
|
+
@photos ||= info.photo.map { |raw_response| Photo.new(raw_response, @photoset_id) }.tap{ puts "Finished initializing photoset!"}
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module FlickrOfflineGallery
|
2
2
|
class PhotosetDownloader
|
3
|
-
def initialize(photoset, size
|
3
|
+
def initialize(photoset, size)
|
4
4
|
@photoset = photoset
|
5
5
|
@size = size
|
6
6
|
end
|
@@ -14,6 +14,7 @@ module FlickrOfflineGallery
|
|
14
14
|
unless File.exist?(local_path)
|
15
15
|
#TODO: this is lazy, so sue me
|
16
16
|
`curl --location -so "#{local_path}" "#{url}"`
|
17
|
+
puts "Downloaded #{local_path}"
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickr_offline_gallery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Parry
|
@@ -52,9 +52,9 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description: Build a local copy of a flickr photoset, including html embed
|
56
|
-
all image sizes, for the purpose off picking photos for your blog even when
|
57
|
-
no internet
|
55
|
+
description: Build a local copy of a flickr photoset, including html embed snippets
|
56
|
+
for all image sizes, for the purpose off picking photos for your blog even when
|
57
|
+
there's no internet
|
58
58
|
email:
|
59
59
|
- lparry@gmail.com
|
60
60
|
executables:
|