directlink 0.0.7.0 → 0.0.8.0
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/api_tokens_for_travis.sh +5 -0
- data/directlink.gemspec +2 -2
- data/lib/directlink.rb +19 -0
- data/test.rb +10 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ed510f04f8bd32fadeb16a4ea27d1133dc8946e
|
4
|
+
data.tar.gz: bf1afde92343fc551abbf6b10902745842dfe496
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2612ddaf05fe8ea4158806d00be6209455772c004d33373bacbe00ffc1cc538aee9c4dade3d84f24c7052e0ec3ed38db0b48192c939c346c590d9d47428bcda
|
7
|
+
data.tar.gz: 647f789a878dd956827ab402ebd0a8147e81c8951e8389eddc1be57c158e33a9cbdaea4d08da604249907d0a094c0966cdf34dafb0376fbcc53414efc170cd8b
|
data/api_tokens_for_travis.sh
CHANGED
@@ -1,3 +1,8 @@
|
|
1
1
|
export IMGUR_CLIENT_ID=0f99cd781c9d0d8
|
2
2
|
export FLICKR_API_KEY=dc2bfd348b01bdc5b09d36876dc38f3d
|
3
3
|
export REDDIT_SECRETS=reddit_token_for_travis.yaml
|
4
|
+
|
5
|
+
touch vk.secret
|
6
|
+
source vk.secret
|
7
|
+
# export VK_ACCESS_TOKEN=... # can't put this here because there is no way known to me to limit the scope of the eternal access token
|
8
|
+
# export VK_CLIENT_SECRET=... # (service key) # can't put this here because there is no way known to me to limit the scope of the eternal access token
|
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.8.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"
|
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.files = `git ls-files -z`.split(?\0) - spec.test_files
|
26
26
|
|
27
27
|
spec.requirements << "you may need to create apps and provide their API tokens:"
|
28
|
-
spec.requirements << "IMGUR_CLIENT_ID, FLICKR_API_KEY"
|
28
|
+
spec.requirements << "IMGUR_CLIENT_ID, FLICKR_API_KEY, REDDIT_SECRETS"
|
29
29
|
end
|
data/lib/directlink.rb
CHANGED
@@ -241,6 +241,17 @@ module DirectLink
|
|
241
241
|
return [false, data["selftext"]]
|
242
242
|
end
|
243
243
|
|
244
|
+
def self.vk link
|
245
|
+
raise ErrorBadLink.new link unless %r{\Ahttps?://vk\.com/id(?<user_id>\d+)\?z=photo(?<id>\k<user_id>_\d+)\z} =~ link
|
246
|
+
raise ErrorMissingEnvVar.new "define VK_ACCESS_TOKEN and VK_CLIENT_SECRET env vars" unless ENV["VK_ACCESS_TOKEN"] && ENV["VK_CLIENT_SECRET"]
|
247
|
+
json = JSON.load NetHTTPUtils.request_data "https://api.vk.com/method/photos.getById", :POST, form: { photos: id, access_token: ENV["VK_ACCESS_TOKEN"], client_secret: ENV["VK_CLIENT_SECRET"], v: "5.101" }
|
248
|
+
json.fetch("response").tap do |r|
|
249
|
+
raise ErrorAssert.new unless 1 == r.size
|
250
|
+
end.first.fetch("sizes").map do |s|
|
251
|
+
s.values_at "width", "height", "url"
|
252
|
+
end.max_by{ |w, h, u| w * h }
|
253
|
+
end
|
254
|
+
|
244
255
|
class_variable_set :@@directlink, Struct.new(:url, :width, :height, :type)
|
245
256
|
end
|
246
257
|
|
@@ -291,6 +302,8 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
|
|
291
302
|
max_read_retry_delay: max_redirect_resolving_retry_delay
|
292
303
|
} : {})
|
293
304
|
rescue Net::ReadTimeout
|
305
|
+
rescue NetHTTPUtils::Error => e
|
306
|
+
raise unless 418 == e.code
|
294
307
|
else
|
295
308
|
link = head.instance_variable_get(:@last_response).uri.to_s
|
296
309
|
end
|
@@ -350,6 +363,12 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup: false, ig
|
|
350
363
|
end if %w{ reddit com } == URI(link).host.split(?.).last(2) ||
|
351
364
|
%w{ redd it } == URI(link).host.split(?.)
|
352
365
|
|
366
|
+
begin
|
367
|
+
w, h, u = DirectLink.vk(link)
|
368
|
+
return struct.new u, w, h
|
369
|
+
rescue DirectLink::ErrorMissingEnvVar
|
370
|
+
end if %w{ vk com } == URI(link).host.split(?.)
|
371
|
+
|
353
372
|
begin
|
354
373
|
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"})
|
355
374
|
rescue FastImage::UnknownImageType
|
data/test.rb
CHANGED
@@ -394,6 +394,9 @@ describe DirectLink do
|
|
394
394
|
["https://www.reddit.com/r/CatsStandingUp/duplicates/abn0ua/cat/", [true, "https://v.redd.it/s9b86afb6w721/DASH_2_4_M?source=fallback"]],
|
395
395
|
["https://www.reddit.com/r/hangers/comments/97you5/tara_radovic/", [true, "https://i.imgur.com/rbLqgOu.jpg"]], # "crossport" from Imgur
|
396
396
|
] ],
|
397
|
+
[ :vk, [
|
398
|
+
["https://vk.com/id57030827?z=photo57030827_456241143", [1920, 1440, "https://sun9-66.userapi.com/c845322/v845322944/167836/bP9z41BybhI.jpg"]],
|
399
|
+
] ],
|
397
400
|
].each do |method, tests|
|
398
401
|
describe method do
|
399
402
|
tests.each_with_index do |(input, expectation), i|
|
@@ -445,6 +448,9 @@ describe DirectLink do
|
|
445
448
|
# ["https://www.reddit.com/r/travel/988889", "https://www.reddit.com/r/travel/comments/988889/playa_miramar_in_guaymas_sonora/"],
|
446
449
|
"https://www.reddit.com/r/KsyushaEgorova/comments/beuqs2/a_little_shy/", # NSFW causes redirect to /over_18? if the special cookie not provided
|
447
450
|
],
|
451
|
+
vk: [
|
452
|
+
"https://vk.com/id57030827?z=photo57030827_456241143",
|
453
|
+
],
|
448
454
|
}.each do |method, tests|
|
449
455
|
describe "DirectLink() calls #{method}" do
|
450
456
|
tests.each_with_index do |(input, expected), i|
|
@@ -514,7 +520,7 @@ describe DirectLink do
|
|
514
520
|
end
|
515
521
|
|
516
522
|
describe "throws ErrorBadLink if method does not match the link" do
|
517
|
-
%i{ google imgur flickr _500px wiki reddit }.each do |method|
|
523
|
+
%i{ google imgur flickr _500px wiki reddit vk }.each do |method|
|
518
524
|
["", "test", "http://example.com/"].each_with_index do |url, i|
|
519
525
|
it "#{method} ##{i + 1}" do
|
520
526
|
assert_raises DirectLink::ErrorBadLink do
|
@@ -617,6 +623,7 @@ describe DirectLink do
|
|
617
623
|
[:_500px, "https://500px.com/photo/112134597/milky-way-by-tom-hall"],
|
618
624
|
[:wiki, "http://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg"],
|
619
625
|
[:reddit, "https://www.reddit.com/123456"],
|
626
|
+
[:vk, "https://vk.com/"],
|
620
627
|
].each do |method, link|
|
621
628
|
it "can otherwise raise DirectLink::ErrorBadLink #{method}" do
|
622
629
|
e = assert_raises(DirectLink::ErrorBadLink, link) do
|
@@ -739,7 +746,7 @@ describe DirectLink do
|
|
739
746
|
# TODO: a test that it appends the `exception.cause`
|
740
747
|
].each_with_index do |(expected_exit_code, link, expected_output, unset), i| # TODO: unset is not used anymore or I have to go sleep?
|
741
748
|
it "##{i + 1}" do
|
742
|
-
string, status = Open3.capture2e "export #{File.read("api_tokens_for_travis.sh").
|
749
|
+
string, status = Open3.capture2e "export #{(File.read("api_tokens_for_travis.sh") + File.read("vk.secret")).scan(/(?<=^export )\S+=\S+/).join(" ")}#{unset} && RUBYOPT='-rbundler/setup #{$-I.map{ |i| "-I #{i}" }.join " "}' ./bin/directlink #{link}"
|
743
750
|
assert_equal [expected_exit_code, "#{expected_output}\n"], [status.exitstatus, string], "for #{link}"
|
744
751
|
end
|
745
752
|
end
|
@@ -782,7 +789,7 @@ describe DirectLink do
|
|
782
789
|
'.gsub(/^ {8}/, ""), "json"],
|
783
790
|
].each do |expected_output, param|
|
784
791
|
it "#{param || "default"} output format" do
|
785
|
-
string, status = Open3.capture2e "export #{File.read("api_tokens_for_travis.sh").
|
792
|
+
string, status = Open3.capture2e "export #{(File.read("api_tokens_for_travis.sh") + File.read("vk.secret")).scan(/(?<=^export )\S+=\S+/).join(" ")} && RUBYOPT='-rbundler/setup' ./bin/directlink#{" --#{param}" if param} #{valid_imgur_image_url1} #{valid_imgur_image_url2}"
|
786
793
|
assert_equal [0, expected_output], [status.exitstatus, string]
|
787
794
|
end
|
788
795
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov aka Nakilon
|
@@ -163,9 +163,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
version: '0'
|
164
164
|
requirements:
|
165
165
|
- 'you may need to create apps and provide their API tokens:'
|
166
|
-
- IMGUR_CLIENT_ID, FLICKR_API_KEY
|
166
|
+
- IMGUR_CLIENT_ID, FLICKR_API_KEY, REDDIT_SECRETS
|
167
167
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.5.2.3
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: converts any kind of image hyperlink to direct link, type of image and its
|