directlink 0.0.6.0 → 0.0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/directlink.gemspec +1 -1
  3. data/lib/directlink.rb +11 -4
  4. data/test.rb +44 -40
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '09afa7efc0cf49f2742c257d2aa0c0810ed5e888'
4
- data.tar.gz: 2241c093814a7f3b2e75dcf44ab7c75d79752013
3
+ metadata.gz: 1b33e244fed09c86b5d956379f5030f225a9cb59
4
+ data.tar.gz: 4324a01c311800d7d28104378175c9894635dffb
5
5
  SHA512:
6
- metadata.gz: 7bb2f434417735a0bbc9526aa2c632b6fe50bb326e5db74b8d86f8cc700ff42f99387a2058b53c7b6bddcab198129718f2412810fb1e403fdd5e14bd2d42bc16
7
- data.tar.gz: f40c51e45aadee4af3ec6d2244d9dc6209ddb7d3f22cb8ecefea2d017e1b8861dfad3cc39b52851b112ea6a69e017cc4a9e4b7491c1822794ac9e655531bfbe0
6
+ metadata.gz: eaa015a87590f251a650cca774af4e1dea7083eaeb73690d121fed151b700241f09dc9f509229a8eb121c43a26e7f1b6f646e99049d573d27cd3c1ab89cce9ce
7
+ data.tar.gz: 23fc26919824925f0774b293f685d4fe5036633ec9b67e11f6d1f5add99d3651a59c2cb144d4246a28cccbbe2f2f394d5e6d5fff78dbb3026f8169d5a03180fd
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.6.0"
3
+ spec.version = "0.0.6.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"
data/lib/directlink.rb CHANGED
@@ -280,9 +280,16 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup = false
280
280
  # max_read_retry_delay: 5, timeout: 5
281
281
 
282
282
  begin
283
- head = NetHTTPUtils.request_data link, :head, header: {
284
- "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36"
285
- }, **(max_redirect_resolving_retry_delay ? {timeout: max_redirect_resolving_retry_delay, max_start_http_retry_delay: max_redirect_resolving_retry_delay, max_read_retry_delay: max_redirect_resolving_retry_delay} : {})
283
+ header = {
284
+ "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36",
285
+ **( %w{ reddit com } == URI(link).host.split(?.).last(2) ||
286
+ %w{ redd it } == URI(link).host.split(?.) ? {Cookie: "over18=1"} : {} ),
287
+ }
288
+ head = NetHTTPUtils.request_data link, :head, header: header, **(max_redirect_resolving_retry_delay ? {
289
+ timeout: max_redirect_resolving_retry_delay,
290
+ max_start_http_retry_delay: max_redirect_resolving_retry_delay,
291
+ max_read_retry_delay: max_redirect_resolving_retry_delay
292
+ } : {})
286
293
  rescue Net::ReadTimeout
287
294
  else
288
295
  link = head.instance_variable_get(:@last_response).uri.to_s
@@ -341,7 +348,7 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup = false
341
348
  fail if link == u
342
349
  rescue DirectLink::ErrorMissingEnvVar
343
350
  end if %w{ reddit com } == URI(link).host.split(?.).last(2) ||
344
- %w{ redd it } == URI(link).host.split(?.)
351
+ %w{ redd it } == URI(link).host.split(?.)
345
352
 
346
353
  begin
347
354
  f = FastImage.new(link, raise_on_failure: true, timeout: 5, http_header: {"User-Agent" => "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36"})
data/test.rb CHANGED
@@ -254,9 +254,9 @@ describe DirectLink do
254
254
  assert_nil e.cause if Exception.instance_methods.include? :cause # Ruby 2.1
255
255
  end
256
256
 
257
- valid_imgur_image_url_direct = "https://i.imgur.com/BLCesav.jpg"
257
+ valid_imgur_image_url_direct = "https://i.imgur.com/dCQprEq.jpg"
258
258
  it 200 do
259
- assert_equal [["https://i.imgur.com/BLCesav.jpg", 1000, 1500, "image/jpeg"]],
259
+ assert_equal [[valid_imgur_image_url_direct, 5760, 3840, "image/jpeg"]],
260
260
  DirectLink.imgur(valid_imgur_image_url_direct)
261
261
  end
262
262
  valid_imgur_image_url_album = "https://imgur.com/a/wPi63mj"
@@ -284,7 +284,7 @@ describe DirectLink do
284
284
  raise NetHTTPUtils::Error.new "", 400 if 1 == f += 1
285
285
  m.call *args
286
286
  } do
287
- assert_equal [["https://i.imgur.com/BLCesav.jpg", 1000, 1500, "image/jpeg"]],
287
+ assert_equal [[valid_imgur_image_url_direct, 5760, 3840, "image/jpeg"]],
288
288
  DirectLink.imgur(valid_imgur_image_url_direct, 4) # do not remove `4` or test may hang
289
289
  end
290
290
  end
@@ -298,7 +298,7 @@ describe DirectLink do
298
298
  end
299
299
 
300
300
  [ # TODO: move these end line comments to test names; and do the same in other tests
301
- ["https://imgur.com/a/Aoh6l", "https://i.imgur.com/BLCesav.jpg", 1000, 1500, "image/jpeg"],
301
+ ["https://imgur.com/a/j5xmY", "https://i.imgur.com/KTTuoyN.jpg", 2828, 2828, "image/jpeg"], # single photo album
302
302
  ["http://i.imgur.com/7xcxxkR.gifv", "http://i.imgur.com/7xcxxkRh.gif", 718, 404, "image/gif"],
303
303
  ["https://imgur.com/9yaMdJq", "https://i.imgur.com/9yaMdJq.mp4", 720, 404, "video/mp4"],
304
304
  ["http://imgur.com/gallery/dCQprEq/new", "https://i.imgur.com/dCQprEq.jpg"],
@@ -371,10 +371,10 @@ describe DirectLink do
371
371
  ["https://www.flickr.com/photos/jacob_schmidt/18414267018/in/album-72157654235845651/", DirectLink::ErrorNotFound], # username in-album
372
372
  ["https://www.flickr.com/photos/tommygi/5291099420/in/dateposted-public/", [1600, 1062, "https://live.staticflickr.com/5249/5291099420_3bf8f43326_o.jpg"]], # username in-public
373
373
  ["https://www.flickr.com/photos/132249412@N02/18593786659/in/album-72157654521569061/", DirectLink::ErrorNotFound],
374
- ["https://www.flickr.com/photos/130019700@N03/18848891351/in/dateposted-public/", [4621, 3081, "https://farm4.staticflickr.com/3796/18848891351_f751b35aeb_o.jpg"]], # userid in-public
375
- ["https://www.flickr.com/photos/frank3/3778768209/in/photolist-6KVb92-eCDTCr-ur8K-7qbL5z-c71afh-c6YvXW-7mHG2L-c71ak9-c71aTq-c71azf-c71aq5-ur8Q-6F6YkR-eCDZsD-eCEakg-eCE6DK-4ymYku-7ubEt-51rUuc-buujQE-ur8x-9fuNu7-6uVeiK-qrmcC6-ur8D-eCEbei-eCDY9P-eCEhCk-eCE5a2-eCH457-eCHrcq-eCEdZ4-eCH6Sd-c71b5o-c71auE-eCHa8m-eCDSbz-eCH1dC-eCEg3v-7JZ4rh-9KwxYL-6KV9yR-9tUSbU-p4UKp7-eCHfwS-6KVbAH-5FrdbP-eeQ39v-eeQ1UR-4jHAGN", [1024, 681, "https://farm3.staticflickr.com/2499/3778768209_280f82abab_b.jpg"]],
376
- ["https://www.flickr.com/photos/patricksloan/18230541413/sizes/l", [2048, 491, "https://farm6.staticflickr.com/5572/18230541413_fec4783d79_k.jpg"]],
377
- ["https://flic.kr/p/vPvCWJ", [2048, 1365, "https://farm1.staticflickr.com/507/19572004110_d44d1b4ead_k.jpg"]],
374
+ ["https://www.flickr.com/photos/130019700@N03/18848891351/in/dateposted-public/", [4621, 3081, "https://live.staticflickr.com/3796/18848891351_f751b35aeb_o.jpg"]], # userid in-public
375
+ ["https://www.flickr.com/photos/frank3/3778768209/in/photolist-6KVb92-eCDTCr-ur8K-7qbL5z-c71afh-c6YvXW-7mHG2L-c71ak9-c71aTq-c71azf-c71aq5-ur8Q-6F6YkR-eCDZsD-eCEakg-eCE6DK-4ymYku-7ubEt-51rUuc-buujQE-ur8x-9fuNu7-6uVeiK-qrmcC6-ur8D-eCEbei-eCDY9P-eCEhCk-eCE5a2-eCH457-eCHrcq-eCEdZ4-eCH6Sd-c71b5o-c71auE-eCHa8m-eCDSbz-eCH1dC-eCEg3v-7JZ4rh-9KwxYL-6KV9yR-9tUSbU-p4UKp7-eCHfwS-6KVbAH-5FrdbP-eeQ39v-eeQ1UR-4jHAGN", [1024, 681, "https://live.staticflickr.com/2499/3778768209_280f82abab_b.jpg"]],
376
+ ["https://www.flickr.com/photos/patricksloan/18230541413/sizes/l", [2048, 491, "https://live.staticflickr.com/5572/18230541413_fec4783d79_k.jpg"]],
377
+ ["https://flic.kr/p/vPvCWJ", [2048, 1365, "https://live.staticflickr.com/507/19572004110_d44d1b4ead_k.jpg"]],
378
378
  ] ],
379
379
  [ :wiki, [
380
380
  ["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"],
@@ -412,43 +412,47 @@ describe DirectLink do
412
412
  end
413
413
 
414
414
  {
415
- google: %w{
416
- https://lh3.googleusercontent.com/-NVJgqmI_2Is/WqMM2OMYg-I/AAAAAAAALrk/5-p3JL3iZt0Ho9dOf_p3gpddzqwr3Wp0ACJoC/w424-h318-n/001
417
- //lh3.googleusercontent.com/proxy/DZtTi5KL7PqiBwJc8weNGLk_Wi2UTaQH0AC_h2kuURiu0AbwyI2ywOk2XgdAjL7ceg=w530-h354-n
418
- //1.bp.blogspot.com/-rYk_u-qROQc/WngolJ8M0LI/AAAAAAAAD-w/woivnaIVzasBPG5C2T1t-VrWKRd_U6lMgCLcBGAs/w530-h278-p/i-469.jpg
419
- https://2.bp.blogspot.com/-rb2PXLGZy0s/W2nQe3mXOSI/AAAAAAAARhQ/P8gV-bMtYbY2xxpTJNcYVxu3XDTUaugxQCLcBGAs/s640/beach-bora-bora-clouds-753626.jpg
420
- 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
421
- https://lh5.googleusercontent.com/FcYUQBKLXWtFLEvbQduvu7FHUm2f7U_MVdMBVnNbpwfzKHIU-xABkudxw-m21SlM0jFYRHedh7Is5Dg6qlgIQF1iSndlWjiKCTTsUo1w=s1080
422
- },
423
- imgur: %w{
424
- https://imgur.com/3eThW
425
- https://i.imgur.com/3eThW
426
- https://m.imgur.com/3eThW
427
- https://www.imgur.com/3eThW
428
- https://goo.gl/ySqUb5
429
- },
415
+ google: [
416
+ "https://lh3.googleusercontent.com/-NVJgqmI_2Is/WqMM2OMYg-I/AAAAAAAALrk/5-p3JL3iZt0Ho9dOf_p3gpddzqwr3Wp0ACJoC/w424-h318-n/001",
417
+ "//lh3.googleusercontent.com/proxy/DZtTi5KL7PqiBwJc8weNGLk_Wi2UTaQH0AC_h2kuURiu0AbwyI2ywOk2XgdAjL7ceg=w530-h354-n",
418
+ "//1.bp.blogspot.com/-rYk_u-qROQc/WngolJ8M0LI/AAAAAAAAD-w/woivnaIVzasBPG5C2T1t-VrWKRd_U6lMgCLcBGAs/w530-h278-p/i-469.jpg",
419
+ "https://2.bp.blogspot.com/-rb2PXLGZy0s/W2nQe3mXOSI/AAAAAAAARhQ/P8gV-bMtYbY2xxpTJNcYVxu3XDTUaugxQCLcBGAs/s640/beach-bora-bora-clouds-753626.jpg",
420
+ "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",
421
+ "https://lh5.googleusercontent.com/FcYUQBKLXWtFLEvbQduvu7FHUm2f7U_MVdMBVnNbpwfzKHIU-xABkudxw-m21SlM0jFYRHedh7Is5Dg6qlgIQF1iSndlWjiKCTTsUo1w=s1080",
422
+ ],
423
+ imgur: [
424
+ ["https://imgur.com/3eThW", "https://imgur.com/3eThW"],
425
+ ["https://i.imgur.com/3eThW", "https://imgur.com/3eThW"],
426
+ ["https://m.imgur.com/3eThW", "https://imgur.com/3eThW"],
427
+ ["https://www.imgur.com/3eThW", "https://imgur.com/3eThW"],
428
+ ["https://goo.gl/ySqUb5", "https://i.imgur.com/QpOBvRY.png"],
429
+ ],
430
430
  _500px: %w{
431
431
  https://500px.com/photo/112134597/milky-way-by-tom-hall
432
432
  },
433
- flickr: %w{
434
- https://www.flickr.com/photos/59880970@N07/15773941043/in/dateposted-public/
435
- https://flic.kr/p/vPvCWJ
436
- },
437
- wiki: %w{
438
- https://en.wikipedia.org/wiki/Third_Party_System#/media/File:United_States_presidential_election_results,_1876-1892.svg
439
- http://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg
440
- },
441
- reddit: %w{
442
- https://www.reddit.com/r/cacography/comments/32tq0i/c/
443
- http://redd.it/32tq0i
444
- https://reddit.com/123456
445
- https://www.reddit.com/r/travel/988889
446
- },
433
+ flickr: [
434
+ "https://www.flickr.com/photos/59880970@N07/15773941043/in/dateposted-public/",
435
+ ["https://flic.kr/p/vPvCWJ", "https://www.flickr.com/photos/mlopezphotography/19572004110/"],
436
+ ],
437
+ wiki: [
438
+ "https://en.wikipedia.org/wiki/Third_Party_System#/media/File:United_States_presidential_election_results,_1876-1892.svg",
439
+ ["http://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg", "https://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg"],
440
+ ],
441
+ reddit: [
442
+ "https://www.reddit.com/r/cacography/comments/32tq0i/c/",
443
+ ["http://redd.it/32tq0i", "https://www.reddit.com/comments/32tq0i"],
444
+ ["https://reddit.com/123456", "https://www.reddit.com/r/funny/comments/123456/im_thinking_about_getting_a_dog_and_youtubed_ways/"],
445
+ ["https://www.reddit.com/r/travel/988889", "https://www.reddit.com/r/travel/comments/988889/playa_miramar_in_guaymas_sonora/"],
446
+ "https://www.reddit.com/r/KsyushaEgorova/comments/beuqs2/a_little_shy/", # NSFW causes redirect to /over_18? if the special cookie not provided
447
+ ],
447
448
  }.each do |method, tests|
448
449
  describe "DirectLink() calls #{method}" do
449
- tests.each_with_index do |input, i|
450
- it "##{i + 1} (this may prematurely fail on redirect resolving, so links should be valid)" do
451
- DirectLink.stub method, ->link{ throw :_ } do
450
+ tests.each_with_index do |(input, expected), i|
451
+ it "##{i + 1}" do
452
+ DirectLink.stub method, ->link{
453
+ assert_equal (expected || input), link
454
+ throw :_
455
+ } do
452
456
  catch :_ do
453
457
  DirectLink input
454
458
  fail "DirectLink.#{method} was not called"
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.6.0
4
+ version: 0.0.6.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: 2019-04-02 00:00:00.000000000 Z
11
+ date: 2019-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastimage