wallbum 1.0.0
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 +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/LICENSE +21 -0
- data/README.md +9 -0
- data/bin/wallbum +47 -0
- data/lib/wallbum.rb +5 -0
- data/lib/wallbum/discogs_helper.rb +45 -0
- data/lib/wallbum/image.rb +22 -0
- data/lib/wallbum/image_packer.rb +38 -0
- data/lib/wallbum/rectangle.rb +111 -0
- data/wallbum.gemspec +18 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aeddd9eda35f8103e6dadfe3d2de4ef83f5eb6a7
|
4
|
+
data.tar.gz: 054b9890b90aee88662e320bff630bb02835836d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8211f027c90a7f9fd421144c5f86a5813026d2e2c150586ce0073d3608c32939f2af8f67a4dfdb3225409b88d51de6bf366009a2bee525b4ea4e925ac32297cd
|
7
|
+
data.tar.gz: cb16ff42e3b97c215962365039a7b277de60bfe4b9b44da9ff97d81a539589ad9718009054114333a648745ca4b45b992aef3b1939f9160ecc6e8c1ecb3b6fea
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
discogs-wrapper (2.0.0)
|
5
|
+
hashie (~> 2.1)
|
6
|
+
oauth (~> 0.4.7)
|
7
|
+
hashie (2.1.2)
|
8
|
+
oauth (0.4.7)
|
9
|
+
rmagick (2.13.2)
|
10
|
+
rubystats (0.2.3)
|
11
|
+
slop (3.6.0)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
discogs-wrapper
|
18
|
+
rmagick
|
19
|
+
rubystats
|
20
|
+
slop
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 John DeSilva
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/bin/wallbum
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'wallbum'
|
4
|
+
|
5
|
+
options = Slop.parse! do
|
6
|
+
banner 'Usage: wallbum {-w 1920} {-h 1080} artist'
|
7
|
+
|
8
|
+
on 'h', 'height=', 'Wallpaper Height'
|
9
|
+
on 'w', 'width=', 'Wallpaper Width'
|
10
|
+
end
|
11
|
+
|
12
|
+
if ARGV.empty?
|
13
|
+
puts options.help
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
artist_name = ARGV.join(" ")
|
18
|
+
|
19
|
+
width = options[:width] || 1920
|
20
|
+
height = options[:height] || 1080
|
21
|
+
|
22
|
+
helper = Wallbum::DiscogsHelper.new
|
23
|
+
|
24
|
+
artist_id = helper.get_discogs_artist_id(artist_name)
|
25
|
+
|
26
|
+
cache_dir = "#{Dir.home}/.wallbum/images_#{artist_id}"
|
27
|
+
|
28
|
+
unless File.directory? cache_dir
|
29
|
+
FileUtils.mkdir_p cache_dir
|
30
|
+
|
31
|
+
puts "Saving images to #{cache_dir}"
|
32
|
+
|
33
|
+
helper.get_artist_images(artist_id) do |filename, image|
|
34
|
+
puts "\t#{filename}"
|
35
|
+
File.open("#{cache_dir}/#{filename}", "wb") do |f|
|
36
|
+
f.write image.read
|
37
|
+
end
|
38
|
+
end
|
39
|
+
else
|
40
|
+
puts "Using cached images in #{cache_dir}"
|
41
|
+
end
|
42
|
+
|
43
|
+
image_files = Dir["#{cache_dir}/*"].collect
|
44
|
+
|
45
|
+
Wallbum::ImagePacking::Packer.new().pack_images(width.to_i, height.to_i, image_files) do |wallpaper|
|
46
|
+
wallpaper.write("#{artist_name.gsub(' ', '_')}.jpeg")
|
47
|
+
end
|
data/lib/wallbum.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'discogs'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module Wallbum
|
5
|
+
class DiscogsHelper
|
6
|
+
def initialize
|
7
|
+
@discogs_wrapper = Discogs::Wrapper.new('wallbum')
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_discogs_artist_id(name)
|
11
|
+
@discogs_wrapper.search(name, type: :artist).results.first.id
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_discogs_releases(artist_id)
|
15
|
+
@discogs_wrapper.get_artist_releases(artist_id).releases
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_release_images(release, &block)
|
19
|
+
return unless ['Main', 'Remix'].include? release.role
|
20
|
+
puts "Downloading '#{release.title}'"
|
21
|
+
release_images = @discogs_wrapper.get_release(release.main_release).images
|
22
|
+
unless release_images.nil?
|
23
|
+
filenames = release_images.map { |image| image.resource_url.split("/").last }
|
24
|
+
filenames.each do |fn|
|
25
|
+
yield fn,
|
26
|
+
open(
|
27
|
+
"http://s.pixogs.com/image/#{fn}",
|
28
|
+
"User-Agent" => "Mozilla/5.0",
|
29
|
+
"Referer" => "http://www.discogs.com/viewimages?release=#{release.main_release}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_artist_images(artist_id, &block)
|
35
|
+
get_discogs_releases(artist_id).each do |release|
|
36
|
+
begin
|
37
|
+
get_release_images(release) do |filename, image|
|
38
|
+
yield filename, image
|
39
|
+
end
|
40
|
+
rescue Discogs::UnknownResource
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'RMagick'
|
2
|
+
|
3
|
+
module Wallbum
|
4
|
+
module ImagePacking
|
5
|
+
class Image
|
6
|
+
|
7
|
+
attr_reader :path
|
8
|
+
attr_reader :width
|
9
|
+
attr_reader :height
|
10
|
+
attr_reader :img
|
11
|
+
attr_accessor :rectangle
|
12
|
+
|
13
|
+
def initialize(path)
|
14
|
+
@path = path
|
15
|
+
@img = Magick::Image.read(path).first
|
16
|
+
@width = @img.columns
|
17
|
+
@height = @img.rows
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative './rectangle.rb'
|
2
|
+
require_relative './image.rb'
|
3
|
+
|
4
|
+
module Wallbum
|
5
|
+
module ImagePacking
|
6
|
+
class Packer
|
7
|
+
def pack_images(size_x, size_y, images, &block)
|
8
|
+
count = images.size
|
9
|
+
|
10
|
+
puts "Making wallpaper with #{images.size} images"
|
11
|
+
|
12
|
+
root = Rectangle.new(nil, 0, 0, size_x, size_y)
|
13
|
+
|
14
|
+
while (root.child_count < count) do
|
15
|
+
root.largest_child.split
|
16
|
+
end
|
17
|
+
|
18
|
+
images.each do |fname|
|
19
|
+
rect = root.empty_child
|
20
|
+
rect.image = Image.new(fname)
|
21
|
+
end
|
22
|
+
|
23
|
+
wallpaper = Magick::Image.new(size_x, size_y) do
|
24
|
+
self.background_color = 'black'
|
25
|
+
end
|
26
|
+
|
27
|
+
root.all_children.each do |rect|
|
28
|
+
wallpaper.composite!(rect.image.img.resize_to_fill(rect.width, rect.height),
|
29
|
+
rect.x,
|
30
|
+
rect.y,
|
31
|
+
Magick::OverCompositeOp)
|
32
|
+
end
|
33
|
+
|
34
|
+
yield wallpaper
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'rubystats'
|
2
|
+
|
3
|
+
module Wallbum
|
4
|
+
module ImagePacking
|
5
|
+
class Rectangle
|
6
|
+
|
7
|
+
attr_reader :x
|
8
|
+
attr_reader :y
|
9
|
+
attr_reader :width
|
10
|
+
attr_reader :height
|
11
|
+
attr_reader :children
|
12
|
+
attr_accessor :image
|
13
|
+
|
14
|
+
def initialize(parent, x, y, width, height)
|
15
|
+
@parent = parent
|
16
|
+
@width = width
|
17
|
+
@height = height
|
18
|
+
@x = x
|
19
|
+
@y = y
|
20
|
+
@children = []
|
21
|
+
@image = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def leaf?
|
25
|
+
@children.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def root?
|
29
|
+
@parent.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
def empty?
|
33
|
+
@image.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def area
|
37
|
+
@width * @height
|
38
|
+
end
|
39
|
+
|
40
|
+
def all_children
|
41
|
+
if leaf?
|
42
|
+
self
|
43
|
+
else
|
44
|
+
@children.collect(&:all_children).flatten
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def child_count
|
49
|
+
if leaf?
|
50
|
+
1
|
51
|
+
else
|
52
|
+
@children.map(&:child_count).reduce(:+)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def largest_child
|
57
|
+
if leaf?
|
58
|
+
self
|
59
|
+
else
|
60
|
+
@children.map(&:largest_child).sort_by { |rect| rect.area }.last
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def empty_child
|
65
|
+
if leaf?
|
66
|
+
if empty?
|
67
|
+
self
|
68
|
+
else
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
else
|
72
|
+
@children.map(&:empty_child).compact.first
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def split
|
77
|
+
if @width > @height
|
78
|
+
split_horz
|
79
|
+
else
|
80
|
+
split_vert
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def split_horz
|
87
|
+
half = (@width / 2)
|
88
|
+
cut = (half*multiplier).ceil
|
89
|
+
@children << Rectangle.new(self, @x, @y, cut, @height)
|
90
|
+
@children << Rectangle.new(self, @x + cut, @y, @width - cut, @height)
|
91
|
+
end
|
92
|
+
|
93
|
+
def split_vert
|
94
|
+
half = (@width / 2)
|
95
|
+
cut = (half * multiplier).ceil
|
96
|
+
@children << Rectangle.new(self, @x, @y, @width, cut)
|
97
|
+
@children << Rectangle.new(self, @x, @y + cut, @width, @height - cut)
|
98
|
+
end
|
99
|
+
|
100
|
+
def multiplier
|
101
|
+
pct = Rubystats::NormalDistribution.new(1.0, 0.2).rng
|
102
|
+
if pct < 0.2
|
103
|
+
pct = 0.2
|
104
|
+
elsif pct > 1.8
|
105
|
+
pct = 1.8
|
106
|
+
end
|
107
|
+
pct
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/wallbum.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'wallbum'
|
3
|
+
s.version = '1.0.0'
|
4
|
+
s.license = 'MIT'
|
5
|
+
s.summary = 'Create a wallpaper from discogs album art'
|
6
|
+
s.authors = ['John DeSilva']
|
7
|
+
s.email = ['desilvjo@umich.edu']
|
8
|
+
s.files = `git ls-files`.split("\n")
|
9
|
+
s.homepage = 'https://github.com/Aesthetikx/wallbum'
|
10
|
+
s.bindir = 'bin'
|
11
|
+
|
12
|
+
s.executables << 'wallbum'
|
13
|
+
|
14
|
+
s.add_runtime_dependency 'discogs-wrapper'
|
15
|
+
s.add_runtime_dependency 'rmagick'
|
16
|
+
s.add_runtime_dependency 'rubystats'
|
17
|
+
s.add_runtime_dependency 'slop'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wallbum
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John DeSilva
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: discogs-wrapper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rmagick
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubystats
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: slop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- desilvjo@umich.edu
|
72
|
+
executables:
|
73
|
+
- wallbum
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- bin/wallbum
|
82
|
+
- lib/wallbum.rb
|
83
|
+
- lib/wallbum/discogs_helper.rb
|
84
|
+
- lib/wallbum/image.rb
|
85
|
+
- lib/wallbum/image_packer.rb
|
86
|
+
- lib/wallbum/rectangle.rb
|
87
|
+
- wallbum.gemspec
|
88
|
+
homepage: https://github.com/Aesthetikx/wallbum
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Create a wallpaper from discogs album art
|
112
|
+
test_files: []
|
113
|
+
has_rdoc:
|