directlink 0.0.8.4 → 0.0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/directlink.gemspec +1 -1
  3. data/lib/directlink.rb +10 -7
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f42b5eafdc2cffee78b290dd2b2873863da1f17
4
- data.tar.gz: edda6ebe3c54923788d5ead6591896a26d0601fc
3
+ metadata.gz: e62e48e14056c1b1ab1c34049bc1e4137ca77239
4
+ data.tar.gz: 405b2ee26671bf02bcc118dd4ae985ba99d545db
5
5
  SHA512:
6
- metadata.gz: b3e0f61364cce617a0bcc7f1ffa03ff2b94f459c80b368a3395596a17015c04217dfeee31d31b8f416f76f88ee80851084e55a6fc1180725f128ac874bc8fbde
7
- data.tar.gz: 07e69d129b074449d3dcc52d187dc9e163fc70bbaabf2a5bbd319127a6447c13408f75b3d8528be8fb1974b8f9b21904a09b13fff301311fd7dfa99070a5f335
6
+ metadata.gz: 1b171d73b0edd1ad7b7e7cab84bf78c82916044858c9fdbd0c8dabfd6cba6a00d6b03db9ef6ac84a001e82f769cbd8df4142f30295aab1670dcfe22700cca812
7
+ data.tar.gz: ffddae00c3c62fa43ea4ce3050def2347d1010e908f1da28a886d72e39ce3c62f4202f5343180f4869523023f832e5be7f40231344baf30fc6510da03c427a50
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "directlink"
3
- spec.version = "0.0.8.4"
3
+ spec.version = "0.0.8.5"
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"
@@ -275,7 +275,7 @@ end
275
275
 
276
276
  require "fastimage"
277
277
 
278
- def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ignore_meta: false
278
+ def DirectLink link, timeout = nil, giveup: false, ignore_meta: false
279
279
  ArgumentError.new("link should be a <String>, not <#{link.class}>") unless link.is_a? String
280
280
  begin
281
281
  URI link
@@ -313,10 +313,10 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
313
313
  **( %w{ reddit com } == URI(link).host.split(?.).last(2) ||
314
314
  %w{ redd it } == URI(link).host.split(?.) ? {Cookie: "over18=1"} : {} ),
315
315
  }
316
- head = NetHTTPUtils.request_data link, :head, header: header, **(max_redirect_resolving_retry_delay ? {
317
- timeout: max_redirect_resolving_retry_delay,
318
- max_start_http_retry_delay: max_redirect_resolving_retry_delay,
319
- max_read_retry_delay: max_redirect_resolving_retry_delay
316
+ head = NetHTTPUtils.request_data link, :head, header: header, **(timeout ? {
317
+ timeout: timeout,
318
+ max_start_http_retry_delay: timeout,
319
+ max_read_retry_delay: timeout
320
320
  } : {})
321
321
  rescue Net::ReadTimeout
322
322
  rescue NetHTTPUtils::Error => e
@@ -370,7 +370,7 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
370
370
  f = ->_{ _.type == :a ? _.attr["href"] : _.children.flat_map(&f) }
371
371
  require "kramdown"
372
372
  return f[Kramdown::Document.new(u).root].map do |sublink|
373
- DirectLink URI.join(link, sublink).to_s, max_redirect_resolving_retry_delay, giveup: giveup
373
+ DirectLink URI.join(link, sublink).to_s, timeout, giveup: giveup
374
374
  end
375
375
  end
376
376
  return struct.new *u.values_at(*%w{ fallback_url width height }), "video" if u.is_a? Hash
@@ -391,7 +391,10 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
391
391
  rescue FastImage::UnknownImageType
392
392
  raise if giveup
393
393
  require "nokogiri"
394
- head = NetHTTPUtils.request_data link, :head, header: {"User-Agent" => "Mozilla"}
394
+ head = NetHTTPUtils.request_data link, :head, header: {"User-Agent" => "Mozilla"},
395
+ max_start_http_retry_delay: timeout,
396
+ timeout: timeout, # NetHTTPUtild passes this as read_timeout to Net::HTTP.start
397
+ max_read_retry_delay: timeout # and then compares accumulated delay to this
395
398
  # if we use :get here we will download megabytes of files just to giveup on content_type we can't process
396
399
  case head.instance_variable_get(:@last_response).content_type
397
400
  when "text/html" ; nil
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.8.4
4
+ version: 0.0.8.5
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: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2019-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastimage