directlink 0.0.5.0 → 0.0.6.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/README.md +3 -2
- data/directlink.gemspec +1 -1
- data/lib/directlink.rb +5 -4
- data/test.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09afa7efc0cf49f2742c257d2aa0c0810ed5e888'
|
4
|
+
data.tar.gz: 2241c093814a7f3b2e75dcf44ab7c75d79752013
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bb2f434417735a0bbc9526aa2c632b6fe50bb326e5db74b8d86f8cc700ff42f99387a2058b53c7b6bddcab198129718f2412810fb1e403fdd5e14bd2d42bc16
|
7
|
+
data.tar.gz: f40c51e45aadee4af3ec6d2244d9dc6209ddb7d3f22cb8ecefea2d017e1b8861dfad3cc39b52851b112ea6a69e017cc4a9e4b7491c1822794ac9e655531bfbe0
|
data/README.md
CHANGED
@@ -173,15 +173,16 @@ Possibly you will instead have a problem with `kramdown` gem -- solve it the sam
|
|
173
173
|
gem "kramdown", "<2"
|
174
174
|
```
|
175
175
|
|
176
|
+
(`<2` here has nothing to do with the Ruby version -- it's just a coincidence)
|
177
|
+
|
176
178
|
## Notes:
|
177
179
|
|
178
180
|
* `module DirectLink` public methods return different sets of properties -- `DirectLink()` unites them
|
179
181
|
* the `ErrorAssert`, `ErrorMissingEnvVar` and `URI::InvalidURIError` should never be raised and you might report it
|
180
|
-
* style: `@@` and lambdas are used to keep things private
|
181
182
|
* this gem is a historically 2 or 3 libraries merged -- this is why tests may look awkward
|
182
183
|
* 500px.com has discontinued API in June 2018 -- the tool now uses undocumented methods
|
183
184
|
* `DirectLink()` can return an Array of Structs for 1) Imgur 2) Reddit unless `giveup = true` is set
|
184
185
|
|
185
186
|
TODO: maybe make all these web service specific methods private and discourage to use them since they all return very different things and sometimes don't raise exceptions while the `DirectLink()` does
|
186
|
-
TODO: what should `--json` print if exception was thrown?
|
187
|
+
TODO: what should `--json` print if exception was thrown?
|
187
188
|
TODO: looped prompt mode
|
data/directlink.gemspec
CHANGED
data/lib/directlink.rb
CHANGED
@@ -355,6 +355,9 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup = false
|
|
355
355
|
else ; raise
|
356
356
|
end
|
357
357
|
html = Nokogiri::HTML NetHTTPUtils.request_data link, header: {"User-Agent" => "Mozilla"}
|
358
|
+
if t = html.at_css("meta[@property='og:image']")
|
359
|
+
return DirectLink t[:content], nil, true
|
360
|
+
end
|
358
361
|
h = {} # TODO: maybe move it outside because of possible img[:src] recursion?...
|
359
362
|
l = lambda do |node, s = []|
|
360
363
|
node.element_children.flat_map do |child|
|
@@ -367,10 +370,8 @@ def DirectLink link, max_redirect_resolving_retry_delay = nil, giveup = false
|
|
367
370
|
end
|
368
371
|
end
|
369
372
|
end
|
370
|
-
l[html].group_by(&:first).map{ |k, v| [k.join(?>), v.map(&:last)] }.tap do |
|
371
|
-
|
372
|
-
raise unless t = html.at_css("meta[@property='og:image']")
|
373
|
-
return DirectLink t[:content], nil, true
|
373
|
+
l[html].group_by(&:first).map{ |k, v| [k.join(?>), v.map(&:last)] }.tap do |results|
|
374
|
+
raise if results.empty?
|
374
375
|
end.max_by{ |_, v| v.map{ |i| i.width * i.height }.inject(:+) / v.size }.last
|
375
376
|
else
|
376
377
|
# TODO: maybe move this to right before `rescue` line
|
data/test.rb
CHANGED
@@ -367,9 +367,9 @@ describe DirectLink do
|
|
367
367
|
[ :flickr, [
|
368
368
|
["https://www.flickr.com/photos/tomas-/17220613278/", DirectLink::ErrorNotFound],
|
369
369
|
["https://www.flickr.com/photos/16936123@N07/18835195572", DirectLink::ErrorNotFound],
|
370
|
-
["https://www.flickr.com/photos/44133687@N00/17380073505/", [3000, 2000, "https://
|
370
|
+
["https://www.flickr.com/photos/44133687@N00/17380073505/", [3000, 2000, "https://live.staticflickr.com/7757/17380073505_ed5178cc6a_o.jpg"]], # trailing slash
|
371
371
|
["https://www.flickr.com/photos/jacob_schmidt/18414267018/in/album-72157654235845651/", DirectLink::ErrorNotFound], # username in-album
|
372
|
-
["https://www.flickr.com/photos/tommygi/5291099420/in/dateposted-public/", [1600, 1062, "https://
|
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
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
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"]],
|
@@ -653,12 +653,12 @@ describe DirectLink do
|
|
653
653
|
describe "giving up" do
|
654
654
|
[
|
655
655
|
["http://example.com", FastImage::UnknownImageType],
|
656
|
-
["https://
|
657
|
-
["https://
|
656
|
+
["https://www.tic.com/index.html", FastImage::UnknownImageType, true],
|
657
|
+
["https://www.tic.com/index.html", 2],
|
658
658
|
["http://imgur.com/HQHBBBD", FastImage::UnknownImageType, true],
|
659
659
|
["http://imgur.com/HQHBBBD", "https://i.imgur.com/HQHBBBD.jpg?fb"], # .at_css("meta[@property='og:image']")
|
660
|
-
["
|
661
|
-
["
|
660
|
+
["https://www.deviantart.com/nadyasonika/art/Asuka-Langley-Beach-Time-590134861", FastImage::UnknownImageType, true],
|
661
|
+
["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"],
|
662
662
|
].each_with_index do |(input, expectation, giveup), i|
|
663
663
|
it "##{i + 1} (#{URI(input).host}) (giveup=#{!!giveup})" do # to match with minitest `-n` run flag
|
664
664
|
ti = ENV.delete "IMGUR_CLIENT_ID"
|
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.
|
4
|
+
version: 0.0.6.0
|
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-
|
11
|
+
date: 2019-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fastimage
|