album_generator 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/album_generator.gemspec +23 -0
- data/bin/album_generator +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/album_generator.rb +11 -0
- data/lib/album_generator/cli.rb +18 -0
- data/lib/album_generator/generator.rb +89 -0
- data/lib/album_generator/version.rb +3 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 658aace5edefb70a6c2debb0ee902506921aa968e43eab7dfdf7e6778cf703b2
|
4
|
+
data.tar.gz: 7aa9ce379880c82e3bb6290295d3ef95a31f7395212edf8a897a6d7684691987
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65f8e07efe4467a5667d85ab89baad2ac440248c9affdb5ac8953265d9c25b6f781a38007f3abe6eb3698b9783a5a11b751c570dd54abfcc0472afa08d92bbf6
|
7
|
+
data.tar.gz: ac135009dd87427d3c291d1c8d9a34ff4310c94171e2db1807580e9cb058e9c1b84dd942785b3082060d7a1eaba52afddc851ffc54b909c1e738697019db6c9e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Andrew Hoglund
|
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
@@ -0,0 +1,39 @@
|
|
1
|
+
# AlbumGenerator
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'album_generator'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install album_generator
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```
|
22
|
+
$ album_generator generate
|
23
|
+
```
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/album_generator.
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'album_generator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "album_generator"
|
8
|
+
spec.version = AlbumGenerator::VERSION
|
9
|
+
spec.authors = ["Andrew Hoglund"]
|
10
|
+
spec.email = ["andrew@andrewhoglund.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generate random album title, artist, and artwork.}
|
13
|
+
spec.description = %q{The logic for this gem is based on the rules from: http://www.noiseaddicts.com/2009/03/random-band-name-cover-album/}
|
14
|
+
spec.homepage = "http://github.com/andrewhoglund/album_generator"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.executables = %w{album_generator}
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
end
|
data/bin/album_generator
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "album_generator"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "album_generator"
|
3
|
+
require "album_generator/generator"
|
4
|
+
|
5
|
+
class AlbumGenerator::CLI < Thor
|
6
|
+
desc "generate", "Generate a new album"
|
7
|
+
def generate(song_count = 5)
|
8
|
+
@generated = Generator.generate(song_count)
|
9
|
+
|
10
|
+
puts "Album Title: #{@generated.album_title}"
|
11
|
+
puts "Artist Name: #{@generated.artist_name}"
|
12
|
+
puts "Artwork File: #{@generated.artwork_file}"
|
13
|
+
puts "Songs:"
|
14
|
+
@generated.song_names.each_with_index do |song,i|
|
15
|
+
puts "#{i}: #{song}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'mini_magick'
|
4
|
+
|
5
|
+
class Generator
|
6
|
+
class GeneratorException < StandardError; end
|
7
|
+
|
8
|
+
def self.generate(song_count = 5)
|
9
|
+
new(song_count).tap(&:generate)
|
10
|
+
end
|
11
|
+
|
12
|
+
@@title_retry_limit = 10
|
13
|
+
@@name_retry_limit = 10
|
14
|
+
@@artwork_retry_limit = 10
|
15
|
+
|
16
|
+
def initialize(song_count)
|
17
|
+
@title_retry = 0
|
18
|
+
@name_retry = 0
|
19
|
+
@artwork_retry = 0
|
20
|
+
@song_retry = 0
|
21
|
+
@song_count = song_count
|
22
|
+
@song_names = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def generate
|
26
|
+
get_album_title
|
27
|
+
get_artist_name
|
28
|
+
get_album_artwork
|
29
|
+
get_song_names
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :album_title, :artist_name, :artwork_file, :song_names
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def random_quote
|
37
|
+
html = fetch_url("http://www.quotationspage.com/random.php3")
|
38
|
+
q = html.css(".quote").last.text.split("\s")
|
39
|
+
q[(q.length - 5)..-1].map(&:capitalize).join(" ")
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_album_title
|
43
|
+
@album_title = random_quote
|
44
|
+
rescue => e
|
45
|
+
handle_exception(e, @title_retry += 1, @@title_retry_limit, :get_album_title)
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_song_names
|
49
|
+
(1..@song_count).each {|i| @song_names << random_quote }
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_artist_name
|
53
|
+
html = fetch_url("https://en.wikipedia.org/wiki/Special:Random")
|
54
|
+
|
55
|
+
@artist_name = html.css("#firstHeading").last.text
|
56
|
+
rescue => e
|
57
|
+
handle_exception(e, @name_retry += 1, @@name_retry_limit, :get_artist_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_album_artwork
|
61
|
+
html = fetch_url("https://www.flickr.com/explore/interesting/7days")
|
62
|
+
user_url = "https://www.flickr.com" + html.css(".Photo")[2].children.xpath("a").last.values[1] + "sizes/o"
|
63
|
+
html2 = fetch_url(user_url)
|
64
|
+
artwork_url = html2.css("#allsizes-photo").last.children.css("img").attribute("src").value
|
65
|
+
image = MiniMagick::Image.open(artwork_url)
|
66
|
+
image.combine_options do |b|
|
67
|
+
b.resize "1600x1600!"
|
68
|
+
end
|
69
|
+
@artwork_file = "/tmp/artwork.jpg"
|
70
|
+
image.write(artwork_file)
|
71
|
+
rescue => e
|
72
|
+
handle_exception(e, @artwork_retry += 1, @@artwork_retry_limit, :get_album_artwork)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def fetch_url(url)
|
78
|
+
Nokogiri::HTML(open(url))
|
79
|
+
end
|
80
|
+
|
81
|
+
def handle_exception(error, retry_count, retry_limit, callback)
|
82
|
+
if retry_count > retry_limit
|
83
|
+
raise GeneratorException.new "unable to perform #{callback}: #{error.message}"
|
84
|
+
else
|
85
|
+
send(callback)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: album_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Hoglund
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: 'The logic for this gem is based on the rules from: http://www.noiseaddicts.com/2009/03/random-band-name-cover-album/'
|
56
|
+
email:
|
57
|
+
- andrew@andrewhoglund.com
|
58
|
+
executables:
|
59
|
+
- album_generator
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- album_generator.gemspec
|
71
|
+
- bin/album_generator
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- lib/album_generator.rb
|
75
|
+
- lib/album_generator/cli.rb
|
76
|
+
- lib/album_generator/generator.rb
|
77
|
+
- lib/album_generator/version.rb
|
78
|
+
homepage: http://github.com/andrewhoglund/album_generator
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubygems_version: 3.0.3
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Generate random album title, artist, and artwork.
|
101
|
+
test_files: []
|