pHash 1.1.5 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +9 -9
- data/README.markdown +1 -1
- data/lib/phash.rb +4 -0
- data/lib/phash/all.rb +4 -3
- data/lib/phash/audio.rb +5 -0
- data/lib/phash/image.rb +5 -0
- data/lib/phash/text.rb +8 -0
- data/lib/phash/video.rb +5 -0
- data/pHash.gemspec +8 -3
- data/spec/phash_spec.rb +21 -34
- metadata +9 -24
- data/spec/spec_helper.rb +0 -14
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWZmNjAyM2VhNWJlZDZmMWEyYTVjZmJlNzYzZTkwNDMyNzFmOGNmNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
MWI5MWY0YWViNDM5MjM2ODYzMDU1MGNlZjBmNTE2YTY1MjE1MjI2MA==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzliZDhmNzk2NDhiZjQzNDBkOTZhMWNlYzdmMTk1ODViYWRiYjZjNDc5MTcy
|
10
|
+
NGQ5OGNiNDkxMjEyNGYyYmUxZjJkNDg5MjFiM2ZlZTkxNmYxOWUwMjc4M2Nk
|
11
|
+
MTYwNGZiYjM2ODBkNDY3ZTA5NWI0ZmMwNDA0NTczYjRkZTVjZDM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmY4ZGU1OWUyZDUzN2RhNGEwODU5YzhkYjA1ZDAyYjIyOTkxMmVkYzU1NjU3
|
14
|
+
YzJiNTk3Y2I0ZjZlODk0YzY5Y2I5YTE5NDAzOWJmMWE4ZTdjNzE2MWEwNGIy
|
15
|
+
MWY2ZjMyN2JlY2EzNTY4YWU3MDEwNThiZjFiNzkwZTcyOTQ0M2I=
|
data/README.markdown
CHANGED
data/lib/phash.rb
CHANGED
data/lib/phash/all.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'phash/audio'
|
2
|
+
require 'phash/image'
|
3
|
+
require 'phash/text'
|
4
|
+
require 'phash/video'
|
data/lib/phash/audio.rb
CHANGED
@@ -111,6 +111,11 @@ module Phash
|
|
111
111
|
|
112
112
|
# Class to store audio hash and compare to other
|
113
113
|
class AudioHash < HashData
|
114
|
+
private
|
115
|
+
|
116
|
+
def to_s
|
117
|
+
data.read_array_of_type(:uint32, :read_uint32, length).map{ |n| format('%08x', n) }.join(' ')
|
118
|
+
end
|
114
119
|
end
|
115
120
|
|
116
121
|
# Class to store audio file hash and compare to other
|
data/lib/phash/image.rb
CHANGED
data/lib/phash/text.rb
CHANGED
@@ -83,6 +83,14 @@ module Phash
|
|
83
83
|
|
84
84
|
# Class to store text hash and compare to other
|
85
85
|
class TextHash < HashData
|
86
|
+
private
|
87
|
+
|
88
|
+
def to_s
|
89
|
+
length.times.map do |i|
|
90
|
+
p = TxtHashPoint.new(data + TxtHashPoint.size * i)
|
91
|
+
format('%016x(%i)', p[:hash], p[:index])
|
92
|
+
end.join(' ')
|
93
|
+
end
|
86
94
|
end
|
87
95
|
|
88
96
|
# Class to store text file hash and compare to other
|
data/lib/phash/video.rb
CHANGED
@@ -39,6 +39,11 @@ module Phash
|
|
39
39
|
|
40
40
|
# Class to store video hash and compare to other
|
41
41
|
class VideoHash < HashData
|
42
|
+
private
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
data.read_array_of_type(:uint64, :read_uint64, length).map{ |n| format('%016x', n) }.join(' ')
|
46
|
+
end
|
42
47
|
end
|
43
48
|
|
44
49
|
# Class to store video file hash and compare to other
|
data/pHash.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'pHash'
|
5
|
-
s.version = '1.
|
5
|
+
s.version = '1.2.0'
|
6
6
|
s.summary = %q{Use pHash with ruby}
|
7
7
|
s.homepage = "http://github.com/toy/#{s.name}"
|
8
8
|
s.authors = ['Ivan Kuchin']
|
@@ -17,6 +17,11 @@ Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.add_dependency 'ffi', '~> 1.0'
|
19
19
|
|
20
|
-
s.add_development_dependency '
|
21
|
-
|
20
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
21
|
+
|
22
|
+
if Gem::Platform.local.os == 'darwin'
|
23
|
+
s.post_install_message = "pHash library can be installed using macports or brew:
|
24
|
+
\tport install pHash
|
25
|
+
\tbrew install --without-video-hash homebrew/boneyard/phash"
|
26
|
+
end
|
22
27
|
end
|
data/spec/phash_spec.rb
CHANGED
@@ -1,43 +1,30 @@
|
|
1
|
-
require
|
1
|
+
require 'phash'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
{
|
4
|
+
Phash::Audio => '*.mp3',
|
5
|
+
Phash::Image => '**/*.{jpg,png}',
|
6
|
+
Phash::Text => '*.txt',
|
7
|
+
Phash::Video => '*.mp4',
|
8
|
+
}.each do |klass, glob|
|
9
|
+
describe klass do
|
10
|
+
filenames = Dir.glob(File.join(File.dirname(__FILE__), 'data', glob))
|
5
11
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
klass.for_paths(filenames).combination(2) do |a, b|
|
13
|
+
similar = a.path.split('-')[0] == b.path.split('-')[0]
|
14
|
+
|
15
|
+
if similar
|
16
|
+
it "finds #{a.path} and #{b.path} similar" do
|
17
|
+
expect(a % b).to be > 0.8
|
18
|
+
end
|
19
|
+
else
|
20
|
+
it "finds #{a.path} and #{b.path} not similar" do
|
21
|
+
expect(a % b).to be <= 0.5
|
13
22
|
end
|
14
23
|
end
|
15
|
-
end
|
16
24
|
|
17
|
-
|
18
|
-
|
19
|
-
(a % b).should == (b % a)
|
25
|
+
it 'returns same result when switching arguments' do
|
26
|
+
expect(a % b).to eq(b % a)
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
23
|
-
|
24
|
-
describe :Audio do
|
25
|
-
let(:collection){ Phash::Audio.for_paths filenames('*.mp3') }
|
26
|
-
include_examples :similarity
|
27
|
-
end
|
28
|
-
|
29
|
-
describe :Image do
|
30
|
-
let(:collection){ Phash::Image.for_paths filenames('**/*.{jpg,png}') }
|
31
|
-
include_examples :similarity
|
32
|
-
end
|
33
|
-
|
34
|
-
describe :Text do
|
35
|
-
let(:collection){ Phash::Text.for_paths filenames('*.txt') }
|
36
|
-
include_examples :similarity
|
37
|
-
end
|
38
|
-
|
39
|
-
# describe :Video do
|
40
|
-
# let(:collection){ Phash::Video.for_paths filenames('*.mp4') }
|
41
|
-
# include_examples :similarity
|
42
|
-
# end
|
43
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pHash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kuchin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -24,34 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ! '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ! '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- -
|
31
|
+
- - ~>
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
33
|
+
version: '3.0'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- -
|
38
|
+
- - ~>
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
40
|
+
version: '3.0'
|
55
41
|
description:
|
56
42
|
email:
|
57
43
|
executables: []
|
@@ -110,12 +96,12 @@ files:
|
|
110
96
|
- spec/data/vader-m.mp3
|
111
97
|
- spec/data/vader-o.mp3
|
112
98
|
- spec/phash_spec.rb
|
113
|
-
- spec/spec_helper.rb
|
114
99
|
homepage: http://github.com/toy/pHash
|
115
100
|
licenses:
|
116
101
|
- GPLv3
|
117
102
|
metadata: {}
|
118
|
-
post_install_message:
|
103
|
+
post_install_message: ! "pHash library can be installed using macports or brew:\n\tport
|
104
|
+
install pHash\n\tbrew install --without-video-hash homebrew/boneyard/phash"
|
119
105
|
rdoc_options: []
|
120
106
|
require_paths:
|
121
107
|
- lib
|
@@ -131,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
117
|
version: '0'
|
132
118
|
requirements: []
|
133
119
|
rubyforge_project: pHash
|
134
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.6.4
|
135
121
|
signing_key:
|
136
122
|
specification_version: 4
|
137
123
|
summary: Use pHash with ruby
|
@@ -177,5 +163,4 @@ test_files:
|
|
177
163
|
- spec/data/vader-m.mp3
|
178
164
|
- spec/data/vader-o.mp3
|
179
165
|
- spec/phash_spec.rb
|
180
|
-
- spec/spec_helper.rb
|
181
166
|
has_rdoc:
|
data/spec/spec_helper.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
-
require 'rspec'
|
3
|
-
require 'phash'
|
4
|
-
|
5
|
-
module SpecHelpers
|
6
|
-
def filenames(pattern)
|
7
|
-
data_dir = File.join File.dirname(__FILE__), 'data'
|
8
|
-
Dir.glob(File.join data_dir, pattern)
|
9
|
-
end
|
10
|
-
|
11
|
-
def main_name(path)
|
12
|
-
File.basename(path).split('-', 2).first
|
13
|
-
end
|
14
|
-
end
|