directlink 0.0.8.5 → 0.0.9.1
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/.bashrc +4 -3
- data/.travis.yml +2 -0
- data/bin/directlink +1 -0
- data/directlink.gemspec +2 -2
- data/lib/directlink.rb +48 -24
- data/test.rb +32 -24
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08e29b8a3032310a9443ca5f2bc001c449722aa8'
|
4
|
+
data.tar.gz: 15ee2b72e8ea566e2250a0311afe530a5b9dbd36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b30d00607103ed669f5876b9360b8280e24a6ba66c06117f577e47b497eb1ed76eee953bf0cfc97a2525dffc7c0f1169377cbcb780d7d2c9c1a1d74e9aaec212
|
7
|
+
data.tar.gz: 36a8ecce05a750e1b5aea43929037d67c38f4dcc0df8d022739aa7508a01d51d573e3f39f0ebbca14fca2dbb90d29eb2be6ae74949b77e1e735da7c2be16ac04
|
data/.bashrc
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
source api_tokens_for_travis.sh
|
2
|
-
echo 'to test: ruby -I
|
3
|
-
echo '
|
4
|
-
echo 'or: bundle exec ./bin/directlink --debug ...'
|
2
|
+
echo 'to test: ruby -I./lib test.rb'
|
3
|
+
echo 'or: ruby -I../nethttputils/lib -I./lib ./bin/directlink --debug ...'
|
4
|
+
echo 'or: bundle exec ruby -I./lib ./bin/directlink --debug ...'
|
5
|
+
echo 'or: byebug -I./lib ./bin/directlink ...'
|
data/.travis.yml
CHANGED
data/bin/directlink
CHANGED
@@ -53,6 +53,7 @@ abort "usage: directlink [--debug] [--json] [--github] [--ignore-meta] <link1> <
|
|
53
53
|
}" if [nil, "-h", "--help", "-v", "--version"].include? ARGV.first
|
54
54
|
|
55
55
|
begin
|
56
|
+
# Struct instances have #each and Array() ruins them so we use .is_a?(Array)
|
56
57
|
if json
|
57
58
|
require "json"
|
58
59
|
t = ARGV.map do |link|
|
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.9.1"
|
4
4
|
spec.summary = "converts any kind of image hyperlink to direct link, type of image and its resolution"
|
5
5
|
|
6
6
|
spec.author = "Victor Maslov aka Nakilon"
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.add_dependency "fastimage", "~>2.1.3"
|
13
13
|
spec.add_dependency "nokogiri"
|
14
|
-
spec.add_dependency "nethttputils", "~>0.
|
14
|
+
spec.add_dependency "nethttputils", "~>0.4.0.0"
|
15
15
|
spec.add_dependency "reddit_bot", "~>1.7.0"
|
16
16
|
spec.add_dependency "kramdown"
|
17
17
|
spec.add_dependency "addressable"
|
data/lib/directlink.rb
CHANGED
@@ -47,7 +47,7 @@ module DirectLink
|
|
47
47
|
when /\A(\/\/lh3\.googleusercontent\.com\/cOh2Nsv7EGo0QbuoKxoKZVZO_NcBzufuvPtzirMJfPmAzCzMtnEncfA7zGIDTJfkc1YZFX2MhgKnjA=)w530-h398-p\z/
|
48
48
|
"https:#{$1}s#{width}/"
|
49
49
|
when /\A(\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9-]{11}\/[VW][a-zA-Z0-9_-]{9}I\/AAAAAAA[AC][a-zA-Z0-9]{3}\/[a-zA-Z0-9_-]{32}[gwAQ]CJoC\/)w530-h[23]\d\d-p\/[^\/]+\z/,
|
50
|
-
/\A(?:https?:)?(\/\/[1-4]\.bp\.blogspot\.com\/-[a-zA-Z0-9_-]{11}\/[UVWX][a-zA-Z0-9_-]{9}I\/AAAAAAAA[A-Z][a-zA-Z0-9_-]{2}\/[a-zA-Z0-9_-]{33}C(?:EwYBhgL|(?:Lc|Kg)BGAs)\/)(?:s640|w\d
|
50
|
+
/\A(?:https?:)?(\/\/[1-4]\.bp\.blogspot\.com\/-[a-zA-Z0-9_-]{11}\/[UVWX][a-zA-Z0-9_-]{9}I\/AAAAAAAA[A-Z][a-zA-Z0-9_-]{2}\/[a-zA-Z0-9_-]{33}C(?:EwYBhgL|(?:Lc|Kg)BGAs(?:YHQ)?)\/)(?:s640|w\d{2,4}-h\d\d\d?-p(?:-k-no-nu)?)\/[^\/]+\z/,
|
51
51
|
/\A(?:https?:)?(\/\/[1-4]\.bp\.blogspot\.com\/-[a-zA-Z0-9-]{11}\/[UV][a-zA-Z0-9_-]{9}I\/AAAAAAAA[A-Z][a-zA-Z0-9]{2}\/[a-zA-Z0-9-]{11}\/)w72-h72-p-k-no-nu\/[^\/]+\z/
|
52
52
|
"https:#{$1}s#{width}/"
|
53
53
|
when /\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_]{11}\/AAAAAAAAAAI\/AAAAAAAAAAQ\/[a-zA-Z0-9_]{11}\/)w530-h[13]\d\d-n\/[^\/]+\z/,
|
@@ -137,7 +137,7 @@ module DirectLink
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def self._500px link
|
140
|
-
raise ErrorBadLink.new link unless %r{\Ahttps://500px\.com/photo/(?<id>[^/]+)/[
|
140
|
+
raise ErrorBadLink.new link unless %r{\Ahttps://500px\.com/photo/(?<id>[^/]+)/[-[a-zA-Z0-9]%]+\/?\z} =~ link
|
141
141
|
require "nokogiri"
|
142
142
|
resp = NetHTTPUtils.request_data link
|
143
143
|
f = lambda do |form|
|
@@ -221,6 +221,7 @@ module DirectLink
|
|
221
221
|
raise ErrorAssert.new "our knowledge about Reddit API seems to be outdated" unless json.size == 2
|
222
222
|
json.find{ |_| _["data"]["children"].first["kind"] == "t3" }
|
223
223
|
end
|
224
|
+
# TODO: do we handle linking Imgur albums?
|
224
225
|
data = json["data"]["children"].first["data"]
|
225
226
|
if data["media"]["reddit_video"]
|
226
227
|
return [true, data["media"]["reddit_video"]["fallback_url"]]
|
@@ -228,6 +229,9 @@ module DirectLink
|
|
228
229
|
raise ErrorAssert.new "our knowledge about Reddit API seems to be outdated" unless data["media"].keys.sort == %w{ oembed type } && %w{ youtube.com gfycat.com imgur.com }.include?(data["media"]["type"])
|
229
230
|
return [true, data["media"]["oembed"]["thumbnail_url"]]
|
230
231
|
end if data["media"]
|
232
|
+
return [true, data["media_metadata"].values.map do |media|
|
233
|
+
[media["m"], *media["p"].max_by{ |_| _["x"] * _["y"] }.values_at("x", "y", "u")]
|
234
|
+
end] if data["media_metadata"]
|
231
235
|
return [true, data["url"]] if data["crosspost_parent"]
|
232
236
|
return [true, data["url"]] unless data["is_self"]
|
233
237
|
raise ErrorAssert.new "our knowledge about Reddit API seems to be outdated" if data["url"] != "https://www.reddit.com" + data["permalink"]
|
@@ -236,7 +240,7 @@ module DirectLink
|
|
236
240
|
|
237
241
|
def self.vk link
|
238
242
|
id, mtd, field, f = case link
|
239
|
-
when %r{\Ahttps://vk\.com/id(?<user_id>\d+)\?z=photo(?<id>\k<user_id>_\d+)(%2F(album\k<user_id>_0|photos\k<user_id>))
|
243
|
+
when %r{\Ahttps://vk\.com/id(?<user_id>\d+)\?z=photo(?<id>\k<user_id>_\d+)(%2F(album\k<user_id>_0|photos\k<user_id>))?\z},
|
240
244
|
%r{\Ahttps://vk\.com/[a-z_]+\?z=photo(?<_>)(?<id>(?<user_id>\d+)_\d+)%2Fphotos\k<user_id>\z},
|
241
245
|
%r{\Ahttps://vk\.com/photo(?<_>)(?<id>-?\d+_\d+)(\?all=1)?\z},
|
242
246
|
%r{\Ahttps://vk\.com/feed\?section=likes&z=photo(?<_>)(?<id>-(?<user_id>\d+)_\d+)%2F(liked\d+|album\k<user_id>_0)\z},
|
@@ -244,15 +248,22 @@ module DirectLink
|
|
244
248
|
%r{\Ahttps://vk\.com/wall(?<user_id>-\d+)_\d+\?z=photo(?<id>\k<user_id>_\d+)%2F(wall\k<user_id>_\d+|album\k<user_id>_00%2Frev|\d+)\z}
|
245
249
|
[$2, :photos, :photos, lambda do |t|
|
246
250
|
raise ErrorAssert.new "our knowledge about VK API seems to be outdated" unless 1 == t.size
|
247
|
-
t
|
251
|
+
t
|
248
252
|
end ]
|
249
|
-
when %r{\Ahttps://vk\.com/wall(?<id
|
253
|
+
when %r{\Ahttps://vk\.com/wall(?<id>-?\d+_\d+)\z},
|
254
|
+
%r{\Ahttps://vk\.com/[a-z\.]+\?w=wall(?<id>\d+_\d+)\z}
|
250
255
|
[$1, :wall, :posts, lambda do |t|
|
251
|
-
t.first.fetch("attachments").
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
+
t.first.fetch("attachments").select do |item|
|
257
|
+
case item.keys
|
258
|
+
when %w{ type photo }
|
259
|
+
raise ErrorAssert.new "our knowledge about VK API seems to be outdated" unless item["type"] == "photo"
|
260
|
+
next true
|
261
|
+
when %w{ type audio }
|
262
|
+
raise ErrorAssert.new "our knowledge about VK API seems to be outdated" unless item["type"] == "audio"
|
263
|
+
else
|
264
|
+
raise ErrorAssert.new "our knowledge about VK API seems to be outdated"
|
265
|
+
end
|
266
|
+
end.map{ |i| i.fetch "photo" }
|
256
267
|
end ]
|
257
268
|
else
|
258
269
|
raise ErrorBadLink.new link
|
@@ -261,12 +272,14 @@ module DirectLink
|
|
261
272
|
sleep 0.25 # "error_msg"=>"Too many requests per second"
|
262
273
|
f.call( JSON.load( NetHTTPUtils.request_data "https://api.vk.com/method/#{mtd}.getById",
|
263
274
|
:POST, form: { field => id, :access_token => ENV["VK_ACCESS_TOKEN"], :client_secret => ENV["VK_CLIENT_SECRET"], :v => "5.101" }
|
264
|
-
).fetch("response") ).
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
275
|
+
).fetch("response") ).map do |photos|
|
276
|
+
photos.fetch("sizes").map do |size|
|
277
|
+
size.values_at("width", "height", "url").tap do |whu|
|
278
|
+
w, h, u = whu
|
279
|
+
whu[0, 2] = FastImage.new(u, raise_on_failure: true).size if [w, h].include? 0
|
280
|
+
end
|
281
|
+
end.max_by{ |w, h, u| w * h }
|
282
|
+
end
|
270
283
|
end
|
271
284
|
|
272
285
|
class_variable_set :@@directlink, Struct.new(:url, :width, :height, :type)
|
@@ -369,11 +382,17 @@ def DirectLink link, timeout = nil, giveup: false, ignore_meta: false
|
|
369
382
|
raise DirectLink::ErrorBadLink.new link if giveup # TODO: print original url in such cases if there was a recursion
|
370
383
|
f = ->_{ _.type == :a ? _.attr["href"] : _.children.flat_map(&f) }
|
371
384
|
require "kramdown"
|
372
|
-
return f[Kramdown::Document.new(u).root].
|
385
|
+
return f[Kramdown::Document.new(u).root].flat_map do |sublink|
|
373
386
|
DirectLink URI.join(link, sublink).to_s, timeout, giveup: giveup
|
374
387
|
end
|
375
388
|
end
|
376
|
-
|
389
|
+
if u.is_a? Hash
|
390
|
+
return struct.new *u.values_at(*%w{ fallback_url width height }), "video"
|
391
|
+
elsif u.is_a? Array
|
392
|
+
return u.map do |t, x, y, u|
|
393
|
+
struct.new u, x, y, t
|
394
|
+
end
|
395
|
+
end
|
377
396
|
return DirectLink u
|
378
397
|
fail if link == u
|
379
398
|
rescue DirectLink::ErrorMissingEnvVar
|
@@ -381,8 +400,9 @@ def DirectLink link, timeout = nil, giveup: false, ignore_meta: false
|
|
381
400
|
%w{ redd it } == URI(link).host.split(?.)
|
382
401
|
|
383
402
|
begin
|
384
|
-
w, h, u
|
385
|
-
|
403
|
+
return DirectLink.vk(link).map do |w, h, u|
|
404
|
+
struct.new u, w, h
|
405
|
+
end
|
386
406
|
rescue DirectLink::ErrorMissingEnvVar
|
387
407
|
end if %w{ vk com } == URI(link).host.split(?.)
|
388
408
|
|
@@ -402,7 +422,10 @@ def DirectLink link, timeout = nil, giveup: false, ignore_meta: false
|
|
402
422
|
end
|
403
423
|
html = Nokogiri::HTML NetHTTPUtils.request_data link, header: {"User-Agent" => "Mozilla"}
|
404
424
|
if t = html.at_css("meta[@property='og:image']")
|
405
|
-
|
425
|
+
begin
|
426
|
+
return DirectLink URI.join(link, t[:content]).to_s, nil, giveup: true
|
427
|
+
rescue URI::InvalidURIError
|
428
|
+
end
|
406
429
|
end unless ignore_meta
|
407
430
|
h = {} # TODO: maybe move it outside because of possible img[:src] recursion?...
|
408
431
|
l = lambda do |node, s = []|
|
@@ -416,9 +439,10 @@ def DirectLink link, timeout = nil, giveup: false, ignore_meta: false
|
|
416
439
|
end
|
417
440
|
end
|
418
441
|
end
|
419
|
-
l[html].
|
420
|
-
raise if results.empty?
|
421
|
-
|
442
|
+
l[html].
|
443
|
+
tap{ |results| raise if results.empty? }.
|
444
|
+
group_by(&:first).map{ |k, v| [k.join(?>), v.map(&:last)] }.
|
445
|
+
max_by{ |_, v| v.map{ |i| i.width * i.height }.inject(:+) }.last
|
422
446
|
else
|
423
447
|
# TODO: maybe move this to right before `rescue` line
|
424
448
|
w, h = f.size
|
data/test.rb
CHANGED
@@ -171,6 +171,7 @@ describe DirectLink do
|
|
171
171
|
http://1.bp.blogspot.com/-iSU4orVuR9Y/VFYrwQZ5qYI/AAAAAAAAMnc/WY4VfCaeplw/w72-h72-p-k-no-nu/Wolf%2Bphotography2.jpg
|
172
172
|
http://1.bp.blogspot.com/-vPQSh6RKijU/VEi7r3D-jJI/AAAAAAAAL2Q/bGHmyuoDp5M/w72-h72-p-k-no-nu/Building%2BIn%2BLondon1-4__880.jpeg
|
173
173
|
http://1.bp.blogspot.com/-W4xKJSsVf3M/Uz73jPlctbI/AAAAAAAAGz4/K8Tw6PILMeY/w72-h72-p-k-no-nu/Beautiful+Japanese+places4.jpg
|
174
|
+
https://1.bp.blogspot.com/-__qsdLxNtcQ/XhaOQle-ECI/AAAAAAAABQ4/S_7SGG_K8eQ7VXIU2wyPvTj9OyBfr_1sQCLcBGAsYHQ/w1200-h630-p-k-no-nu/iceland_poppies_orange_flowers_field-wallpaper-3840x2160.jpg
|
174
175
|
https://lh3.googleusercontent.com/-tV86KJvppss/XE2Nb2Z2aAI/AAAAAAAAGu4/94E_AuB4YWAaJ59n43wmmd9rFa--OUuSQCJoC/w530-h338-n/IMG_6845%252C.png
|
175
176
|
https://lh3.googleusercontent.com/-cr-2ZSQGMPg/XFWLfetwr7I/AAAAAAAAQQQ/TbwDk56BBIwb4IDDO0SwfArFSZyDG0i0wCJoC/w530-h360-n/DSC07294.JPG
|
176
177
|
}.each_with_index do |link, i|
|
@@ -222,7 +223,7 @@ describe DirectLink do
|
|
222
223
|
|
223
224
|
# TODO: expand this for every branch in lib
|
224
225
|
%w{
|
225
|
-
https_long_blogspot https://
|
226
|
+
https_long_blogspot https://1.bp.blogspot.com/-__qsdLxNtcQ/XhaOQle-ECI/AAAAAAAABQ4/S_7SGG_K8eQ7VXIU2wyPvTj9OyBfr_1sQCLcBGAsYHQ/w1200-h630-p-k-no-nu/iceland_poppies_orange_flowers_field-wallpaper-3840x2160.jpg https://1.bp.blogspot.com/-__qsdLxNtcQ/XhaOQle-ECI/AAAAAAAABQ4/S_7SGG_K8eQ7VXIU2wyPvTj9OyBfr_1sQCLcBGAsYHQ/s0/
|
226
227
|
http_short_blogspot http://4.bp.blogspot.com/-poH-QXn7YGg/U-3ZTDkeF_I/AAAAAAAAISE/ms2gNIb-v-g/w72-h72-p-k-no-nu/Top-24-Inspired-181.jpg https://4.bp.blogspot.com/-poH-QXn7YGg/U-3ZTDkeF_I/AAAAAAAAISE/ms2gNIb-v-g/s0/
|
227
228
|
just_gplus https://lh3.googleusercontent.com/-NiGph3ObOPg/XE3DgnavXlI/AAAAAAABvgE/pcPPCe88rsU1r941wwP76TVf_o89i74kwCJoC/w530-h353-n/DSCF0753.JPG https://lh3.googleusercontent.com/-NiGph3ObOPg/XE3DgnavXlI/AAAAAAABvgE/pcPPCe88rsU1r941wwP76TVf_o89i74kwCJoC/s0/
|
228
229
|
google_keep https://lh5.googleusercontent.com/fRmAL_04p7oomNHCiV4tH4-agHSDBtLaWi_Tb6bgE5ZSHVu5OjQF3iRn06nNwP3ywZwdFP92zWM-o8yw0cn6m0tDTBARuO6F9e0wYu_1=s685 https://lh5.googleusercontent.com/fRmAL_04p7oomNHCiV4tH4-agHSDBtLaWi_Tb6bgE5ZSHVu5OjQF3iRn06nNwP3ywZwdFP92zWM-o8yw0cn6m0tDTBARuO6F9e0wYu_1=s0
|
@@ -363,6 +364,8 @@ describe DirectLink do
|
|
363
364
|
[
|
364
365
|
[ :_500px, [
|
365
366
|
["https://500px.com/photo/264092015/morning-rider-by-tiger-seo", [1200, 800, "https://drscdn.500px.org/photo/264092015/m%3D900/v2?sig=68a9206477f573d8e2838faa6a929e7267f22dc5f9e98f1771f7a8a63efa2ed7", "jpeg"]],
|
367
|
+
["https://500px.com/photo/1017579834/-poppies-flowers-by-David-Dubnitskiy/", [1819, 2500, "https://drscdn.500px.org/photo/1017579834/m%3D900/v2?sig=022e3e9dd836ffd8c1d31ae26c83735e4e42b4c8733d0c4380d8270aebbca44e", "jpeg"]],
|
368
|
+
["https://500px.com/photo/1017557263/iss%E5%87%8C%E6%97%A5%E5%81%8F%E9%A3%9F-by-%E7%A7%8B%E8%A3%A4Choku-/", [2048, 2048, "https://drscdn.500px.org/photo/1017557263/m%3D2048/v2?sig=1994a09e33794117082e91fa58c40614a2bfd19d3e0dd78e067968d38aca92be", "jpeg"]]
|
366
369
|
] ],
|
367
370
|
[ :flickr, [
|
368
371
|
["https://www.flickr.com/photos/tomas-/17220613278/", DirectLink::ErrorNotFound],
|
@@ -395,16 +398,18 @@ describe DirectLink do
|
|
395
398
|
["https://www.reddit.com/r/hangers/comments/97you5/tara_radovic/", [true, "https://i.imgur.com/rbLqgOu.jpg"]], # "crossport" from Imgur
|
396
399
|
] ],
|
397
400
|
[ :vk, [
|
398
|
-
["https://vk.com/wall-105984091_7806", [960, 1280, "https://sun9-41.userapi.com/c855224/v855224900/a72f1/7OZ8ux9Wcwo.jpg"]],
|
399
|
-
["https://vk.com/
|
400
|
-
["https://vk.com/
|
401
|
-
["https://vk.com/
|
402
|
-
["https://vk.com/
|
403
|
-
["https://vk.com/photo-
|
404
|
-
["https://vk.com/
|
405
|
-
["https://vk.com/
|
406
|
-
["https://vk.com/
|
407
|
-
["https://vk.com/
|
401
|
+
["https://vk.com/wall-105984091_7806", [[960, 1280, "https://sun9-41.userapi.com/c855224/v855224900/a72f1/7OZ8ux9Wcwo.jpg"]]],
|
402
|
+
["https://vk.com/wall298742340_4715", [[1080, 1080, "https://sun9-24.userapi.com/c857136/v857136625/15e38b/CsCqsJD174A.jpg"]]],
|
403
|
+
["https://vk.com/id57030827?z=photo57030827_456241143%2Falbum57030827_0", [[1920, 1440, "https://sun9-66.userapi.com/c845322/v845322944/167836/bP9z41BybhI.jpg"]]],
|
404
|
+
["https://vk.com/id57030827?z=photo57030827_456241143", [[1920, 1440, "https://sun9-66.userapi.com/c845322/v845322944/167836/bP9z41BybhI.jpg"]]],
|
405
|
+
["https://vk.com/wall-185182611_454?z=photo-185182611_457239340%2Fwall-185182611_454", [[1280, 960, "https://sun9-46.userapi.com/c851028/v851028578/1a62f6/VB4SdR1O6Tg.jpg"]]],
|
406
|
+
["https://vk.com/wall-105984091_7946?z=photo-105984091_457243312%2Falbum-105984091_00%2Frev", [[1280, 875, "https://sun9-37.userapi.com/c852020/v852020134/1b6b36/0IsDFb-Hda4.jpg"]]],
|
407
|
+
["https://vk.com/photo533531776_456239427?all=1", [[750, 938, "https://sun9-25.userapi.com/c849416/v849416600/14b949/V01Ch1gYjhc.jpg"]]],
|
408
|
+
["https://vk.com/photo-155488973_456242404", [[1486, 1000, "https://sun9-7.userapi.com/c852132/v852132877/8578e/m6AJWiskiKE.jpg"]]],
|
409
|
+
["https://vk.com/id2272074?z=photo2272074_264578776%2Fphotos2272074", [[604, 484, "https://sun9-10.userapi.com/c10472/u2272074/-7/x_407b2ba2.jpg"]]],
|
410
|
+
["https://vk.com/feed?section=likes&z=photo-117564754_456261460%2Fliked3902406", [[1024, 1335, "https://sun9-72.userapi.com/c854028/v854028353/895b6/izQJresLdf0.jpg"]]],
|
411
|
+
["https://vk.com/likizimy?z=photo-42543351_456239941%2Fwall-42543351_1908", [[1179, 1731, "https://sun9-47.userapi.com/c855036/v855036571/60f7b/ryCPJIMyMkI.jpg"]]],
|
412
|
+
["https://vk.com/e_rod?z=photo298742340_457247118%2Fphotos298742340", [[1728, 2160, "https://sun9-53.userapi.com/c858320/v858320596/c7714/oImGe4o1ZJI.jpg"]]],
|
408
413
|
] ],
|
409
414
|
].each do |method, tests|
|
410
415
|
next if method == :vk && ENV.include?("TRAVIS")
|
@@ -441,7 +446,7 @@ describe DirectLink do
|
|
441
446
|
["https://goo.gl/ySqUb5", "https://i.imgur.com/QpOBvRY.png"],
|
442
447
|
],
|
443
448
|
_500px: [
|
444
|
-
%w{ https://500px.com/photo/112134597/milky-way-by-tom-hall https://
|
449
|
+
%w{ https://500px.com/photo/112134597/milky-way-by-tom-hall https://500px.com/photo/112134597/milky-way-by-tom-hall },
|
445
450
|
],
|
446
451
|
flickr: [
|
447
452
|
"https://www.flickr.com/photos/59880970@N07/15773941043/in/dateposted-public/",
|
@@ -648,7 +653,7 @@ describe DirectLink do
|
|
648
653
|
|
649
654
|
describe "other domains tests" do
|
650
655
|
[
|
651
|
-
["http://www.aeronautica.difesa.it/organizzazione/REPARTI/divolo/PublishingImages/6%C2%B0%20Stormo/2013-decollo%20al%20tramonto%20REX%201280.jpg", ["http://www.aeronautica.difesa.it/organizzazione/REPARTI/divolo/PublishingImages/6%C2%B0%20Stormo/2013-decollo%20al%20tramonto%20REX%201280.jpg", 1280, 853, :jpeg], nil, 1],
|
656
|
+
# ["http://www.aeronautica.difesa.it/organizzazione/REPARTI/divolo/PublishingImages/6%C2%B0%20Stormo/2013-decollo%20al%20tramonto%20REX%201280.jpg", ["http://www.aeronautica.difesa.it/organizzazione/REPARTI/divolo/PublishingImages/6%C2%B0%20Stormo/2013-decollo%20al%20tramonto%20REX%201280.jpg", 1280, 853, :jpeg], nil, 1], # website is dead?
|
652
657
|
# ["http://minus.com/lkP3hgRJd9npi", SocketError, /nodename nor servname provided, or not known|No address associated with hostname/, 0],
|
653
658
|
["http://www.cutehalloweencostumeideas.org/wp-content/uploads/2017/10/Niagara-Falls_04.jpg", SocketError, /nodename nor servname provided, or not known|Name or service not known/, 0],
|
654
659
|
].each_with_index do |(input, expectation, message_string_or_regex, max_redirect_resolving_retry_delay), i|
|
@@ -674,36 +679,39 @@ describe DirectLink do
|
|
674
679
|
describe "giving up" do
|
675
680
|
[
|
676
681
|
["http://example.com", FastImage::UnknownImageType],
|
677
|
-
["https://www.tic.com/index.html", FastImage::UnknownImageType, true],
|
678
|
-
["https://www.tic.com/index.html", 2],
|
682
|
+
# ["https://www.tic.com/index.html", FastImage::UnknownImageType, true], # needs new test or stub
|
683
|
+
# ["https://www.tic.com/index.html", 2], # needs new test or stub
|
679
684
|
["http://imgur.com/HQHBBBD", FastImage::UnknownImageType, true],
|
680
685
|
["http://imgur.com/HQHBBBD", "https://i.imgur.com/HQHBBBD.jpg?fb"], # .at_css("meta[@property='og:image']")
|
681
686
|
["https://www.deviantart.com/nadyasonika/art/Asuka-Langley-Beach-Time-590134861", FastImage::UnknownImageType, true],
|
682
|
-
["https://www.deviantart.com/nadyasonika/art/Asuka-Langley-Beach-Time-590134861", "https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/943f66cb-78ad-40f2-a086-44420b98b431/d9rcmz1-5cbc5670-0193-485b-ac14-755ddb9562f4.jpg/v1/fill/w_1024,h_732,q_75,strp/asuka_langley_beach_time_by_nadyasonika_d9rcmz1-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.
|
687
|
+
["https://www.deviantart.com/nadyasonika/art/Asuka-Langley-Beach-Time-590134861", "https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/943f66cb-78ad-40f2-a086-44420b98b431/d9rcmz1-5cbc5670-0193-485b-ac14-755ddb9562f4.jpg/v1/fill/w_1024,h_732,q_75,strp/asuka_langley_beach_time_by_nadyasonika_d9rcmz1-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3siaGVpZ2h0IjoiPD03MzIiLCJwYXRoIjoiXC9mXC85NDNmNjZjYi03OGFkLTQwZjItYTA4Ni00NDQyMGI5OGI0MzFcL2Q5cmNtejEtNWNiYzU2NzAtMDE5My00ODViLWFjMTQtNzU1ZGRiOTU2MmY0LmpwZyIsIndpZHRoIjoiPD0xMDI0In1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmltYWdlLm9wZXJhdGlvbnMiXX0.L6OhXuQZ_9ovKOdjjuQbvxpD0mG8M_KiqV4ljEDfW3Q"],
|
688
|
+
["https://calgary.skyrisecities.com/news/2019/11/blue-morning-light", "https://cdn.skyrisecities.com/sites/default/files/images/articles/2019/11/39834/39834-132071.jpg"], # og:image without scheme
|
689
|
+
["https://www.reddit.com/r/darksouls3/comments/e59djh/hand_it_over_that_thing_your_wallpaper/", DirectLink::ErrorBadLink, true],
|
690
|
+
["https://www.reddit.com/r/darksouls3/comments/e59djh/hand_it_over_that_thing_your_wallpaper/", 6],
|
683
691
|
].each_with_index do |(input, expectation, giveup), i|
|
684
692
|
it "##{i + 1} (#{URI(input).host}) (giveup=#{!!giveup})" do # to match with minitest `-n` run flag
|
685
|
-
ti = ENV.delete "IMGUR_CLIENT_ID"
|
686
|
-
tr = ENV.delete "REDDIT_SECRETS"
|
693
|
+
ti = ENV.delete "IMGUR_CLIENT_ID" if %w{ imgur com } == URI(input).host.split(?.).last(2)
|
694
|
+
tr = ENV.delete "REDDIT_SECRETS" if %w{ reddit com } == URI(input).host.split(?.).last(2)
|
687
695
|
begin
|
688
696
|
case expectation
|
689
697
|
when Class
|
690
698
|
e = assert_raises expectation, "for #{input} (giveup = #{giveup})" do
|
691
|
-
DirectLink input,
|
699
|
+
DirectLink input, 10, giveup: giveup
|
692
700
|
end
|
693
701
|
assert_equal expectation.to_s, e.class.to_s, "for #{input} (giveup = #{giveup})"
|
694
702
|
when String
|
695
|
-
result = DirectLink input,
|
703
|
+
result = DirectLink input, 10, giveup: giveup
|
696
704
|
assert_equal expectation, result.url, "for #{input} (giveup = #{giveup})"
|
697
705
|
else
|
698
|
-
result = DirectLink input,
|
706
|
+
result = DirectLink input, 10, giveup: giveup
|
699
707
|
result = [result] unless result.is_a? Array # we can't do `Array(<Struct>)` because it splats by elements
|
700
708
|
assert_equal expectation, result.size, ->{
|
701
709
|
"for #{input} (giveup = #{giveup}): #{result.map &:url}"
|
702
710
|
}
|
703
711
|
end
|
704
712
|
ensure
|
705
|
-
ENV["IMGUR_CLIENT_ID"] = ti
|
706
|
-
ENV["REDDIT_SECRETS"] = tr
|
713
|
+
ENV["IMGUR_CLIENT_ID"] = ti if ti
|
714
|
+
ENV["REDDIT_SECRETS"] = tr if tr
|
707
715
|
end
|
708
716
|
end
|
709
717
|
end
|
@@ -816,7 +824,7 @@ describe DirectLink do
|
|
816
824
|
end
|
817
825
|
it "ignores <meta> tag" do
|
818
826
|
string, status = Open3.capture2e "RUBYOPT='-rbundler/setup' ./bin/directlink --json --ignore-meta https://www.kp.ru/daily/26342.7/3222103/"
|
819
|
-
assert_equal [0, 21, "https://s11.stc.all.kpcdn.net/share/i/12/8024261/
|
827
|
+
assert_equal [0, 21, "https://s11.stc.all.kpcdn.net/share/i/12/8024261/inx960x640.jpg"], [status.exitstatus, JSON.load(string).size, JSON.load(string).first.fetch("url")]
|
820
828
|
end
|
821
829
|
|
822
830
|
end
|
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.9.1
|
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:
|
11
|
+
date: 2020-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fastimage
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.4.0.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.4.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: reddit_bot
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|