nico_util 0.0.5 → 0.0.6
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/.gitignore +59 -5
- data/lib/nico_util/illust.rb +36 -2
- data/lib/nico_util/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 61e94b87e69a4fbd87254449063114d3d400fd71
|
|
4
|
+
data.tar.gz: 140cb48edac18e3a09a1c5fb17691046051b9725
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 18f046fa1b2807cd0d74498177fe4e00eade8d8f1f8a44af90a81f05db5ca37cba864312173cca850cc6e0b0e35cc245622730722e8cbdccbb72596579ddfa6c
|
|
7
|
+
data.tar.gz: cd1d7079a051c8aa2d87698dfa4c03f2cf496cbae099489332049a852d498621f9e6c8c3573b408a43ea9d9f0ab3523436246c496bbccea9248dc647f0185bfd
|
data/.gitignore
CHANGED
|
@@ -1,9 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
### https://raw.github.com/github/gitignore/98a0d1176bb57de53e73d78bdf7c5d8b785202cc/Global/OSX.gitignore
|
|
2
|
+
|
|
3
|
+
.DS_Store
|
|
4
|
+
.AppleDouble
|
|
5
|
+
.LSOverride
|
|
6
|
+
|
|
7
|
+
# Icon must end with two \r
|
|
8
|
+
Icon
|
|
9
|
+
|
|
10
|
+
# Thumbnails
|
|
11
|
+
._*
|
|
12
|
+
|
|
13
|
+
# Files that might appear on external disk
|
|
14
|
+
.Spotlight-V100
|
|
15
|
+
.Trashes
|
|
16
|
+
|
|
17
|
+
# Directories potentially created on remote AFP share
|
|
18
|
+
.AppleDB
|
|
19
|
+
.AppleDesktop
|
|
20
|
+
Network Trash Folder
|
|
21
|
+
Temporary Items
|
|
22
|
+
.apdisk
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### https://raw.github.com/github/gitignore/98a0d1176bb57de53e73d78bdf7c5d8b785202cc/ruby.gitignore
|
|
26
|
+
|
|
27
|
+
*.gem
|
|
28
|
+
*.rbc
|
|
29
|
+
/.config
|
|
5
30
|
/coverage/
|
|
6
|
-
/
|
|
31
|
+
/InstalledFiles
|
|
7
32
|
/pkg/
|
|
8
33
|
/spec/reports/
|
|
34
|
+
/test/tmp/
|
|
35
|
+
/test/version_tmp/
|
|
9
36
|
/tmp/
|
|
37
|
+
/vendor/
|
|
38
|
+
|
|
39
|
+
## Specific to RubyMotion:
|
|
40
|
+
.dat*
|
|
41
|
+
.repl_history
|
|
42
|
+
build/
|
|
43
|
+
|
|
44
|
+
## Documentation cache and generated files:
|
|
45
|
+
/.yardoc/
|
|
46
|
+
/_yardoc/
|
|
47
|
+
/doc/
|
|
48
|
+
/rdoc/
|
|
49
|
+
|
|
50
|
+
## Environment normalisation:
|
|
51
|
+
/.bundle/
|
|
52
|
+
/lib/bundler/man/
|
|
53
|
+
|
|
54
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
55
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
56
|
+
Gemfile.lock
|
|
57
|
+
.ruby-version
|
|
58
|
+
.ruby-gemset
|
|
59
|
+
|
|
60
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
61
|
+
.rvmrc
|
|
62
|
+
|
|
63
|
+
|
data/lib/nico_util/illust.rb
CHANGED
|
@@ -8,6 +8,8 @@ module NicoUtil
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
class Illust
|
|
11
|
+
class InvalidImageError < StandardError; end
|
|
12
|
+
|
|
11
13
|
def initialize owner, illust_id
|
|
12
14
|
@owner = owner
|
|
13
15
|
if illust_id[0..1] == 'im'
|
|
@@ -77,8 +79,40 @@ module NicoUtil
|
|
|
77
79
|
end
|
|
78
80
|
|
|
79
81
|
def save filename
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
data = download
|
|
83
|
+
check = check_image data
|
|
84
|
+
if check[1] == :damaged
|
|
85
|
+
raise InvalidImageError, "Downloaded image was broken. The filetype was #{check[0]}."
|
|
86
|
+
elsif check[0] == :unknown
|
|
87
|
+
raise InvalidImageError, "The filetype of downloaded image was unknown."
|
|
88
|
+
end
|
|
89
|
+
filename = Pathname(filename).sub_ext('.'+check[0].to_s).to_s
|
|
90
|
+
File.binwrite(filename, data)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
private
|
|
94
|
+
|
|
95
|
+
def check_image data
|
|
96
|
+
result = [ :unknown, :clean ]
|
|
97
|
+
begin
|
|
98
|
+
header = data[0, 8]
|
|
99
|
+
footer = data[data.length-12, 12]
|
|
100
|
+
rescue
|
|
101
|
+
result[1] = :damaged
|
|
102
|
+
return result
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
if header[0,2].unpack("H*") == [ "ffd8" ]
|
|
106
|
+
result[0] = :jpg
|
|
107
|
+
result[1] = :damaged unless footer[-2,2].unpack("H*") == [ "ffd9" ]
|
|
108
|
+
elsif header[0,3].unpack("A*") == [ "GIF" ]
|
|
109
|
+
result[0] = :gif
|
|
110
|
+
result[1] = :damaged unless footer[-1,1].unpack("H*") == [ "3b" ]
|
|
111
|
+
elsif header[0,8].unpack("H*") == [ "89504e470d0a1a0a" ]
|
|
112
|
+
result[0] = :png
|
|
113
|
+
result[1] = :damaged unless footer[-12,12].unpack("H*") == [ "0000000049454e44ae426082" ]
|
|
114
|
+
end
|
|
115
|
+
result
|
|
82
116
|
end
|
|
83
117
|
end
|
|
84
118
|
end
|
data/lib/nico_util/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nico_util
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tatsuya Tanaka (tattn)
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-11-
|
|
11
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|