directlink 0.0.8.4 → 0.0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +46 -29
- data/test.rb +29 -23
- 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: 2fd631d28a9163381634ef669e093e592f930ded
|
4
|
+
data.tar.gz: 0b50f85bbfc1650fd3c600a087088bce1d804c7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f37f81c0cc925df667eddca3ce2bf2c801438712deb22547acd2bc96f314728a377e1efbfc00c35304ed308b9bbf2f481a07a65edaf0626baf2e37b51044c84
|
7
|
+
data.tar.gz: fddbc5f906b2b9b49434dd7d0e2bb9fbffd5119defd5494b5b849ff8eb7ff201275b2e2b271db6f80506641bb3dddbce046f482db387671753b4fc53acc9f23f
|
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]
|
|
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.0"
|
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
@@ -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-Z]]+\/?\z} =~ link
|
141
141
|
require "nokogiri"
|
142
142
|
resp = NetHTTPUtils.request_data link
|
143
143
|
f = lambda do |form|
|
@@ -236,7 +236,7 @@ module DirectLink
|
|
236
236
|
|
237
237
|
def self.vk link
|
238
238
|
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>))
|
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>))?\z},
|
240
240
|
%r{\Ahttps://vk\.com/[a-z_]+\?z=photo(?<_>)(?<id>(?<user_id>\d+)_\d+)%2Fphotos\k<user_id>\z},
|
241
241
|
%r{\Ahttps://vk\.com/photo(?<_>)(?<id>-?\d+_\d+)(\?all=1)?\z},
|
242
242
|
%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 +244,22 @@ module DirectLink
|
|
244
244
|
%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
245
|
[$2, :photos, :photos, lambda do |t|
|
246
246
|
raise ErrorAssert.new "our knowledge about VK API seems to be outdated" unless 1 == t.size
|
247
|
-
t
|
247
|
+
t
|
248
248
|
end ]
|
249
|
-
when %r{\Ahttps://vk\.com/wall(?<id
|
249
|
+
when %r{\Ahttps://vk\.com/wall(?<id>-?\d+_\d+)\z},
|
250
|
+
%r{\Ahttps://vk\.com/[a-z\.]+\?w=wall(?<id>\d+_\d+)\z}
|
250
251
|
[$1, :wall, :posts, lambda do |t|
|
251
|
-
t.first.fetch("attachments").
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
252
|
+
t.first.fetch("attachments").select do |item|
|
253
|
+
case item.keys
|
254
|
+
when %w{ type photo }
|
255
|
+
raise ErrorAssert.new "our knowledge about VK API seems to be outdated" unless item["type"] == "photo"
|
256
|
+
next true
|
257
|
+
when %w{ type audio }
|
258
|
+
raise ErrorAssert.new "our knowledge about VK API seems to be outdated" unless item["type"] == "audio"
|
259
|
+
else
|
260
|
+
raise ErrorAssert.new "our knowledge about VK API seems to be outdated"
|
261
|
+
end
|
262
|
+
end.map{ |i| i.fetch "photo" }
|
256
263
|
end ]
|
257
264
|
else
|
258
265
|
raise ErrorBadLink.new link
|
@@ -261,12 +268,14 @@ module DirectLink
|
|
261
268
|
sleep 0.25 # "error_msg"=>"Too many requests per second"
|
262
269
|
f.call( JSON.load( NetHTTPUtils.request_data "https://api.vk.com/method/#{mtd}.getById",
|
263
270
|
: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
|
-
|
271
|
+
).fetch("response") ).map do |photos|
|
272
|
+
photos.fetch("sizes").map do |size|
|
273
|
+
size.values_at("width", "height", "url").tap do |whu|
|
274
|
+
w, h, u = whu
|
275
|
+
whu[0, 2] = FastImage.new(u, raise_on_failure: true).size if [w, h].include? 0
|
276
|
+
end
|
277
|
+
end.max_by{ |w, h, u| w * h }
|
278
|
+
end
|
270
279
|
end
|
271
280
|
|
272
281
|
class_variable_set :@@directlink, Struct.new(:url, :width, :height, :type)
|
@@ -275,7 +284,7 @@ end
|
|
275
284
|
|
276
285
|
require "fastimage"
|
277
286
|
|
278
|
-
def DirectLink link,
|
287
|
+
def DirectLink link, timeout = nil, giveup: false, ignore_meta: false
|
279
288
|
ArgumentError.new("link should be a <String>, not <#{link.class}>") unless link.is_a? String
|
280
289
|
begin
|
281
290
|
URI link
|
@@ -313,10 +322,10 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
|
|
313
322
|
**( %w{ reddit com } == URI(link).host.split(?.).last(2) ||
|
314
323
|
%w{ redd it } == URI(link).host.split(?.) ? {Cookie: "over18=1"} : {} ),
|
315
324
|
}
|
316
|
-
head = NetHTTPUtils.request_data link, :head, header: header, **(
|
317
|
-
timeout:
|
318
|
-
max_start_http_retry_delay:
|
319
|
-
max_read_retry_delay:
|
325
|
+
head = NetHTTPUtils.request_data link, :head, header: header, **(timeout ? {
|
326
|
+
timeout: timeout,
|
327
|
+
max_start_http_retry_delay: timeout,
|
328
|
+
max_read_retry_delay: timeout
|
320
329
|
} : {})
|
321
330
|
rescue Net::ReadTimeout
|
322
331
|
rescue NetHTTPUtils::Error => e
|
@@ -369,8 +378,8 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
|
|
369
378
|
raise DirectLink::ErrorBadLink.new link if giveup # TODO: print original url in such cases if there was a recursion
|
370
379
|
f = ->_{ _.type == :a ? _.attr["href"] : _.children.flat_map(&f) }
|
371
380
|
require "kramdown"
|
372
|
-
return f[Kramdown::Document.new(u).root].
|
373
|
-
DirectLink URI.join(link, sublink).to_s,
|
381
|
+
return f[Kramdown::Document.new(u).root].flat_map do |sublink|
|
382
|
+
DirectLink URI.join(link, sublink).to_s, timeout, giveup: giveup
|
374
383
|
end
|
375
384
|
end
|
376
385
|
return struct.new *u.values_at(*%w{ fallback_url width height }), "video" if u.is_a? Hash
|
@@ -381,8 +390,9 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
|
|
381
390
|
%w{ redd it } == URI(link).host.split(?.)
|
382
391
|
|
383
392
|
begin
|
384
|
-
w, h, u
|
385
|
-
|
393
|
+
return DirectLink.vk(link).map do |w, h, u|
|
394
|
+
struct.new u, w, h
|
395
|
+
end
|
386
396
|
rescue DirectLink::ErrorMissingEnvVar
|
387
397
|
end if %w{ vk com } == URI(link).host.split(?.)
|
388
398
|
|
@@ -391,7 +401,10 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
|
|
391
401
|
rescue FastImage::UnknownImageType
|
392
402
|
raise if giveup
|
393
403
|
require "nokogiri"
|
394
|
-
head = NetHTTPUtils.request_data link, :head, header: {"User-Agent" => "Mozilla"}
|
404
|
+
head = NetHTTPUtils.request_data link, :head, header: {"User-Agent" => "Mozilla"},
|
405
|
+
max_start_http_retry_delay: timeout,
|
406
|
+
timeout: timeout, # NetHTTPUtild passes this as read_timeout to Net::HTTP.start
|
407
|
+
max_read_retry_delay: timeout # and then compares accumulated delay to this
|
395
408
|
# if we use :get here we will download megabytes of files just to giveup on content_type we can't process
|
396
409
|
case head.instance_variable_get(:@last_response).content_type
|
397
410
|
when "text/html" ; nil
|
@@ -399,7 +412,10 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
|
|
399
412
|
end
|
400
413
|
html = Nokogiri::HTML NetHTTPUtils.request_data link, header: {"User-Agent" => "Mozilla"}
|
401
414
|
if t = html.at_css("meta[@property='og:image']")
|
402
|
-
|
415
|
+
begin
|
416
|
+
return DirectLink URI.join(link, t[:content]), nil, giveup: true
|
417
|
+
rescue URI::InvalidURIError
|
418
|
+
end
|
403
419
|
end unless ignore_meta
|
404
420
|
h = {} # TODO: maybe move it outside because of possible img[:src] recursion?...
|
405
421
|
l = lambda do |node, s = []|
|
@@ -413,9 +429,10 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
|
|
413
429
|
end
|
414
430
|
end
|
415
431
|
end
|
416
|
-
l[html].
|
417
|
-
raise if results.empty?
|
418
|
-
|
432
|
+
l[html].
|
433
|
+
tap{ |results| raise if results.empty? }.
|
434
|
+
group_by(&:first).map{ |k, v| [k.join(?>), v.map(&:last)] }.
|
435
|
+
max_by{ |_, v| v.map{ |i| i.width * i.height }.inject(:+) }.last
|
419
436
|
else
|
420
437
|
# TODO: maybe move this to right before `rescue` line
|
421
438
|
w, h = f.size
|
data/test.rb
CHANGED
@@ -363,6 +363,7 @@ describe DirectLink do
|
|
363
363
|
[
|
364
364
|
[ :_500px, [
|
365
365
|
["https://500px.com/photo/264092015/morning-rider-by-tiger-seo", [1200, 800, "https://drscdn.500px.org/photo/264092015/m%3D900/v2?sig=68a9206477f573d8e2838faa6a929e7267f22dc5f9e98f1771f7a8a63efa2ed7", "jpeg"]],
|
366
|
+
["https://500px.com/photo/1017579834/-poppies-flowers-by-David-Dubnitskiy/", [1819, 2500, "https://drscdn.500px.org/photo/1017579834/m%3D900/v2?sig=022e3e9dd836ffd8c1d31ae26c83735e4e42b4c8733d0c4380d8270aebbca44e", "jpeg"]],
|
366
367
|
] ],
|
367
368
|
[ :flickr, [
|
368
369
|
["https://www.flickr.com/photos/tomas-/17220613278/", DirectLink::ErrorNotFound],
|
@@ -395,16 +396,18 @@ describe DirectLink do
|
|
395
396
|
["https://www.reddit.com/r/hangers/comments/97you5/tara_radovic/", [true, "https://i.imgur.com/rbLqgOu.jpg"]], # "crossport" from Imgur
|
396
397
|
] ],
|
397
398
|
[ :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/
|
399
|
+
["https://vk.com/wall-105984091_7806", [[960, 1280, "https://sun9-41.userapi.com/c855224/v855224900/a72f1/7OZ8ux9Wcwo.jpg"]]],
|
400
|
+
["https://vk.com/wall298742340_4715", [[1080, 1080, "https://sun9-24.userapi.com/c857136/v857136625/15e38b/CsCqsJD174A.jpg"]]],
|
401
|
+
["https://vk.com/id57030827?z=photo57030827_456241143%2Falbum57030827_0", [[1920, 1440, "https://sun9-66.userapi.com/c845322/v845322944/167836/bP9z41BybhI.jpg"]]],
|
402
|
+
["https://vk.com/id57030827?z=photo57030827_456241143", [[1920, 1440, "https://sun9-66.userapi.com/c845322/v845322944/167836/bP9z41BybhI.jpg"]]],
|
403
|
+
["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"]]],
|
404
|
+
["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"]]],
|
405
|
+
["https://vk.com/photo533531776_456239427?all=1", [[750, 938, "https://sun9-25.userapi.com/c849416/v849416600/14b949/V01Ch1gYjhc.jpg"]]],
|
406
|
+
["https://vk.com/photo-155488973_456242404", [[1486, 1000, "https://sun9-7.userapi.com/c852132/v852132877/8578e/m6AJWiskiKE.jpg"]]],
|
407
|
+
["https://vk.com/id2272074?z=photo2272074_264578776%2Fphotos2272074", [[604, 484, "https://sun9-10.userapi.com/c10472/u2272074/-7/x_407b2ba2.jpg"]]],
|
408
|
+
["https://vk.com/feed?section=likes&z=photo-117564754_456261460%2Fliked3902406", [[1024, 1335, "https://sun9-72.userapi.com/c854028/v854028353/895b6/izQJresLdf0.jpg"]]],
|
409
|
+
["https://vk.com/likizimy?z=photo-42543351_456239941%2Fwall-42543351_1908", [[1179, 1731, "https://sun9-47.userapi.com/c855036/v855036571/60f7b/ryCPJIMyMkI.jpg"]]],
|
410
|
+
["https://vk.com/e_rod?z=photo298742340_457247118%2Fphotos298742340", [[1728, 2160, "https://sun9-53.userapi.com/c858320/v858320596/c7714/oImGe4o1ZJI.jpg"]]],
|
408
411
|
] ],
|
409
412
|
].each do |method, tests|
|
410
413
|
next if method == :vk && ENV.include?("TRAVIS")
|
@@ -441,7 +444,7 @@ describe DirectLink do
|
|
441
444
|
["https://goo.gl/ySqUb5", "https://i.imgur.com/QpOBvRY.png"],
|
442
445
|
],
|
443
446
|
_500px: [
|
444
|
-
%w{ https://500px.com/photo/112134597/milky-way-by-tom-hall https://
|
447
|
+
%w{ https://500px.com/photo/112134597/milky-way-by-tom-hall https://500px.com/photo/112134597/milky-way-by-tom-hall },
|
445
448
|
],
|
446
449
|
flickr: [
|
447
450
|
"https://www.flickr.com/photos/59880970@N07/15773941043/in/dateposted-public/",
|
@@ -648,7 +651,7 @@ describe DirectLink do
|
|
648
651
|
|
649
652
|
describe "other domains tests" do
|
650
653
|
[
|
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],
|
654
|
+
# ["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
655
|
# ["http://minus.com/lkP3hgRJd9npi", SocketError, /nodename nor servname provided, or not known|No address associated with hostname/, 0],
|
653
656
|
["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
657
|
].each_with_index do |(input, expectation, message_string_or_regex, max_redirect_resolving_retry_delay), i|
|
@@ -674,36 +677,39 @@ describe DirectLink do
|
|
674
677
|
describe "giving up" do
|
675
678
|
[
|
676
679
|
["http://example.com", FastImage::UnknownImageType],
|
677
|
-
["https://www.tic.com/index.html", FastImage::UnknownImageType, true],
|
678
|
-
["https://www.tic.com/index.html", 2],
|
680
|
+
# ["https://www.tic.com/index.html", FastImage::UnknownImageType, true], # needs new test or stub
|
681
|
+
# ["https://www.tic.com/index.html", 2], # needs new test or stub
|
679
682
|
["http://imgur.com/HQHBBBD", FastImage::UnknownImageType, true],
|
680
683
|
["http://imgur.com/HQHBBBD", "https://i.imgur.com/HQHBBBD.jpg?fb"], # .at_css("meta[@property='og:image']")
|
681
684
|
["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.
|
685
|
+
["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"],
|
686
|
+
["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
|
687
|
+
["https://www.reddit.com/r/darksouls3/comments/e59djh/hand_it_over_that_thing_your_wallpaper/", DirectLink::ErrorBadLink, true],
|
688
|
+
["https://www.reddit.com/r/darksouls3/comments/e59djh/hand_it_over_that_thing_your_wallpaper/", 6],
|
683
689
|
].each_with_index do |(input, expectation, giveup), i|
|
684
690
|
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"
|
691
|
+
ti = ENV.delete "IMGUR_CLIENT_ID" if %w{ imgur com } == URI(input).host.split(?.).last(2)
|
692
|
+
tr = ENV.delete "REDDIT_SECRETS" if %w{ reddit com } == URI(input).host.split(?.).last(2)
|
687
693
|
begin
|
688
694
|
case expectation
|
689
695
|
when Class
|
690
696
|
e = assert_raises expectation, "for #{input} (giveup = #{giveup})" do
|
691
|
-
DirectLink input,
|
697
|
+
DirectLink input, 10, giveup: giveup
|
692
698
|
end
|
693
699
|
assert_equal expectation.to_s, e.class.to_s, "for #{input} (giveup = #{giveup})"
|
694
700
|
when String
|
695
|
-
result = DirectLink input,
|
701
|
+
result = DirectLink input, 10, giveup: giveup
|
696
702
|
assert_equal expectation, result.url, "for #{input} (giveup = #{giveup})"
|
697
703
|
else
|
698
|
-
result = DirectLink input,
|
704
|
+
result = DirectLink input, 10, giveup: giveup
|
699
705
|
result = [result] unless result.is_a? Array # we can't do `Array(<Struct>)` because it splats by elements
|
700
706
|
assert_equal expectation, result.size, ->{
|
701
707
|
"for #{input} (giveup = #{giveup}): #{result.map &:url}"
|
702
708
|
}
|
703
709
|
end
|
704
710
|
ensure
|
705
|
-
ENV["IMGUR_CLIENT_ID"] = ti
|
706
|
-
ENV["REDDIT_SECRETS"] = tr
|
711
|
+
ENV["IMGUR_CLIENT_ID"] = ti if ti
|
712
|
+
ENV["REDDIT_SECRETS"] = tr if tr
|
707
713
|
end
|
708
714
|
end
|
709
715
|
end
|
@@ -816,7 +822,7 @@ describe DirectLink do
|
|
816
822
|
end
|
817
823
|
it "ignores <meta> tag" do
|
818
824
|
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/
|
825
|
+
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
826
|
end
|
821
827
|
|
822
828
|
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.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:
|
11
|
+
date: 2020-06-28 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
|