directlink 0.0.9.1 → 0.0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/directlink +5 -10
- data/directlink.gemspec +13 -11
- data/lib/directlink.rb +74 -47
- data/unit.test.rb +1548 -0
- metadata +17 -40
- data/.bashrc +0 -5
- data/.travis.yml +0 -39
- data/Gemfile +0 -3
- data/README.md +0 -198
- data/Rakefile +0 -1
- data/api_tokens_for_travis.sh +0 -8
- data/gplus.txt +0 -1454
- data/reddit_token_for_travis.yaml +0 -4
- data/test.rb +0 -832
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.11.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:
|
11
|
+
date: 2021-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fastimage
|
@@ -16,56 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
31
|
+
- - "<"
|
39
32
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: nethttputils
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.4.0.0
|
33
|
+
version: '1.11'
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - "
|
38
|
+
- - "<"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
40
|
+
version: '1.11'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: reddit_bot
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
47
|
+
version: 1.10.0
|
62
48
|
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
54
|
+
version: 1.10.0
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: kramdown
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +81,7 @@ dependencies:
|
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: minitest
|
84
|
+
name: minitest-around
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - ">="
|
@@ -109,7 +95,7 @@ dependencies:
|
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
98
|
+
name: webmock
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
101
|
- - ">="
|
@@ -129,19 +115,11 @@ executables:
|
|
129
115
|
extensions: []
|
130
116
|
extra_rdoc_files: []
|
131
117
|
files:
|
132
|
-
- ".bashrc"
|
133
|
-
- ".travis.yml"
|
134
|
-
- Gemfile
|
135
118
|
- LICENSE
|
136
|
-
- README.md
|
137
|
-
- Rakefile
|
138
|
-
- api_tokens_for_travis.sh
|
139
119
|
- bin/directlink
|
140
120
|
- directlink.gemspec
|
141
|
-
- gplus.txt
|
142
121
|
- lib/directlink.rb
|
143
|
-
-
|
144
|
-
- test.rb
|
122
|
+
- unit.test.rb
|
145
123
|
homepage: https://github.com/nakilon/directlink
|
146
124
|
licenses:
|
147
125
|
- MIT
|
@@ -155,20 +133,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
133
|
requirements:
|
156
134
|
- - ">="
|
157
135
|
- !ruby/object:Gem::Version
|
158
|
-
version: '
|
136
|
+
version: '2.3'
|
159
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
138
|
requirements:
|
161
139
|
- - ">="
|
162
140
|
- !ruby/object:Gem::Version
|
163
141
|
version: '0'
|
164
142
|
requirements:
|
165
|
-
- 'you may
|
143
|
+
- 'you may want to create apps and provide API tokens:'
|
166
144
|
- IMGUR_CLIENT_ID, FLICKR_API_KEY, REDDIT_SECRETS
|
167
145
|
rubyforge_project:
|
168
146
|
rubygems_version: 2.5.2.3
|
169
147
|
signing_key:
|
170
148
|
specification_version: 4
|
171
|
-
summary:
|
172
|
-
resolution
|
149
|
+
summary: obtains from any kind of hyperlink a link to an image, its format and resolution
|
173
150
|
test_files:
|
174
|
-
- test.rb
|
151
|
+
- unit.test.rb
|
data/.bashrc
DELETED
data/.travis.yml
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
|
4
|
-
script: "source api_tokens_for_travis.sh && ruby test.rb"
|
5
|
-
|
6
|
-
os:
|
7
|
-
- linux
|
8
|
-
- osx
|
9
|
-
rvm:
|
10
|
-
- ruby-head
|
11
|
-
- 2.7
|
12
|
-
- 2.6
|
13
|
-
- 2.5
|
14
|
-
- 2.4
|
15
|
-
- 2.3
|
16
|
-
- 2.2
|
17
|
-
- 2.1
|
18
|
-
- 2.0
|
19
|
-
- jruby-head
|
20
|
-
matrix:
|
21
|
-
allow_failures:
|
22
|
-
|
23
|
-
# NetHTTPUtils does not pass query params or smth
|
24
|
-
- rvm: jruby-head
|
25
|
-
os: osx
|
26
|
-
|
27
|
-
# the 'Picked up _JAVA_OPTIONS: -Xmx2048m -Xms512m' output at jruby start ruins binstub tests
|
28
|
-
# TODO: -W0 does not help but probably there is another option or I should patch tests for jruby
|
29
|
-
- rvm: jruby-head
|
30
|
-
os: linux
|
31
|
-
|
32
|
-
# the 'The command "bundle install --jobs=3 --retry=3" failed and exited with 1 during .'
|
33
|
-
# I guess Travis is deprecating old Rubies and so will I
|
34
|
-
- rvm: 2.0
|
35
|
-
os: osx
|
36
|
-
- rvm: 2.1
|
37
|
-
os: osx
|
38
|
-
- rvm: 2.2
|
39
|
-
os: osx
|
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,198 +0,0 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/Nakilon/directlink.png?)](https://travis-ci.org/Nakilon/directlink)
|
2
|
-
![Gem Version](https://badge.fury.io/rb/directlink.png?)
|
3
|
-
|
4
|
-
# gem directlink
|
5
|
-
|
6
|
-
This tool obtains from any sort of hyperlink (a thumbnail URL, a link to a photo album, a news article, etc.) a directlink(s) to high resolution images at that page. Also it tells the resulting resolution and the image type (format). The gem also includes a binary so you can use it as a CLI.
|
7
|
-
|
8
|
-
## Usage
|
9
|
-
|
10
|
-
### As a binary
|
11
|
-
|
12
|
-
```
|
13
|
-
$ gem install directlink
|
14
|
-
```
|
15
|
-
```
|
16
|
-
$ directlink
|
17
|
-
usage: directlink [--debug] [--json] [--github] <link1> <link2> <link3> ...
|
18
|
-
```
|
19
|
-
Converts `<img src=` attribute value from any Google web service to the largest available:
|
20
|
-
```
|
21
|
-
$ directlink //4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg
|
22
|
-
<= //4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg
|
23
|
-
=> https://4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/s0/IMG_20171223_093922.jpg
|
24
|
-
jpeg 4160x3120
|
25
|
-
```
|
26
|
-
Given the link to a page it tries to find the main image on it.
|
27
|
-
```
|
28
|
-
$ directlink https://plus.google.com/107956229381790410785/posts/Gu9apRHri41
|
29
|
-
<= https://plus.google.com/107956229381790410785/posts/Gu9apRHri41
|
30
|
-
=> https://lh3.googleusercontent.com/-mRDjiHoDA30/W0mndQaRXeI/AAAAAAAAfyA/NhZGMAoQsbAb8cUFDzNWh-NXQ9O-YQhuQCJoC/s0/001
|
31
|
-
jpeg 2000x1328
|
32
|
-
```
|
33
|
-
Retrieves all images from Imgur album or gallery, orders them by resolution from high to low:
|
34
|
-
```
|
35
|
-
$ directlink https://imgur.com/a/oacI3gl
|
36
|
-
<= https://imgur.com/a/oacI3gl
|
37
|
-
=> https://i.imgur.com/QpOBvRY.png
|
38
|
-
image/png 460x460
|
39
|
-
=> https://i.imgur.com/9j4KdkJ.png
|
40
|
-
image/png 100x100
|
41
|
-
```
|
42
|
-
Follows redirects:
|
43
|
-
```
|
44
|
-
$ directlink https://goo.gl/ySqUb5
|
45
|
-
<= https://goo.gl/ySqUb5
|
46
|
-
=> https://i.imgur.com/QpOBvRY.png
|
47
|
-
image/png 460x460
|
48
|
-
```
|
49
|
-
Accepts multiple input links:
|
50
|
-
```
|
51
|
-
$ directlink https://imgur.com/a/oacI3gl https://goo.gl/ySqUb5
|
52
|
-
<= https://imgur.com/a/oacI3gl
|
53
|
-
=> https://i.imgur.com/QpOBvRY.png
|
54
|
-
image/png 460x460
|
55
|
-
=> https://i.imgur.com/9j4KdkJ.png
|
56
|
-
image/png 100x100
|
57
|
-
<= https://goo.gl/ySqUb5
|
58
|
-
=> https://i.imgur.com/QpOBvRY.png
|
59
|
-
image/png 460x460
|
60
|
-
```
|
61
|
-
Emits JSON:
|
62
|
-
```
|
63
|
-
$ directlink --json https://imgur.com/a/oacI3gl https://avatars1.githubusercontent.com/u/2870363?100
|
64
|
-
[
|
65
|
-
[
|
66
|
-
{
|
67
|
-
"url": "https://i.imgur.com/QpOBvRY.png",
|
68
|
-
"width": 460,
|
69
|
-
"height": 460,
|
70
|
-
"type": "image/png"
|
71
|
-
},
|
72
|
-
{
|
73
|
-
"url": "https://i.imgur.com/9j4KdkJ.png",
|
74
|
-
"width": 100,
|
75
|
-
"height": 100,
|
76
|
-
"type": "image/png"
|
77
|
-
}
|
78
|
-
],
|
79
|
-
{
|
80
|
-
"url": "https://avatars1.githubusercontent.com/u/2870363?100",
|
81
|
-
"width": 460,
|
82
|
-
"height": 460,
|
83
|
-
"type": "jpeg"
|
84
|
-
}
|
85
|
-
]
|
86
|
-
```
|
87
|
-
By default tries to parse the `<meta property="og:image"` tag in the "don't give up" mode but can also ignore it:
|
88
|
-
```
|
89
|
-
$ directlink --ignore-meta https://www.kp.ru/daily/26342.7/3222103/
|
90
|
-
<= https://www.kp.ru/daily/26342.7/3222103/
|
91
|
-
=> https://s11.stc.all.kpcdn.net/share/i/12/8024261/wx1080.jpg
|
92
|
-
jpeg 1080x653
|
93
|
-
=> https://s13.stc.all.kpcdn.net/share/i/12/8024233/wx1080.jpg
|
94
|
-
jpeg 1080x653
|
95
|
-
...
|
96
|
-
```
|
97
|
-
Downloads `master:HEAD` version of `lib/directlink.rb` from GitHub and uses it once instead of installed one:
|
98
|
-
```
|
99
|
-
$ directlink --github https://imgur.com/a/oacI3gl
|
100
|
-
```
|
101
|
-
When an image hosting with known API is recognized, it will try to use the API tokens you've provided as env vars (otherwise it will go the "don't give up" mode):
|
102
|
-
```
|
103
|
-
$ export IMGUR_CLIENT_ID=0f99cd781...
|
104
|
-
$ export FLICKR_API_KEY=dc2bfd348b...
|
105
|
-
$ export REDDIT_SECRETS=secrets.yaml
|
106
|
-
```
|
107
|
-
(check the format of reddit secrets file in the [reddit_bot gem dependency README](https://github.com/Nakilon/reddit_bot/#usage))
|
108
|
-
|
109
|
-
#### the "don't give up mode"
|
110
|
-
|
111
|
-
If the passed link is not the image link or a photo page of a known image hosting, the tool is still able to find the main images that the linked webpage contains. Like in the second example of this README or here -- it found three images in the markdown file:
|
112
|
-
```
|
113
|
-
$ directlink https://github.com/Nakilon/dhash-vips
|
114
|
-
<= https://github.com/Nakilon/dhash-vips
|
115
|
-
=> https://camo.githubusercontent.com/852607c7f4b604fc3c83b782c4f6983cf488b0d4/68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f64686173682d766970732e6e616b696c6f6e2e70726f2f64686173685f69737375655f6578616d706c652e706e67
|
116
|
-
png 592x366
|
117
|
-
=> https://camo.githubusercontent.com/5e354666bac69e32d605dbd45351bfb7d808924b/68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f64686173682d766970732e6e616b696c6f6e2e70726f2f6964686173685f6578616d706c655f696e2e706e67
|
118
|
-
png 773x679
|
119
|
-
=> https://camo.githubusercontent.com/5456cc20ae9b20c06792ddd19b533ae36404d8c1/68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f64686173682d766970732e6e616b696c6f6e2e70726f2f6964686173685f6578616d706c655f6f75742e706e67
|
120
|
-
png 1610x800
|
121
|
-
```
|
122
|
-
It can even find images in the Markdown body of a Reddit self post! (new feature, needs more testing)
|
123
|
-
|
124
|
-
### As a library
|
125
|
-
|
126
|
-
```
|
127
|
-
irb> require "directlink"
|
128
|
-
irb> require "pp"
|
129
|
-
|
130
|
-
irb> pp DirectLink "https://imgur.com/a/oacI3gl"
|
131
|
-
[#<struct
|
132
|
-
url="https://i.imgur.com/QpOBvRY.png",
|
133
|
-
width=460,
|
134
|
-
height=460,
|
135
|
-
type="image/png">,
|
136
|
-
#<struct
|
137
|
-
url="https://i.imgur.com/9j4KdkJ.png",
|
138
|
-
width=100,
|
139
|
-
height=100,
|
140
|
-
type="image/png">]
|
141
|
-
```
|
142
|
-
Google can serve image in arbitrary resolution so `DirectLink.google` has an optional argument to specify the desired width:
|
143
|
-
```
|
144
|
-
irb> DirectLink.google "//4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg", 100
|
145
|
-
=> "https://4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/s100/IMG_20171223_093922.jpg"
|
146
|
-
```
|
147
|
-
To disable the "don't give up" mode (otherwise it consumes time on analyzing all the images on the linked page):
|
148
|
-
```
|
149
|
-
irb> DirectLink "https://github.com/Nakilon/dhash-vips", nil, true
|
150
|
-
# raises FastImage::UnknownImageType
|
151
|
-
```
|
152
|
-
To silent the STDOUT logger that you may see sometimes:
|
153
|
-
```ruby
|
154
|
-
DirectLink.silent = true
|
155
|
-
```
|
156
|
-
You also may look into [`bin/directlink`](bin/directlink) as a library usage example and the list of all possible exceptions.
|
157
|
-
|
158
|
-
#### about long retries
|
159
|
-
|
160
|
-
Some network exceptions like `SocketError` may be not permanent (local network issues) so `NetHTTPUtils` (that resolves redirect at the beginning of `DirectLink()` call) by default retries exponentially increasing retry delay until it gets to 3600sec, but such exceptions can have permanent reasons like a canceled web domain. To see it:
|
161
|
-
```ruby
|
162
|
-
NetHTTPUtils.logger.level = Logger::WARN
|
163
|
-
```
|
164
|
-
```
|
165
|
-
W 180507 102210 : NetHTTPUtils : retrying in 10 seconds because of SocketError 'Failed to open TCP connection to minus.com:80 (getaddrinfo: nodename nor servname provided, or not known)' at: http://minus.com/
|
166
|
-
```
|
167
|
-
To make `DirectLink()` respond faster pass an optional argument that specifies the max retry delay. Here we get the exception immediately:
|
168
|
-
```ruby
|
169
|
-
DirectLink "http://minus.com/", 0
|
170
|
-
```
|
171
|
-
```
|
172
|
-
SocketError: Failed to open TCP connection to minus.com:80 (getaddrinfo: nodename nor servname provided, or not known) to http://minus.com/
|
173
|
-
```
|
174
|
-
|
175
|
-
#### Ruby 2.0
|
176
|
-
|
177
|
-
The `addressable` dependency (for proper URI parsing) has a dependency that by default wants Ruby 2.1 or higher. You may fix it safely by adding this line to your `Gemfile`:
|
178
|
-
```
|
179
|
-
gem "jwt", "<2"
|
180
|
-
```
|
181
|
-
Possibly you will instead have a problem with `kramdown` gem -- solve it the same way:
|
182
|
-
```
|
183
|
-
gem "kramdown", "<2"
|
184
|
-
```
|
185
|
-
|
186
|
-
(`<2` here has nothing to do with the Ruby version -- it's just a coincidence)
|
187
|
-
|
188
|
-
## Notes:
|
189
|
-
|
190
|
-
* `module DirectLink` public methods return different sets of properties -- `DirectLink()` unites them
|
191
|
-
* the `ErrorAssert`, `ErrorMissingEnvVar` and `URI::InvalidURIError` should never be raised and you might report it
|
192
|
-
* this gem is a historically 2 or 3 libraries merged -- this is why tests may look awkward
|
193
|
-
* 500px.com has discontinued API in June 2018 -- the tool now uses undocumented methods
|
194
|
-
* `DirectLink()` can return an Array of Structs for 1) Imgur 2) Reddit unless `giveup = true` is set
|
195
|
-
|
196
|
-
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
|
197
|
-
TODO: what should `--json` print if exception was thrown?
|
198
|
-
TODO: looped prompt mode
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
data/api_tokens_for_travis.sh
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
export IMGUR_CLIENT_ID=0f99cd781c9d0d8
|
2
|
-
export FLICKR_API_KEY=dc2bfd348b01bdc5b09d36876dc38f3d
|
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
|