directlink 0.0.8.3 → 0.0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/directlink.gemspec +2 -2
- data/lib/directlink.rb +5 -10
- data/test.rb +6 -4
- 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: 2f42b5eafdc2cffee78b290dd2b2873863da1f17
|
4
|
+
data.tar.gz: edda6ebe3c54923788d5ead6591896a26d0601fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3e0f61364cce617a0bcc7f1ffa03ff2b94f459c80b368a3395596a17015c04217dfeee31d31b8f416f76f88ee80851084e55a6fc1180725f128ac874bc8fbde
|
7
|
+
data.tar.gz: 07e69d129b074449d3dcc52d187dc9e163fc70bbaabf2a5bbd319127a6447c13408f75b3d8528be8fb1974b8f9b21904a09b13fff301311fd7dfa99070a5f335
|
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.8.
|
3
|
+
spec.version = "0.0.8.4"
|
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.3.
|
14
|
+
spec.add_dependency "nethttputils", "~>0.3.3.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
@@ -141,14 +141,7 @@ module DirectLink
|
|
141
141
|
require "nokogiri"
|
142
142
|
resp = NetHTTPUtils.request_data link
|
143
143
|
f = lambda do |form|
|
144
|
-
JSON.load(
|
145
|
-
NetHTTPUtils.request_data "https://api.500px.com/v1/photos",
|
146
|
-
form: form,
|
147
|
-
header: {
|
148
|
-
"Cookie" => resp.instance_variable_get(:@last_response).to_hash.fetch("set-cookie").join(?\s),
|
149
|
-
"X-CSRF-Token" => Nokogiri::HTML(resp).at_css("[name=csrf-token]")[:content]
|
150
|
-
}
|
151
|
-
).fetch("photos").values.first
|
144
|
+
JSON.load(NetHTTPUtils.request_data "https://api.500px.com/v1/photos", form: form).fetch("photos").values.first
|
152
145
|
end
|
153
146
|
w, h = f[{"ids" => id }].values_at("width", "height")
|
154
147
|
# we need the above request to find the real resolution otherwise the "url" in the next request will be wrong
|
@@ -244,10 +237,11 @@ module DirectLink
|
|
244
237
|
def self.vk link
|
245
238
|
id, mtd, field, f = case link
|
246
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
|
+
%r{\Ahttps://vk\.com/[a-z_]+\?z=photo(?<_>)(?<id>(?<user_id>\d+)_\d+)%2Fphotos\k<user_id>\z},
|
247
241
|
%r{\Ahttps://vk\.com/photo(?<_>)(?<id>-?\d+_\d+)(\?all=1)?\z},
|
248
242
|
%r{\Ahttps://vk\.com/feed\?section=likes&z=photo(?<_>)(?<id>-(?<user_id>\d+)_\d+)%2F(liked\d+|album\k<user_id>_0)\z},
|
249
|
-
%r{\Ahttps://vk\.com/[a-
|
250
|
-
%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
|
243
|
+
%r{\Ahttps://vk\.com/[a-z_]+\?z=photo(?<_>)(?<id>(?<user_id>-\d+)_\d+)%2F(wall\k<user_id>_\d+|album\k<user_id>_0)\z},
|
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}
|
251
245
|
[$2, :photos, :photos, lambda do |t|
|
252
246
|
raise ErrorAssert.new "our knowledge about VK API seems to be outdated" unless 1 == t.size
|
253
247
|
t.first
|
@@ -264,6 +258,7 @@ module DirectLink
|
|
264
258
|
raise ErrorBadLink.new link
|
265
259
|
end
|
266
260
|
raise ErrorMissingEnvVar.new "define VK_ACCESS_TOKEN and VK_CLIENT_SECRET env vars" unless ENV["VK_ACCESS_TOKEN"] && ENV["VK_CLIENT_SECRET"]
|
261
|
+
sleep 0.25 # "error_msg"=>"Too many requests per second"
|
267
262
|
f.call( JSON.load( NetHTTPUtils.request_data "https://api.vk.com/method/#{mtd}.getById",
|
268
263
|
:POST, form: { field => id, :access_token => ENV["VK_ACCESS_TOKEN"], :client_secret => ENV["VK_CLIENT_SECRET"], :v => "5.101" }
|
269
264
|
).fetch("response") ).fetch("sizes").map do |s|
|
data/test.rb
CHANGED
@@ -372,7 +372,7 @@ describe DirectLink do
|
|
372
372
|
["https://www.flickr.com/photos/tommygi/5291099420/in/dateposted-public/", [1600, 1062, "https://live.staticflickr.com/5249/5291099420_29fae96e38_h.jpg"]], # username in-public
|
373
373
|
["https://www.flickr.com/photos/132249412@N02/18593786659/in/album-72157654521569061/", DirectLink::ErrorNotFound],
|
374
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", [
|
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", [4096, 2723, "https://live.staticflickr.com/2499/3778768209_dfa75a41cc_4k.jpg"]],
|
376
376
|
["https://www.flickr.com/photos/patricksloan/18230541413/sizes/l", [2048, 491, "https://live.staticflickr.com/5572/18230541413_fec4783d79_k.jpg"]],
|
377
377
|
["https://flic.kr/p/vPvCWJ", [2048, 1365, "https://live.staticflickr.com/507/19572004110_d44d1b4ead_k.jpg"]],
|
378
378
|
] ],
|
@@ -404,8 +404,10 @@ describe DirectLink do
|
|
404
404
|
["https://vk.com/id2272074?z=photo2272074_264578776%2Fphotos2272074", [604, 484, "https://sun9-10.userapi.com/c10472/u2272074/-7/x_407b2ba2.jpg"]],
|
405
405
|
["https://vk.com/feed?section=likes&z=photo-117564754_456261460%2Fliked3902406", [1024, 1335, "https://sun9-72.userapi.com/c854028/v854028353/895b6/izQJresLdf0.jpg"]],
|
406
406
|
["https://vk.com/likizimy?z=photo-42543351_456239941%2Fwall-42543351_1908", [1179, 1731, "https://sun9-47.userapi.com/c855036/v855036571/60f7b/ryCPJIMyMkI.jpg"]],
|
407
|
+
["https://vk.com/e_rod?z=photo298742340_457247118%2Fphotos298742340", [1728, 2160, "https://sun9-53.userapi.com/c858320/v858320596/c7714/oImGe4o1ZJI.jpg"]],
|
407
408
|
] ],
|
408
409
|
].each do |method, tests|
|
410
|
+
next if method == :vk && ENV.include?("TRAVIS")
|
409
411
|
describe method do
|
410
412
|
tests.each_with_index do |(input, expectation), i|
|
411
413
|
it "#{method} ##{i + 1}" do
|
@@ -438,9 +440,9 @@ describe DirectLink do
|
|
438
440
|
["https://www.imgur.com/3eThW", "https://imgur.com/3eThW"],
|
439
441
|
["https://goo.gl/ySqUb5", "https://i.imgur.com/QpOBvRY.png"],
|
440
442
|
],
|
441
|
-
_500px:
|
442
|
-
https://500px.com/photo/112134597/milky-way-by-tom-hall
|
443
|
-
|
443
|
+
_500px: [
|
444
|
+
%w{ https://500px.com/photo/112134597/milky-way-by-tom-hall https://web.500px.com/photo/112134597/milky-way-by-tom-hall? },
|
445
|
+
],
|
444
446
|
flickr: [
|
445
447
|
"https://www.flickr.com/photos/59880970@N07/15773941043/in/dateposted-public/",
|
446
448
|
["https://flic.kr/p/vPvCWJ", "https://www.flickr.com/photos/mlopezphotography/19572004110/"],
|
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
|
+
version: 0.0.8.4
|
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
|
+
date: 2019-11-08 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.3.
|
47
|
+
version: 0.3.3.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.3.
|
54
|
+
version: 0.3.3.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: reddit_bot
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|