directlink 0.0.10.0 → 0.0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/directlink.gemspec +3 -3
- data/lib/directlink.rb +14 -8
- data/unit.test.rb +53 -6
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 30657b1850442ca6f1267344dc356cdd3e0e55e8
|
4
|
+
data.tar.gz: b8dc86a2fb80cadb1583207934840fc28fdb6177
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d11e9b0f07127be8b711495f1496e527bd979c015a0376512e916c5f92fda19fcfd617d67584c768c1c223ebd41cb57c28bbf258b39659cdd12d5db4653f4120
|
7
|
+
data.tar.gz: 8d6beddd649ec2f1316009abe70c9224de3a34d8234443a040d492066b792b79d9f3fe3771b9906949982f1f5d12ff00a4dbebd9468bda2db63941e74e34f663
|
data/directlink.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "directlink"
|
3
|
-
spec.version = "0.0.
|
3
|
+
spec.version = "0.0.11.0"
|
4
4
|
spec.summary = "obtains from any kind of hyperlink a link to an image, its format and resolution"
|
5
5
|
|
6
6
|
spec.author = "Victor Maslov aka Nakilon"
|
@@ -12,9 +12,9 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.required_ruby_version = ">=2.3" # because <<~ heredocs in tests
|
13
13
|
|
14
14
|
spec.add_dependency "fastimage", "~>2.2.0"
|
15
|
-
spec.add_dependency "nokogiri"
|
15
|
+
spec.add_dependency "nokogiri", "<1.11" # 1.11 requires ruby 2.5
|
16
16
|
spec.add_dependency "nethttputils", "~>0.4.1.0"
|
17
|
-
spec.add_dependency "reddit_bot", "~>1.
|
17
|
+
spec.add_dependency "reddit_bot", "~>1.9.0"
|
18
18
|
spec.add_dependency "kramdown"
|
19
19
|
spec.add_dependency "addressable"
|
20
20
|
spec.add_development_dependency "minitest-around"
|
data/lib/directlink.rb
CHANGED
@@ -40,13 +40,15 @@ module DirectLink
|
|
40
40
|
SocketError,
|
41
41
|
Net::OpenTimeout,
|
42
42
|
Errno::ECONNRESET,
|
43
|
+
Errno::ECONNREFUSED,
|
44
|
+
Errno::ETIMEDOUT, # from FastImage
|
43
45
|
NetHTTPUtils::Error,
|
44
46
|
NetHTTPUtils::EOFError_from_rbuf_fill,
|
45
47
|
FastImage::UnknownImageType,
|
46
48
|
FastImage::ImageFetchFailure,
|
47
49
|
DirectLink::ErrorNotFound,
|
48
50
|
DirectLink::ErrorBadLink,
|
49
|
-
] #
|
51
|
+
] # all known exceptions that can be raised while using Directlink but not as its fault
|
50
52
|
|
51
53
|
|
52
54
|
def self.google src, width = 0
|
@@ -78,8 +80,11 @@ module DirectLink
|
|
78
80
|
/\A(https:\/\/lh[356]\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/AAAAAAAAAAI\/AAAAAAAAAAA\/[a-zA-Z0-9_]{34}\/)s(?:46|64)-c(?:-k(?:-no)?)?-mo\/photo\.jpg\z/
|
79
81
|
"#{$1}s#{width}/"
|
80
82
|
# Google Keep
|
81
|
-
when /\A(https:\/\/lh\d\.googleusercontent\.com\/[a-zA-Z0-9_-]{104,106}=s)\d\d\d\d?\
|
83
|
+
when /\A(https:\/\/lh\d\.googleusercontent\.com\/[a-zA-Z0-9_-]{104,106}=s)\d\d\d\d?\z/
|
82
84
|
"#{$1}#{width}"
|
85
|
+
# opensea
|
86
|
+
when /\A(https:\/\/lh3\.googleusercontent\.com\/[a-zA-Z0-9]{78}-nGx_jf_XGqqiVANe_Jr8u2g=)w1400-k\z/
|
87
|
+
"#{$1}s#{width}"
|
83
88
|
# mp4
|
84
89
|
when /\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z]{11}\/W[a-zA-Z0-9]{9}I\/AAAAAAAAODw\/[a-zA-Z0-9]{32}QCJoC\/)w530-h883-n-k-no\/[^\/]+\.mp4\z/
|
85
90
|
"#{$1}s#{width}/"
|
@@ -91,6 +96,7 @@ module DirectLink
|
|
91
96
|
end
|
92
97
|
end
|
93
98
|
|
99
|
+
|
94
100
|
require "json"
|
95
101
|
|
96
102
|
# TODO make the timeout handling respect the way the Directlink method works with timeouts
|
@@ -244,9 +250,9 @@ module DirectLink
|
|
244
250
|
end
|
245
251
|
if data["media_metadata"]
|
246
252
|
return [true, data["media_metadata"].values.map do |media|
|
247
|
-
next if media == {"status"=>"failed"}
|
248
|
-
raise ErrorAssert.new "our knowledge about Reddit API seems to be outdated" unless media["status"] == "valid"
|
249
|
-
[media["m"], *media["s"].values_at("x", "y"), CGI.unescapeHTML(media["s"]["u"])]
|
253
|
+
next if media == {"status"=>"failed"} || media == {"status"=>"unprocessed"}
|
254
|
+
raise ErrorAssert.new "our knowledge about Reddit API seems to be outdated (media == #{media.inspect})" unless media["status"] == "valid"
|
255
|
+
[media["m"], *media["s"].values_at("x", "y"), CGI.unescapeHTML(media["s"][media["m"]=="image/gif" ? "gif" : "u"])]
|
250
256
|
end.compact]
|
251
257
|
end
|
252
258
|
return [true, "#{"https://www.reddit.com" if /\A\/r\/[0-9a-zA-Z_]+\/comments\/[0-9a-z]{5,6}\// =~ data["url"]}#{data["url"]}"] if data["crosspost_parent"]
|
@@ -268,7 +274,7 @@ module DirectLink
|
|
268
274
|
t
|
269
275
|
end ]
|
270
276
|
when %r{\Ahttps://vk\.com/wall(?<id>-?\d+_\d+)\z},
|
271
|
-
%r{\Ahttps://vk\.com/[a-z\.]+\?w=wall(?<id
|
277
|
+
%r{\Ahttps://vk\.com/[a-z\.]+\?w=wall(?<id>-?\d+_\d+)\z}
|
272
278
|
[$1, :wall, :posts, lambda do |t|
|
273
279
|
t.first.fetch("attachments").select do |item|
|
274
280
|
case item.keys
|
@@ -293,7 +299,7 @@ module DirectLink
|
|
293
299
|
photos.fetch("sizes").map do |size|
|
294
300
|
size.values_at("width", "height", "url").tap do |whu|
|
295
301
|
w, h, u = whu
|
296
|
-
whu[0, 2] = FastImage.new(u, raise_on_failure: true).size if [w, h].include? 0
|
302
|
+
whu[0, 2] = FastImage.new(u, raise_on_failure: true).size if [w, h].include? 0 # wtf?
|
297
303
|
end
|
298
304
|
end.max_by{ |w, h, u| w * h }
|
299
305
|
end
|
@@ -347,7 +353,7 @@ def DirectLink link, timeout = nil, proxy = nil, giveup: false, ignore_meta: fal
|
|
347
353
|
max_start_http_retry_delay: timeout,
|
348
354
|
max_read_retry_delay: timeout,
|
349
355
|
} : {})
|
350
|
-
rescue Net::ReadTimeout
|
356
|
+
rescue Net::ReadTimeout, Errno::ETIMEDOUT
|
351
357
|
rescue NetHTTPUtils::Error => e
|
352
358
|
raise unless 418 == e.code
|
353
359
|
else
|
data/unit.test.rb
CHANGED
@@ -4,12 +4,6 @@ require "minitest/mock"
|
|
4
4
|
require "webmock/minitest"
|
5
5
|
require_relative "webmock_patch"
|
6
6
|
|
7
|
-
ENV["IMGUR_CLIENT_ID"] = "001788999ccdddf"
|
8
|
-
ENV["FLICKR_API_KEY"] = "00123333456678889bbbbcccddddddff"
|
9
|
-
ENV["REDDIT_SECRETS"] = "reddit_token.yaml"
|
10
|
-
ENV["VK_ACCESS_TOKEN"] = "0011222222233334455566667777778888888888999999aaaaaaabbbbcddddddddddddddeeeeeeeffffff"
|
11
|
-
ENV["VK_CLIENT_SECRET"] = "0011223445555555555566777777888999999999999aaaaaaabccddddddddeeefffffff"
|
12
|
-
|
13
7
|
require_relative "lib/directlink"
|
14
8
|
DirectLink.silent = true # TODO: remove?
|
15
9
|
DirectLink.timeout = 30 # TODO: tests about this attribute
|
@@ -190,6 +184,7 @@ describe DirectLink do
|
|
190
184
|
https://lh3.googleusercontent.com/-tV86KJvppss/XE2Nb2Z2aAI/AAAAAAAAGu4/94E_abcDE6AaJ59n43wmmd9rFa--OUuSQCJoC/w530-h338-n/IMG_6845%252C.png
|
191
185
|
https://lh3.googleusercontent.com/-cr-2ZSQGMPg/XFWLfetwr7I/AAAAAAAAQQQ/TbwDabcDE6wb4IDDO0SwfArFSZyDG0i0wCJoC/w530-h360-n/DSC07294.JPG
|
192
186
|
https://lh3.googleusercontent.com/-7ey25Wg_cQ4/X-Xy8LJPjMI/AAAAAAAAALE/raXQabcDE6EzEDfAg3TcsOU_xc9z4szcwCLcBGAsYHQ/w1200-h630-p-k-no-nu/1608905381407960-0.png
|
187
|
+
https://lh3.googleusercontent.com/C84udoMpvJmi95AqshlF9acaR11TCsUgO9rGB9gG1w5Wp3WpB7U52ntft4jBHAyDg2guo6zqI4KZim-nGx_jf_XGqqiVANe_Jr8u2g=w1400-k
|
193
188
|
}.each_with_index do |link, i|
|
194
189
|
it "largeimages ##{i + 1}" do
|
195
190
|
assert DirectLink.google link
|
@@ -567,6 +562,43 @@ describe DirectLink do
|
|
567
562
|
nil,
|
568
563
|
"https://v.redd.it/abcde6fb6w721",
|
569
564
|
],
|
565
|
+
["https://www.reddit.com/r/MapPorn/comments/abd123/________aaaabdeeeeeefggghhhiilmmnnoorrrssttuvyyz/",
|
566
|
+
[true, [
|
567
|
+
["image/gif", 500, 375, "https://i.redd.it/00146fghhjkox.gif"],
|
568
|
+
["image/jpg", 1000, 600, "https://preview.redd.it/1369aacghkswy.jpg?width=1000&format=pjpg&auto=webp&s=0122334444557777778889aaabbbbcdddddeeeef"],
|
569
|
+
]],
|
570
|
+
false, "abd123",
|
571
|
+
nil,
|
572
|
+
nil,
|
573
|
+
"https://www.reddit.com/gallery/abd123",
|
574
|
+
{
|
575
|
+
"00146fghhjkox"=>{
|
576
|
+
"status"=>"valid",
|
577
|
+
"e"=>"AnimatedImage",
|
578
|
+
"m"=>"image/gif",
|
579
|
+
"p"=>[],
|
580
|
+
"s"=>{
|
581
|
+
"y"=>375,
|
582
|
+
"gif"=>"https://i.redd.it/00146fghhjkox.gif",
|
583
|
+
"mp4"=>"",
|
584
|
+
"x"=>500
|
585
|
+
},
|
586
|
+
"id"=>"00146fghhjkox"
|
587
|
+
},
|
588
|
+
"1369aacghkswy"=>{
|
589
|
+
"status"=>"valid",
|
590
|
+
"e"=>"Image",
|
591
|
+
"m"=>"image/jpg",
|
592
|
+
"p"=>[],
|
593
|
+
"s"=>{
|
594
|
+
"y"=>600,
|
595
|
+
"x"=>1000,
|
596
|
+
"u"=>"https://preview.redd.it/1369aacghkswy.jpg?width=1000&format=pjpg&auto=webp&s=0122334444557777778889aaabbbbcdddddeeeef"
|
597
|
+
},
|
598
|
+
"id"=>"1369aacghkswy"
|
599
|
+
}
|
600
|
+
},
|
601
|
+
]
|
570
602
|
].each_with_index do |(input, expectation, is_self, id, media, crosspost_parent, url, media_metadata), i|
|
571
603
|
it "kinds of links" do
|
572
604
|
unless is_self.nil?
|
@@ -636,6 +668,10 @@ describe DirectLink do
|
|
636
668
|
[104, 130, "https://sun9-53.userapi.com/impf/c123456/v123456596/c7714/oImGe4o1ZJI.jpg?size=104x130&quality=96&sign=6ad356e84dcd6bbf2069d9b869a7bdb1&c_uniq_tag=8KN44nSlDjD-FMDiRhHqk6udwiqZfn5n1qqPNFwu_nI&type=album"],
|
637
669
|
[1728, 2160, "https://sun9-53.userapi.com/impf/c123456/v123456596/c7714/oImGe4o1ZJI.jpg?size=1728x2160&quality=96&proxy=1&sign=c7961913ff3efd5064f2ed6c394288f2&c_uniq_tag=CA61KgCRsRXbHm4VJEYYskjpjpSiTHI7UPV4FsCPRmI&type=album"],
|
638
670
|
] ],
|
671
|
+
["https://vk.com/wasserman.anatoliy?w=wall-123457771_353", [864, 1080, "https://userapi.com/impg/13456AABBCDDKKOQSTUWXZbcfghhhjlpqquwyz/z0UtQg2M1s4.jpg"], "wall", [
|
672
|
+
[104, 130, "https://sun9-38.userapi.com/impg/13456AABBCDDKKOQSTUWXZbcfghhhjlpqquwyz/z0UtQg2M1s4.jpg?size=104x130&quality=96&sign=a6012bb508e208c7b2b22c42872215e4&c_uniq_tag=qX06fI2p7bmyvnta_Pt2omQ-l5RBLcrG1DBsLWx1jJA&type=album"],
|
673
|
+
[864, 1080, "https://sun9-38.userapi.com/impg/13456AABBCDDKKOQSTUWXZbcfghhhjlpqquwyz/z0UtQg2M1s4.jpg?size=864x1080&quality=96&sign=8f02c4c6794efd653ed79609bf0850c8&c_uniq_tag=6WP6TY0RTDiG_8NK1lkYUOge22jtjkzGLLwc6IDxjjg&type=album"],
|
674
|
+
] ],
|
639
675
|
].each_with_index do |(input, expectation, mtd, stub), i|
|
640
676
|
it "kinds of links" do
|
641
677
|
stub = {sizes: stub.map{ |w,h,u| {width: w, height: h, url: u} }}
|
@@ -794,6 +830,7 @@ describe DirectLink do
|
|
794
830
|
assert (3 <= tries)
|
795
831
|
assert (tries <= 4)
|
796
832
|
end
|
833
|
+
|
797
834
|
it "Reddit correctly parses out id when no token provided" do
|
798
835
|
stub_request(:head, "https://www.reddit.com/r/gifs/comments/9ftc8f/")
|
799
836
|
m = NetHTTPUtils.method :request_data
|
@@ -936,6 +973,16 @@ describe DirectLink do
|
|
936
973
|
end
|
937
974
|
end
|
938
975
|
end
|
976
|
+
it "HEAD Errno::ETIMEDOUT and GET FastImage::ImageFetchFailure are handled by DirectLink::NORMAL_EXCEPTIONS" do
|
977
|
+
assert_includes DirectLink::NORMAL_EXCEPTIONS, FastImage::ImageFetchFailure
|
978
|
+
assert_raises FastImage::ImageFetchFailure do
|
979
|
+
NetHTTPUtils.stub :request_data, ->_,mtd,*{ fail unless mtd == :HEAD; raise Errno::ETIMEDOUT } do
|
980
|
+
FastImage.stub :new, ->*{ raise FastImage::ImageFetchFailure } do
|
981
|
+
DirectLink "http://www.mesacc.edu/~hello12345/hello/images/photos/aerial/a1234.jpg"
|
982
|
+
end
|
983
|
+
end
|
984
|
+
end
|
985
|
+
end
|
939
986
|
[ # TODO this URLs may be reused from tests that check that this method calls internal method
|
940
987
|
[:google, "//lh3.googleusercontent.com/proxy/578BDGJKLLNPTZceiikqtww_Wi2UTaQH0AC_h2kuURiu0AbwyI2ywOk2XgdAjL7ceg=w530-h354-n"],
|
941
988
|
[:imgur, "http://imgur.com/ABCDEFG"],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: directlink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov aka Nakilon
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fastimage
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.11'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "<"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.11'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: nethttputils
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.9.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.9.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: kramdown
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
description:
|
125
|
+
description:
|
126
126
|
email: nakilon@gmail.com
|
127
127
|
executables:
|
128
128
|
- directlink
|
@@ -139,7 +139,7 @@ licenses:
|
|
139
139
|
- MIT
|
140
140
|
metadata:
|
141
141
|
source_code_uri: https://github.com/nakilon/directlink
|
142
|
-
post_install_message:
|
142
|
+
post_install_message:
|
143
143
|
rdoc_options: []
|
144
144
|
require_paths:
|
145
145
|
- lib
|
@@ -156,8 +156,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
requirements:
|
157
157
|
- 'you may want to create apps and provide API tokens:'
|
158
158
|
- IMGUR_CLIENT_ID, FLICKR_API_KEY, REDDIT_SECRETS
|
159
|
-
|
160
|
-
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.5.2.3
|
161
|
+
signing_key:
|
161
162
|
specification_version: 4
|
162
163
|
summary: obtains from any kind of hyperlink a link to an image, its format and resolution
|
163
164
|
test_files:
|