directlink 0.0.8.6 → 0.0.8.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a1ae138f21693bf2fd25cdeaf7bc4752bb13ea3
4
- data.tar.gz: 324e4a5f70a2d41a44b49c8990b3f86d75097b94
3
+ metadata.gz: c8c2014f90201877c2ba3e77b957bcc868ff0fd0
4
+ data.tar.gz: f022f3940ca791a122dedd4f04f3f993d70c1b92
5
5
  SHA512:
6
- metadata.gz: 46fb0e0f41a0b08f0f9b649492b39e279ce18b98cad89a07eb85bed2a1e1785e84180e65de7b0186e699ed942920af55e895dcc8892c6f04aca0da8e1b19ae6c
7
- data.tar.gz: 9b27ff12af472d897c029dbe45416c7bedfdefd86afd0af88ec6cca65864c10a98603282cafc526796cda43dedae7657c107441ad3c4878dcf62645536719a75
6
+ metadata.gz: 71db986e82556414634ad85effdc9661c8816da3a448b86e0ffcb35acfe99118f83c03ed6d4ace3984555681f19acebc6253d4bea45ad9d16b179a689085d0b9
7
+ data.tar.gz: 336fa591f2a3371bed2a075ad89e0a9f9fb9555010910d3ac624cbe36dfe2c72b812494f1197023962b567ea44094cf49f0c8b77047db5611d267424055d361d
data/.bashrc CHANGED
@@ -1,4 +1,5 @@
1
1
  source api_tokens_for_travis.sh
2
- echo 'to test: ruby -I../nethttputils/lib -I./lib test.rb'
3
- echo 'to test: ruby -I../nethttputils/lib -I./lib ./bin/directlink --debug ...'
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 ...'
@@ -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|
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "directlink"
3
- spec.version = "0.0.8.6"
3
+ spec.version = "0.0.8.7"
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"
@@ -369,7 +369,7 @@ def DirectLink link, timeout = nil, giveup: false, ignore_meta: false
369
369
  raise DirectLink::ErrorBadLink.new link if giveup # TODO: print original url in such cases if there was a recursion
370
370
  f = ->_{ _.type == :a ? _.attr["href"] : _.children.flat_map(&f) }
371
371
  require "kramdown"
372
- return f[Kramdown::Document.new(u).root].map do |sublink|
372
+ return f[Kramdown::Document.new(u).root].flat_map do |sublink|
373
373
  DirectLink URI.join(link, sublink).to_s, timeout, giveup: giveup
374
374
  end
375
375
  end
@@ -402,7 +402,10 @@ def DirectLink link, timeout = nil, giveup: false, ignore_meta: false
402
402
  end
403
403
  html = Nokogiri::HTML NetHTTPUtils.request_data link, header: {"User-Agent" => "Mozilla"}
404
404
  if t = html.at_css("meta[@property='og:image']")
405
- return DirectLink URI.join(link, t[:content]), nil, giveup: true
405
+ begin
406
+ return DirectLink URI.join(link, t[:content]), nil, giveup: true
407
+ rescue URI::InvalidURIError
408
+ end
406
409
  end unless ignore_meta
407
410
  h = {} # TODO: maybe move it outside because of possible img[:src] recursion?...
408
411
  l = lambda do |node, s = []|
data/test.rb CHANGED
@@ -681,10 +681,12 @@ describe DirectLink do
681
681
  ["https://www.deviantart.com/nadyasonika/art/Asuka-Langley-Beach-Time-590134861", FastImage::UnknownImageType, true],
682
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.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9NzMyIiwicGF0aCI6IlwvZlwvOTQzZjY2Y2ItNzhhZC00MGYyLWEwODYtNDQ0MjBiOThiNDMxXC9kOXJjbXoxLTVjYmM1NjcwLTAxOTMtNDg1Yi1hYzE0LTc1NWRkYjk1NjJmNC5qcGciLCJ3aWR0aCI6Ijw9MTAyNCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.M-a_heYtVPwnR4eC9KIPk2mIYeNzEaTg4b4jqr_GwyI"],
683
683
  ["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
684
+ ["https://www.reddit.com/r/darksouls3/comments/e59djh/hand_it_over_that_thing_your_wallpaper/", DirectLink::ErrorBadLink, true],
685
+ ["https://www.reddit.com/r/darksouls3/comments/e59djh/hand_it_over_that_thing_your_wallpaper/", 6],
684
686
  ].each_with_index do |(input, expectation, giveup), i|
685
687
  it "##{i + 1} (#{URI(input).host}) (giveup=#{!!giveup})" do # to match with minitest `-n` run flag
686
- ti = ENV.delete "IMGUR_CLIENT_ID"
687
- tr = ENV.delete "REDDIT_SECRETS"
688
+ ti = ENV.delete "IMGUR_CLIENT_ID" if %w{ imgur com } == URI(input).host.split(?.).last(2)
689
+ tr = ENV.delete "REDDIT_SECRETS" if %w{ reddit com } == URI(input).host.split(?.).last(2)
688
690
  begin
689
691
  case expectation
690
692
  when Class
@@ -703,8 +705,8 @@ describe DirectLink do
703
705
  }
704
706
  end
705
707
  ensure
706
- ENV["IMGUR_CLIENT_ID"] = ti
707
- ENV["REDDIT_SECRETS"] = tr
708
+ ENV["IMGUR_CLIENT_ID"] = ti if ti
709
+ ENV["REDDIT_SECRETS"] = tr if tr
708
710
  end
709
711
  end
710
712
  end
@@ -817,7 +819,7 @@ describe DirectLink do
817
819
  end
818
820
  it "ignores <meta> tag" do
819
821
  string, status = Open3.capture2e "RUBYOPT='-rbundler/setup' ./bin/directlink --json --ignore-meta https://www.kp.ru/daily/26342.7/3222103/"
820
- assert_equal [0, 21, "https://s11.stc.all.kpcdn.net/share/i/12/8024261/wx1080.jpg"], [status.exitstatus, JSON.load(string).size, JSON.load(string).first.fetch("url")]
822
+ 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")]
821
823
  end
822
824
 
823
825
  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.8.6
4
+ version: 0.0.8.7
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-20 00:00:00.000000000 Z
11
+ date: 2020-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastimage