directlink 0.0.1.5 → 0.0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/directlink.gemspec +1 -1
- data/lib/directlink.rb +16 -10
- data/test.rb +30 -7
- 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: 2e3122bab4547d8bdb684ff41906edddb54030ea
|
4
|
+
data.tar.gz: 1a14b888b2ce1ee4e5c0f1493cbdfedaca5a49da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2d49ca7a20bfe00eb33128328156f25e8e8703cb2e2ecfad3af876e3e52d8eaa12a64781482acce3767dcc1d114c40462b6f2465b851a4f0f257e971ccbaec3
|
7
|
+
data.tar.gz: 662c63eaf3d635e9a1b4f642b0787f29045a19ca52c309a383e20aa912804de64a4acd47b36f4cf259647293cfd0a49ec5996195da1ce28d2138a0a5c937c441
|
data/directlink.gemspec
CHANGED
data/lib/directlink.rb
CHANGED
@@ -36,17 +36,20 @@ module DirectLink
|
|
36
36
|
case src
|
37
37
|
# Google Plus post image
|
38
38
|
when /\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_-]{11}\/W[n-r][a-zA-Z0-9_-]{8}I\/AAAAAAAA[bA-V][a-zA-Z0-9]{2}\/[a-zA-Z0-9_-]{32}[gwAQ]CJoC\/)w[1-4]\d\d-h(318|353|727)-n(\/[^\/]+)\z/,
|
39
|
-
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-
|
40
|
-
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_-]{11}\/W[a-zA-Z0-9_-]{9}I\/AAAAAAA[a-zA-Z0-9_-]{4}\/[a-zA-Z0-9_-]{33}(?:CJoC|CL0B(?:GAs)?)\/)w530(?:-d)?-h[2-9]\d\d-n(\/[^\/]+)\z/,
|
41
|
-
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_-]{11}\/W[a-zA-Z0-9_-]{9}I\/AAAAAAAA[a-zA-Z0-9]{3}\/[a-zA-Z0-9_-]{32}[gwAQ]CJoC\/)w424-h318-n(\/[^\/]+)\z/,
|
42
|
-
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_-]{11}\/W[a-zA-Z0-9]{9}I\/AAAAAAAA[ABI][a-zA-Z][a-zA-Z0-9]\/[a-zA-Z0-9_-]{32}[gwAQ]CJoC\/)w265-h353-n(\/[^\/]+)\z/,
|
43
|
-
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/W[a-zA-Z]{8}[DMV_]I\/AAAAAAAA[a-zA-Z]{3}\/[a-zA-Z0-9_]{32}[wQ]CJoC\/)w239-h318-n(\/[^\/]+)\z/,
|
44
|
-
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/Wu[a-zA-Z]{7}HI\/AAAAAAAABAI\/[a-zA-Z0-9]{32}QCJoC\/)w398-h318-n(\/[^\/]+)\z/,
|
45
|
-
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9-]{11}\/Wv[a-zA-Z0-9]{7}PI\/AAAAAAAAC60\/[a-zA-Z0-9-]{32}QCJoC\/)w408-h318-n(\/[^\/]+)\z/,
|
39
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_]{11}\/W[a-zA-Z0-9_]{9}I\/AAAAAAAA[a-zA-Z_]{3}\/[a-zA-Z0-9_]{32}[gwQ]CJoC\/)w239-h318-n(\/[^\/]+)\z/,
|
46
40
|
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/Wv[a-zA-Z0-9]{7}_I\/AAAAAAAAA20\/[a-zA-Z0-9]{32}QCJoC\/)w212-h318-n(\/[^\/]+)\z/,
|
41
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/W[a-zA-Z0-9]{9}I\/AAAAAAAAA_A\/[a-zA-Z0-9_]{32}wCJoC\/)w296-h318-n(\/[^\/]+)\z/,
|
42
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/Wu[a-zA-Z]{7}HI\/AAAAAAAABAI\/[a-zA-Z0-9]{32}QCJoC\/)w398-h318-n(\/[^\/]+)\z/,
|
47
43
|
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9-]{11}\/Wv[a-zA-Z_]{7}AI\/AAAAAAAACkQ\/[a-zA-Z0-9]{32}gCJoC\/)w318-h318-n(\/[^\/]+)\z/,
|
48
|
-
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/
|
49
|
-
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/W[a-zA-Z0-9]{9}I\/
|
44
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9-]{11}\/W[a-zA-Z0-9]{9}I\/AAAAAAAAA_A\/[a-zA-Z0-9]{32}QCJoC\/)w318-h318-n(\/[^\/]+)\z/,
|
45
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/W[a-zA-Z0-9-]{9}I\/AAAAAAAAA_A\/[a-zA-Z0-9]{32}wCJoC\/)w301-h318-n(\/[^\/]+)\z/,
|
46
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_-]{11}\/W[a-zA-Z0-9_-]{9}I\/AAAAAAAA[a-zA-Z0-9_]{3}\/[a-zA-Z0-9_-]{32}[gwAQ]CJoC\/)w424-h318-n(\/[^\/]+)\z/,
|
47
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9-]{11}\/Wv[a-zA-Z0-9]{7}PI\/AAAAAAAAC60\/[a-zA-Z0-9-]{32}QCJoC\/)w408-h318-n(\/[^\/]+)\z/,
|
48
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_-]{11}\/W[a-zA-Z0-9_-]{9}I\/AAAAAAA[a-zA-Z0-9_-]{4}\/[a-zA-Z0-9_-]{33}(?:CJoC|CL0B(?:GAs)?)\/)w530(?:-d)?-h[1-9]\d\d-n(\/[^\/]+)\z/,
|
49
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/W[a-zA-Z0-9]{9}I\/AAAAAAAA[a-zA-Z]{3}\/[a-zA-Z0-9-]{32}QCJoC\/)w530-h175-n(\/[^\/]+)\z/,
|
50
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_-]{11}\/W[a-zA-Z0-9_]{9}I\/AAAAAAAA[ABI][a-zA-Z][a-zA-Z0-9]\/[a-zA-Z0-9_-]{32}[gwAQ]CJoC\/)w265-h353-n(\/[^\/]+)\z/,
|
51
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/W[a-zA-Z0-9]{9}I\/AAAAAAAA[A-Z]{3}\/[a-zA-Z0-9_]{32}wCJoC\/)w346-h195-n-k-no(\/[^\/.]+\.gif)\z/,
|
52
|
+
/\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_]{11}\/W[a-zA-Z0-9]{9}I\/AAAAAAAA[A-Z0-9]{3}\/[a-zA-Z0-9_]{32}gCJoC\/)w486-h864-n(\/[^\/]+)\z/
|
50
53
|
"#{$1}s#{width}#{$2}"
|
51
54
|
when /\A(\/\/lh3\.googleusercontent\.com\/proxy\/[a-zA-Z0-9_-]{66,523}=)(?:w(?:464|504|530)-h[2-7]\d\d-[np]|s530-p|s110-p-k)\z/
|
52
55
|
"https:#{$1}s#{width}"
|
@@ -103,8 +106,10 @@ module DirectLink
|
|
103
106
|
if data["error"]
|
104
107
|
raise ErrorAssert.new "unexpected error #{data.inspect} for #{link}"
|
105
108
|
elsif data["images"]
|
109
|
+
raise ErrorNotFound.new link.inspect if data["images"].empty?
|
106
110
|
data["images"]
|
107
111
|
elsif data["type"] && data["type"].start_with?("image/")
|
112
|
+
# TODO check if this branch is possible at all
|
108
113
|
[ data ]
|
109
114
|
# elsif data["comment"]
|
110
115
|
# fi["https://imgur.com/" + data["image_id"]]
|
@@ -168,6 +173,7 @@ module DirectLink
|
|
168
173
|
end.max_by{ |w, h, u| w * h }
|
169
174
|
end
|
170
175
|
|
176
|
+
require "cgi"
|
171
177
|
def self.wiki link
|
172
178
|
raise ErrorBadLink.new link unless %r{\Ahttps?://([a-z]{2}\.wikipedia|commons.wikimedia)\.org/wiki(/[^/]+)*/(?<id>File:.+)} =~ link
|
173
179
|
t = JSON.load json = NetHTTPUtils.request_data( "https://commons.wikimedia.org/w/api.php", form: {
|
@@ -175,7 +181,7 @@ module DirectLink
|
|
175
181
|
action: "query",
|
176
182
|
prop: "imageinfo",
|
177
183
|
iiprop: "url",
|
178
|
-
titles: id,
|
184
|
+
titles: CGI.unescape(id),
|
179
185
|
} )
|
180
186
|
imageinfo = t["query"]["pages"].values.first["imageinfo"]
|
181
187
|
raise ErrorAssert.new "unexpected format of API response about #{link}: #{json}" unless imageinfo
|
data/test.rb
CHANGED
@@ -45,7 +45,7 @@ describe DirectLink do
|
|
45
45
|
1002 https://lh3.googleusercontent.com/-d8FkfLWq-_4/WpQXzEfFgBI/AAAAAAAADww/J32xKSAYUkgIc3pyrZnNmRec6kjdnJBHgCJoC/w239-h318-n/gplus-485739203.jpg
|
46
46
|
".scan(/(\S+) (\S+)/).each do |i, link| # some pre-May-2018 urls dump from a community
|
47
47
|
it "Google Plus community post image ##{i}" do
|
48
|
-
DirectLink.google link
|
48
|
+
assert DirectLink.google link
|
49
49
|
end
|
50
50
|
end
|
51
51
|
%w{
|
@@ -61,9 +61,25 @@ describe DirectLink do
|
|
61
61
|
https://lh3.googleusercontent.com/-NGME5H7fY1o/WtaUJCaDGmI/AAAAAAAAmBQ/jZhatiBmHPEiAAABcY2DoJ6KuzVBvqGxQCJoC/w530-h150-n/%25D0%25A1%25D0%25BD%25D0%25B8%25D0%25BC%25D0%25BE%25D0%25BA%2B%25D1%258D%25D0%25BA%25D1%2580%25D0%25B0%25D0%25BD%25D0%25B0%2B2018-04-18%2B%25D0%25B2%2B3.32.42.png
|
62
62
|
https://lh3.googleusercontent.com/-40QwR_c58sw/WsLyS3a8uhI/AAAAAAAAAas/ojaQoF1-ZFIboOS6c5kLs7bOl_TAOU6oACJoC/w424-h318-n/271091.jpg
|
63
63
|
https://lh3.googleusercontent.com/-XhWuVCyNBjY/WvOtHOyaj_I/AAAAAAAAAKo/gOAn__a75NwYSgaBaEBGeCTAFI9MyjqlwCJoC/w239-h318-n/IMG_20180510_081956.jpg
|
64
|
+
https://lh3.googleusercontent.com/-R19p_rDI8mY/Wwma1oEvD6I/AAAAAAAAEX8/tQc4JOq58REEWlukw2jDCTUjH3ejGZI8gCJoC/w486-h864-n/gplus1392977354.jpg
|
64
65
|
}.each_with_index do |link, i| # March contenstants
|
65
|
-
it "another Google Plus community post image ##{i + 1}" do
|
66
|
-
DirectLink.google link
|
66
|
+
it "another (March) Google Plus community post image ##{i + 1}" do
|
67
|
+
assert DirectLink.google link
|
68
|
+
end
|
69
|
+
end
|
70
|
+
%w{
|
71
|
+
https://lh3.googleusercontent.com/-mFRn677_gic/WwUz3_Www7I/AAAAAAAABio/MNYvB57tBvIl6Bxp0GsKHvg0hSyHyVWhwCJoC/w265-h353-n/IMG_20180522_210620_317.jpg
|
72
|
+
https://lh3.googleusercontent.com/-6iAmBl21QVc/Wu4Khtduz-I/AAAAAAAAA_A/lvpwTuatrtkhL31co1n9xa7kwKEVwc6IwCJoC/w301-h318-n/gplus662578195.jpg
|
73
|
+
https://lh3.googleusercontent.com/-NnKGFBtNG2Q/Wvt9mUDC1QI/AAAAAAAANEw/2uWvIzQmG-Y3CGHuB8-UU114z4Zr8lkLQCJoC/w530-h175-n/PANO_20180516_025747.jpg
|
74
|
+
https://lh3.googleusercontent.com/-Q7WO7uK6_Ew/WwvJcNQ39BI/AAAAAAAABvI/xb1bdwuEZGM2SmbwamwiMmZKFOW44bhPgCJoC/w239-h318-n/DSC03627.JPG
|
75
|
+
https://lh3.googleusercontent.com/-Uxa1I3V7WWI/Wu4Khq0IkaI/AAAAAAAAA_A/Dxs9JYJ6f6sv_7jNWMdNl3eo2jh9nYqDwCJoC/w296-h318-n/gplus-328480287.jpg
|
76
|
+
https://lh3.googleusercontent.com/-xp3mV2iqjyo/Wu4Khr5ZKhI/AAAAAAAAA_A/725HNeKw2hYtuddakPreAkaucQR6HOYGgCJoC/w424-h318-n/20180317_085037.jpg
|
77
|
+
https://lh3.googleusercontent.com/-oyYSEl5GABY/Wu4Khov2uGI/AAAAAAAAA_A/xFVaLt1emxUtOvys7Mw8QZIF2599lNV6ACJoC/w424-h318-n/20180317_085508.jpg
|
78
|
+
https://lh3.googleusercontent.com/-69MIjxFjtXg/Wu4KhkZD9nI/AAAAAAAAA_A/lBHtrho7HBQgkZNztMTdR3o1RSu47OnigCJoC/w239-h318-n/gplus1795981938.jpg
|
79
|
+
https://lh3.googleusercontent.com/-RW-U7dkkT88/Wu4Khs76OSI/AAAAAAAAA_A/2rsXBfNM4Isi3YBNWlgLnPgQpVN72dXiQCJoC/w318-h318-n/gplus-379421668.jpg
|
80
|
+
}.each_with_index do |link, i| # April contenstants
|
81
|
+
it "another (April) Google Plus community post image ##{i + 1}" do
|
82
|
+
assert DirectLink.google link
|
67
83
|
end
|
68
84
|
end
|
69
85
|
%w{
|
@@ -76,14 +92,14 @@ describe DirectLink do
|
|
76
92
|
https://lh3.googleusercontent.com/-5USmSTZHWWI/WMi3q1GdgiI/AAAAAAAAQIA/lu9FTcUL6xMw4wdoW_I148Vm1BtF5mImwCJoC/w346-h195-n-k-no/Good%2BJob.gif
|
77
93
|
}.each_with_index do |link, i| # gpluscomm_105636351696833883213_86400
|
78
94
|
it "already high res image ##{i + 1}" do
|
79
|
-
DirectLink.google link
|
95
|
+
assert DirectLink.google link
|
80
96
|
end
|
81
97
|
end
|
82
98
|
%w{
|
83
99
|
//lh3.googleusercontent.com/proxy/S-Z1P92Dd_u0DjYrz5Tb7j0mbZsGjPVffx9lHPQZCqqCFr6vAigCPOG0fEYKU6d-wIvwYr2WriAfh97KjBr9Bq1RKgyHzHq2fpAotTnJYOLd3x_tF2chsGBVuAewE7qp2QDtCYyomyn3dGjZ6cKUnYIC8w=s110-p-k
|
84
100
|
}.each_with_index do |link, i|
|
85
101
|
it "posted_website_preview_##{i + 1}" do
|
86
|
-
DirectLink.google link
|
102
|
+
assert DirectLink.google link
|
87
103
|
end
|
88
104
|
end
|
89
105
|
%w{
|
@@ -94,7 +110,7 @@ describe DirectLink do
|
|
94
110
|
4 https://lh3.googleusercontent.com/-Rb833O10RB4/AAAAAAAAAAI/AAAAAAAAEJc/DawCLQGnaSA/s45-p-k-rw-no/photo.jpg
|
95
111
|
}.each_slice 2 do |i, link|
|
96
112
|
it "Google Plus userpic #{i}" do
|
97
|
-
DirectLink.google link
|
113
|
+
assert DirectLink.google link
|
98
114
|
end
|
99
115
|
end
|
100
116
|
%w{
|
@@ -105,7 +121,7 @@ describe DirectLink do
|
|
105
121
|
_ https://lh6.googleusercontent.com/-BQEbGrPRFk4/AAAAAAAAAAI/AAAAAAAAAAA/AIcfdXDBweE5VzGGy4zMraO_pqiLuFN3yQ/s46-c-k-no-mo/photo.jpg
|
106
122
|
}.each_slice 2 do |i, link|
|
107
123
|
it "Hangout userpic #{i}" do
|
108
|
-
DirectLink.google link
|
124
|
+
assert DirectLink.google link
|
109
125
|
end
|
110
126
|
end
|
111
127
|
end
|
@@ -123,6 +139,12 @@ describe DirectLink do
|
|
123
139
|
end
|
124
140
|
end
|
125
141
|
|
142
|
+
it "ErrorNotFound" do
|
143
|
+
assert_raises DirectLink::ErrorNotFound do
|
144
|
+
DirectLink.imgur "https://imgur.com/a/wPi63mj"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
126
148
|
valid_imgur_image_url = "https://i.imgur.com/BLCesav.jpg"
|
127
149
|
it 200 do
|
128
150
|
assert_equal [["https://i.imgur.com/BLCesav.jpg", 1000, 1500, "image/jpeg"]],
|
@@ -224,6 +246,7 @@ describe DirectLink do
|
|
224
246
|
["https://en.wikipedia.org/wiki/Prostitution_by_country#/media/File:Prostitution_laws_of_the_world.PNG", "https://upload.wikimedia.org/wikipedia/commons/e/e8/Prostitution_laws_of_the_world.PNG"],
|
225
247
|
["https://en.wikipedia.org/wiki/Third_Party_System#/media/File:United_States_presidential_election_results,_1876-1892.svg", DirectLink::ErrorAssert],
|
226
248
|
["http://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg", "https://upload.wikimedia.org/wikipedia/commons/0/0d/Eduard_Bohlen_anagoria.jpg"],
|
249
|
+
["https://en.wikipedia.org/wiki/Spanish_Civil_War#/media/File:Alfonso_XIIIdeEspa%C3%B1a.jpg", "https://upload.wikimedia.org/wikipedia/commons/f/fb/Alfonso_XIIIdeEspa%C3%B1a.jpg"], # escaped input URI
|
227
250
|
] ],
|
228
251
|
].each do |method, tests|
|
229
252
|
describe method do
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov aka Nakilon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nethttputils
|