ficon 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +14 -0
- data/ficon.gemspec +25 -0
- data/lib/ficon/version.rb +3 -0
- data/lib/ficon.rb +76 -0
- data/test/ficon_test.rb +37 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8bb5dcc8886d22d589e2f3d9dfef5ab42bc6adb8
|
4
|
+
data.tar.gz: f72571f07afcfc2f9693dbf94c7030cce7bfb321
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ead6ae9ac27815133dd6a219cdcebb44d527f43dc5451e0739d49fc945613b6beb4648ae9132d2e1807b0808d9cc0645ee299671611775c9019773ae9fe4953a
|
7
|
+
data.tar.gz: bd4875fd569db49ab0cebada2a67e9608ec0536dca7b91e5698add2be1bbb3617ad29baf66febdb9592daa173e53ab221b33861e66f204bcd31bbce57e3e523d
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
**/*.sw?
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Dan Milne
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Ficon
|
2
|
+
|
3
|
+
Find all the icons for a given URL. Favicons, og:image etc and return them in as a list.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ficon'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ficon
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
irb(main)> Ficon.from_uri "https://facebook.com"
|
22
|
+
=> ["https://www.facebook.com/images/fb_icon_325x325.png", "https://fbstatic-a.akamaihd.net/rsrc.php/yV/r/hzMapiNYYpW.ico", "https://www.facebook.com/favicon.ico"]
|
23
|
+
|
24
|
+
## Todo
|
25
|
+
|
26
|
+
When returning a win8-tile, should probably test if there's a colour assocaited with it. EG, twitter returns:
|
27
|
+
|
28
|
+
````html
|
29
|
+
<meta name="msapplication-TileImage" content="//abs.twimg.com/favicons/win8-tile-144.png"/>
|
30
|
+
<meta name="msapplication-TileColor" content="#00aced"/>
|
31
|
+
````
|
32
|
+
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it ( https://github.com/dkam/ficon/fork )
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/ficon.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ficon/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ficon"
|
8
|
+
spec.version = Ficon::VERSION
|
9
|
+
spec.authors = ["Dan Milne"]
|
10
|
+
spec.email = ["d@nmilne.com"]
|
11
|
+
spec.summary = %q{Find website icons}
|
12
|
+
spec.description = %q{Ficon finds icons for websites and optionally, the best icon}
|
13
|
+
spec.homepage = "https://github.com/dkam/ficon"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'nokogiri', "~> 1.6"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake", "~> 10"
|
25
|
+
end
|
data/lib/ficon.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require "ficon/version"
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'uri'
|
6
|
+
require 'net/http'
|
7
|
+
|
8
|
+
module Ficon
|
9
|
+
def self.from_uri(_uri)
|
10
|
+
uri = URI(_uri)
|
11
|
+
doc = nil
|
12
|
+
|
13
|
+
begin
|
14
|
+
data = open(uri)
|
15
|
+
doc = Nokogiri::HTML(data)
|
16
|
+
|
17
|
+
uri = data.base_uri
|
18
|
+
|
19
|
+
rescue OpenURI::HTTPError, SocketError => e
|
20
|
+
puts e.inspect
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
|
24
|
+
results = from_page(doc).collect {|result| normalise(uri, result) }.uniq
|
25
|
+
|
26
|
+
results.concat( from_probes(uri, results) )
|
27
|
+
|
28
|
+
return results
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.from_probes(uri, already_found=[])
|
32
|
+
|
33
|
+
# Check if root domain redirects before probing, striping path - eg http://www.apple.com.au/ -> http://www.apple.com/au/
|
34
|
+
|
35
|
+
probe = Net::HTTP.new(uri.host).request_head("/")
|
36
|
+
if probe.code == "301" || probe.code == "302"
|
37
|
+
uri = URI(probe.header["Location"])
|
38
|
+
uri.path = ""
|
39
|
+
end
|
40
|
+
|
41
|
+
results = []
|
42
|
+
guesses = ["/favicon.ico", "/favicon.png"]
|
43
|
+
|
44
|
+
guesses.each do |guess|
|
45
|
+
uri.path = guess
|
46
|
+
unless already_found.include?( uri.to_s )
|
47
|
+
results << uri.to_s if( Net::HTTP.new(uri.host).request_head(uri.path).header.code == "200")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
return results
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.from_page(page)
|
55
|
+
doc = nil
|
56
|
+
if page.is_a? String
|
57
|
+
doc = Nokogiri::HTML(page)
|
58
|
+
elsif page.is_a? Nokogiri::HTML::Document
|
59
|
+
doc = page
|
60
|
+
else
|
61
|
+
raise ArgumentError
|
62
|
+
end
|
63
|
+
|
64
|
+
doc.xpath("//meta[@property='og:image']|//meta[@name='msapplication-TileImage']|//link[@type='image/ico' or @type='image/vnd.microsoft.icon']|//link[@rel='icon' or @rel='shortcut icon' or @rel='apple-touch-icon-precomposed' or @rel='apple-touch-icon']").collect {|e| e.values.select {|v| v =~ /\.png$|\.jpg$|\.gif$|\.ico$|\.svg$/ }}.flatten
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.normalise(base, candidate)
|
69
|
+
parsed_candidate = URI(candidate);
|
70
|
+
|
71
|
+
parsed_candidate.host = base.host if parsed_candidate.host.nil? # Set relative URLs to absolute
|
72
|
+
parsed_candidate.scheme = base.scheme if parsed_candidate.scheme.nil? # Set the schema if missing
|
73
|
+
|
74
|
+
parsed_candidate.to_s
|
75
|
+
end
|
76
|
+
end
|
data/test/ficon_test.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
PathHere = File.dirname(__FILE__)
|
6
|
+
$LOAD_PATH.unshift File.join(PathHere, "..", "lib")
|
7
|
+
|
8
|
+
require 'ficon'
|
9
|
+
|
10
|
+
Tests = []
|
11
|
+
Tests << { html: %Q{<meta name="msapplication-TileImage" content="https://s.yimg.com/pw/images/favicon-msapplication-tileimage.png"/> }, value: 'https://s.yimg.com/pw/images/favicon-msapplication-tileimage.png' }
|
12
|
+
Tests << { html: %Q{<link rel="shortcut icon" type="image/ico" href="https://s.yimg.com/pw/favicon.ico"> }, value: 'https://s.yimg.com/pw/favicon.ico' }
|
13
|
+
Tests << { html: %Q{<link href="/apple-touch-icon.png" rel="apple-touch-icon-precomposed">}, value: '/apple-touch-icon.png' }
|
14
|
+
Tests << { html: %Q{<link rel="shortcut icon" href="/wp-content/themes/torrentfreakredux/assets/img/icons/favicon.png">}, value: '/wp-content/themes/torrentfreakredux/assets/img/icons/favicon.png' }
|
15
|
+
Tests << { html: %Q{<link rel="apple-touch-icon-precomposed" href="/wp-content/themes/torrentfreakredux/assets/img/icons/57.png">}, value: '/wp-content/themes/torrentfreakredux/assets/img/icons/57.png' }
|
16
|
+
Tests << { html: %Q{<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/wp-content/themes/torrentfreakredux/assets/img/icons/114.png">}, value: '/wp-content/themes/torrentfreakredux/assets/img/icons/114.png' }
|
17
|
+
Tests << { html: %Q{<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/wp-content/themes/torrentfreakredux/assets/img/icons/72.png">}, value: '/wp-content/themes/torrentfreakredux/assets/img/icons/72.png' }
|
18
|
+
Tests << { html: %Q{<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/wp-content/themes/torrentfreakredux/assets/img/icons/144.png">}, value: '/wp-content/themes/torrentfreakredux/assets/img/icons/144.png' }
|
19
|
+
Tests << { html: %Q{<link rel="shortcut icon" href="/favicon.png">}, value: '/favicon.png' }
|
20
|
+
Tests << { html: %Q{<link rel="apple-touch-icon" href="/apple-touch-icon.png">}, value: '/apple-touch-icon.png' }
|
21
|
+
Tests << { html: %Q{<link rel="shortcut icon" href="http://example.com/myicon.ico" />}, value: 'http://example.com/myicon.ico' }
|
22
|
+
Tests << { html: %Q{<link rel="icon" href="http://example.com/image.ico" />}, value: 'http://example.com/image.ico' }
|
23
|
+
Tests << { html: %Q{<link rel="icon" type="image/vnd.microsoft.icon" href="http://example.com/image.ico" />}, value: 'http://example.com/image.ico' }
|
24
|
+
Tests << { html: %Q{<link rel="icon" type="image/png" href="http://example.com/image.png" />}, value: 'http://example.com/image.png' }
|
25
|
+
Tests << { html: %Q{<link rel="icon" type="image/gif" href="http://example.com/image.gif" />}, value: 'http://example.com/image.gif' }
|
26
|
+
Tests << { html: %Q{<link rel="icon" type="image/x-icon" href="http://example.com/image.ico"/>}, value: 'http://example.com/image.ico' }
|
27
|
+
Tests << { html: %Q{<link rel="shortcut icon" href="https://fbstatic-a.akamaihd.net/rsrc.php/yl/r/H3nktOa7ZMg.ico" />}, value: 'https://fbstatic-a.akamaihd.net/rsrc.php/yl/r/H3nktOa7ZMg.ico' }
|
28
|
+
Tests << { html: %Q{<meta property="og:image" content="https://www.facebook.com/images/fb_icon_325x325.png" />}, value: 'https://www.facebook.com/images/fb_icon_325x325.png' }
|
29
|
+
|
30
|
+
|
31
|
+
class FiconTest < Test::Unit::TestCase
|
32
|
+
def test_html_chunks
|
33
|
+
Tests.each do |t|
|
34
|
+
assert Ficon.from_page( t[:html] )[0] == t[:value], "Seaching |#{t[:html]}| expected #{t[:value]}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ficon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Milne
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10'
|
55
|
+
description: Ficon finds icons for websites and optionally, the best icon
|
56
|
+
email:
|
57
|
+
- d@nmilne.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- ficon.gemspec
|
68
|
+
- lib/ficon.rb
|
69
|
+
- lib/ficon/version.rb
|
70
|
+
- test/ficon_test.rb
|
71
|
+
homepage: https://github.com/dkam/ficon
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Find website icons
|
95
|
+
test_files:
|
96
|
+
- test/ficon_test.rb
|