directlink 0.0.1.2 → 0.0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a8470c30310de349800459f325c2d244075fba2
4
- data.tar.gz: fe0a118c8bb52d675325ce8d3356bb8fa7ca936f
3
+ metadata.gz: 94ddd6c7b855b36aa7ae7fe49b98fb7c6bb87f08
4
+ data.tar.gz: 968b1fed9d2478f945b66cc0fccee78f31710ba5
5
5
  SHA512:
6
- metadata.gz: 60db6a81f31ba3a0425db1bf74d6719e852a6710fb716a081817ae9eaa8482f923b1ec1a5cb5f9dbf1d265e3599807c090a0e949e53ab568def36af7c6ffb53f
7
- data.tar.gz: 693fab788a1c312f3cf42843e5029d4f40db50127da55034160ff9a607ac4002a57371632df3b24e0aa82f4ce1aaf4d5f00e83cd0589ff6f573ced8fab28b7c1
6
+ metadata.gz: e44e1eacf06235a1eda481e0ca0e521504327a6631f88953c1aeb4b412b2d7b445417556c3595143afb6fa48e348b8a37b365162acbd812fe8a775ce939fc53a
7
+ data.tar.gz: e8d3360b8e1686d71b33d2231114865693e314f44f5d191a7fe1bd9052776798dcfa37c7d98ff01f59429ce00523bb3ebfc7970a8069d9df6a45f4984fe48569
data/README.md CHANGED
@@ -1,22 +1,23 @@
1
1
  [![Build Status](https://travis-ci.org/Nakilon/directlink.png?)](https://travis-ci.org/Nakilon/directlink)
2
2
  ![Gem Version](https://badge.fury.io/rb/directlink.png?)
3
3
 
4
+ # gem directlink
5
+
6
+ This tool can convert a thumbnail URL to a high resolution image URL for several popular image hostings. Also it tells the resulting resolution and the image type (format). I wanted such automation often so finally I've decided to make a gem with a binary.
7
+
4
8
  ## Usage
5
9
 
6
- ### As binary
10
+ ### As a binary
7
11
 
8
12
  ```
9
13
  $ gem install directlink
10
- $ directlink
11
- usage: directlink [--debug] [--json] <link1> <link2> <link3> ...
12
14
  ```
13
- When known image hosting that has handy API is recognized, the API will be used and you'll have to create app there and provide env vars:
14
15
  ```
15
- $ export IMGUR_CLIENT_ID=0f99cd781...
16
- $ export FLICKR_API_KEY=dc2bfd348b...
17
- $ export _500PX_CONSUMER_KEY=ESkHT...
16
+ $ directlink
17
+ usage: directlink [--debug] [--json] [--github] <link1> <link2> <link3> ...
18
18
  ```
19
- Converts `<img src=` attribute value from any Google web service to its high resolution version:
19
+ Converts `<img src=` attribute value from any (current regexes are very strict and are going to fail -- it is a [defensive programming](https://en.wikipedia.org/wiki/Defensive_programming) practice
20
+ ) Google web service to its high resolution version:
20
21
  ```
21
22
  $ directlink //4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg
22
23
  <= //4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg
@@ -79,10 +80,16 @@ $ directlink --json https://imgur.com/a/oacI3gl https://avatars1.githubuserconte
79
80
  ```
80
81
  Downloads master:HEAD version of `lib/directlink.rb` from GitHub and uses it once instead of installed one (this is easier than installing gem from repo):
81
82
  ```
82
- $ directlink --github <url>
83
+ $ directlink --github https://imgur.com/a/oacI3gl
84
+ ```
85
+ When known image hosting that has handy API is recognized, the API will be used and you'll have to create app there and provide env vars:
86
+ ```
87
+ $ export IMGUR_CLIENT_ID=0f99cd781...
88
+ $ export FLICKR_API_KEY=dc2bfd348b...
89
+ $ export _500PX_CONSUMER_KEY=ESkHT...
83
90
  ```
84
91
 
85
- ### As library
92
+ ### As a library
86
93
 
87
94
  ```
88
95
  irb> require "directlink"
@@ -99,16 +106,8 @@ irb> pp DirectLink "https://imgur.com/a/oacI3gl"
99
106
  width=100,
100
107
  height=100,
101
108
  type="image/png">]
102
-
103
- irb> pp DirectLink "//4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg"
104
- #<struct
105
- url=
106
- "https://4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/s0/IMG_20171223_093922.jpg",
107
- width=4160,
108
- height=3120,
109
- type=:jpeg>
110
109
  ```
111
- Google can serve image in arbitrary resolution so `DirectLink.google` has optional argument to specify the width:
110
+ Google can serve image in arbitrary resolution so `DirectLink.google` has optional argument to specify the desired width:
112
111
  ```
113
112
  irb> DirectLink.google "//4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg", 100
114
113
  => "https://4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/s100/IMG_20171223_093922.jpg"
@@ -120,7 +119,7 @@ DirectLink.silent = true
120
119
 
121
120
  #### about slow retries
122
121
 
123
- 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 for reasons like canceled web domain. To see it:
122
+ 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:
124
123
  ```ruby
125
124
  NetHTTPUtils.logger.level = Logger::WARN
126
125
  ```
@@ -139,6 +138,7 @@ SocketError: Failed to open TCP connection to minus.com:80 (getaddrinfo: nodenam
139
138
 
140
139
  * `module DirectLink` public methods return different sets of properties -- `DirectLink()` unites them
141
140
  * the `DirectLink::ErrorAssert` should never happen and you might report it if it does
142
- * style: `@@` and lambdas are used to keep things private
143
141
  * style: all exceptions should be classified as `DirectLink::Error*` or `FastImage::*`
144
- * this gem is a 2 or 3 libraries united so don't expect tests to be full and consistent
142
+ * style: `@@` and lambdas are used to keep things private
143
+ * resolution of 500px.com photo is that you get via Pro membership, not that image by URL really has
144
+ * this gem is a 2 or 3 libraries merged so don't expect tests to be full and consistent
data/bin/directlink CHANGED
@@ -43,7 +43,7 @@ else
43
43
  require "directlink"
44
44
  end
45
45
  DirectLink.silent = !debug
46
- abort "usage: directlink [--debug] [--json] <link1> <link2> <link3> ...\n#{
46
+ abort "usage: directlink [--debug] [--json] [--github] <link1> <link2> <link3> ...\n#{
47
47
  if github
48
48
  "impossible to tell version for sure from raw.githubusercontent.com"
49
49
  else
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.1.2"
3
+ spec.version = "0.0.1.3"
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
@@ -34,6 +34,7 @@ module DirectLink
34
34
 
35
35
  def self.google src, width = 0
36
36
  case src
37
+ # Google Plus post image
37
38
  when /\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_-]{11}\/W[n-r][a-zA-Z0-9_-]{8}I\/AAAAAAAA[bA-V][a-zA-Z0-9]{2}\/[a-zA-Z0-9_-]{32}[gwAQ]CJoC\/)w[1-4]\d\d-h(318|353|727)-n(\/[^\/]+)\z/,
38
39
  /\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9_-]{11}\/W[a-zA-Z0-9_-]{9}I\/AAAAAAA[a-zA-Z0-9_-]{4}\/[a-zA-Z0-9_-]{33}(?:CJoC|CL0B(?:GAs)?)\/)w530(?:-d)?-h[2-9]\d\d-n(\/[^\/]+)\z/
39
40
  "#{$1}s#{width}#{$2}"
@@ -42,6 +43,15 @@ module DirectLink
42
43
  when /\A(\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9-]{11}\/W[a-zA-Z0-9_-]{9}I\/AAAAAAA[AC][a-zA-Z0-9]{3}\/[a-zA-Z0-9_-]{32}[gw]CJoC\/)w530-h3\d\d-p(\/[^\/]+)\z/,
43
44
  /\A(\/\/[14]\.bp\.blogspot\.com\/-[a-zA-Z0-9_-]{11}\/W[np][a-zA-Z0-9_-]{8}I\/AAAAAAAA[DE][a-zA-Z0-9_-]{2}\/[a-zA-Z0-9_-]{33}C(?:Lc|Kg)BGAs\/)w530-h278-p(\/[^\/]+)\z/
44
45
  "https:#{$1}s#{width}#{$2}"
46
+ # Google Plus userpic
47
+ when /\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9-]{11}\/AAAAAAAAAAI\/AAAAAAAA[a-zA-Z0-9]{3}\/[a-zA-Z0-9_-]{11}\/)s\d\d-p(?:-k)?-rw-no(\/photo\.jpg)\z/
48
+ "#{$1}s#{width}#{$2}"
49
+ # Hangout userpic
50
+ when /\A(https:\/\/lh5\.googleusercontent\.com\/-[a-zA-Z]{11}\/AAAAAAAAAAI\/AAAAAAAAAAA\/[a-zA-Z0-9]{11}\/)s64-c-k(\/photo\.jpg)\z/,
51
+ /\A(https:\/\/lh[35]\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/AAAAAAAAAAI\/AAAAAAAA[a-zA-Z0-9]{3}\/[a-zA-Z0-9-]{11}\/)s\d\d-c-k-no(\/photo\.jpg)\z/,
52
+ /\A(https:\/\/lh3\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/AAAAAAAAAAI\/AAAAAAAAAAA\/[a-zA-Z0-9]{34}\/)s64-c-mo(\/photo\.jpg)\z/,
53
+ /\A(https:\/\/lh6\.googleusercontent\.com\/-[a-zA-Z0-9]{11}\/AAAAAAAAAAI\/AAAAAAAAAAA\/[a-zA-Z0-9_]{34}\/)s46-c-k-no-mo(\/photo\.jpg)\z/
54
+ "#{$1}s#{width}#{$2}"
45
55
  else
46
56
  raise ErrorBadLink.new src
47
57
  end
data/test.rb CHANGED
@@ -43,9 +43,31 @@ describe DirectLink do
43
43
  783 https://lh3.googleusercontent.com/-SqAvt_F__bg/Wq0huHcX2NI/AAAAAAAAVj0/XfnwCU7JwhUh0Knw8rcXA-bhpKYkI4hdwCJoC/w358-h318-n/IMG_20180317_120218-01-01.jpeg
44
44
  830 https://lh3.googleusercontent.com/-VB3YlLVL_tQ/Wo21yTbKl_I/AAAAAAAAApU/3DURmsYBklcv0kif2ZRjhoLG4mTHYf8OwCJoC/w254-h318-n/180218_00001.jpg
45
45
  1002 https://lh3.googleusercontent.com/-d8FkfLWq-_4/WpQXzEfFgBI/AAAAAAAADww/J32xKSAYUkgIc3pyrZnNmRec6kjdnJBHgCJoC/w239-h318-n/gplus-485739203.jpg
46
- ".scan(/(\S+) (\S+)/).each do |i, url|
47
- it "##{i}" do
48
- assert_kind_of String, DirectLink.google(url)
46
+ ".scan(/(\S+) (\S+)/).each do |i, link|
47
+ it "Google Plus post image ##{i}" do
48
+ DirectLink.google link
49
+ end
50
+ end
51
+ %w{
52
+ 0 https://lh3.googleusercontent.com/-okfI8E6JAgg/AAAAAAAAAAI/AAAAAAAAZa0/FEv9H8woCBg/s30-p-rw-no/photo.jpg
53
+ 7 https://lh3.googleusercontent.com/-okfI8E6JAgg/AAAAAAAAAAI/AAAAAAAAZa0/FEv9H8woCBg/s75-p-rw-no/photo.jpg
54
+ _ https://lh3.googleusercontent.com/-bhgxgLsFYWI/AAAAAAAAAAI/AAAAAAAA4MI/_KuKE-Goa7E/s35-p-k-rw-no/photo.jpg
55
+ - https://lh3.googleusercontent.com/-tl9-AdHhGiY/AAAAAAAAAAI/AAAAAAAA8uY/vVeZX8SbTXI/s35-p-k-rw-no/photo.jpg
56
+ 4 https://lh3.googleusercontent.com/-Rb833O10RB4/AAAAAAAAAAI/AAAAAAAAEJc/DawCLQGnaSA/s45-p-k-rw-no/photo.jpg
57
+ }.each_slice 2 do |i, link|
58
+ it "Google Plus userpic #{i}" do
59
+ DirectLink.google link
60
+ end
61
+ end
62
+ %w{
63
+ - https://lh3.googleusercontent.com/-10bBuroWuoU/AAAAAAAAAAI/AAAAAAAAl90/ed314-fNMGg/s20-c-k-no/photo.jpg
64
+ just https://lh5.googleusercontent.com/-RT6j6oYpZzU/AAAAAAAAAAI/AAAAAAAAAO4/WISrqFs1vT8/s46-c-k-no/photo.jpg
65
+ no-no https://lh5.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/s64-c-k/photo.jpg
66
+ no-k-no https://lh3.googleusercontent.com/-okfI8E6JAgg/AAAAAAAAAAI/AAAAAAAAAAA/AIcfdXD1lA9yGoSbsihWmGfnl6Z3Rn43WA/s64-c-mo/photo.jpg
67
+ _ https://lh6.googleusercontent.com/-BQEbGrPRFk4/AAAAAAAAAAI/AAAAAAAAAAA/AIcfdXDBweE5VzGGy4zMraO_pqiLuFN3yQ/s46-c-k-no-mo/photo.jpg
68
+ }.each_slice 2 do |i, link|
69
+ it "Hangout userpic #{i}" do
70
+ DirectLink.google link
49
71
  end
50
72
  end
51
73
  end
@@ -185,9 +207,7 @@ describe DirectLink do
185
207
  {
186
208
  google: %w{
187
209
  https://lh3.googleusercontent.com/-NVJgqmI_2Is/WqMM2OMYg-I/AAAAAAAALrk/5-p3JL3iZt0Ho9dOf_p3gpddzqwr3Wp0ACJoC/w424-h318-n/001
188
- https://lh3.googleusercontent.com/-2JzV0ErXvv8/Wsdr-m5Q_aI/AAAAAAAA_-I/Lw_e6qEMPUck4yW9yWhkC-nBNd5em8c3QCJoC/w530-h795-n/888052_800n.jpg
189
210
  //lh3.googleusercontent.com/proxy/DZtTi5KL7PqiBwJc8weNGLk_Wi2UTaQH0AC_h2kuURiu0AbwyI2ywOk2XgdAjL7ceg=w530-h354-n
190
- //lh3.googleusercontent.com/-h1siEcRFqJ8/Wiv1iDQhNVI/AAAAAAAAQV4/9gGepSmYkDMLyVTG_1EBCMmj-UhmclXWwCJoC/w530-h353-p/001
191
211
  //1.bp.blogspot.com/-rYk_u-qROQc/WngolJ8M0LI/AAAAAAAAD-w/woivnaIVzasBPG5C2T1t-VrWKRd_U6lMgCLcBGAs/w530-h278-p/i-469.jpg
192
212
  },
193
213
  imgur: %w{
@@ -304,11 +324,11 @@ describe DirectLink do
304
324
 
305
325
  describe "shows usage help if misused" do
306
326
  [
307
- [/\Ausage: directlink \[--debug\] \[--json\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, nil],
308
- [/\Ausage: directlink \[--debug\] \[--json\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "-h"],
309
- [/\Ausage: directlink \[--debug\] \[--json\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "--help"],
310
- [/\Ausage: directlink \[--debug\] \[--json\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "-v"],
311
- [/\Ausage: directlink \[--debug\] \[--json\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "--version"],
327
+ [/\Ausage: directlink \[--debug\] \[--json\] \[--github\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, nil],
328
+ [/\Ausage: directlink \[--debug\] \[--json\] \[--github\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "-h"],
329
+ [/\Ausage: directlink \[--debug\] \[--json\] \[--github\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "--help"],
330
+ [/\Ausage: directlink \[--debug\] \[--json\] \[--github\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "-v"],
331
+ [/\Ausage: directlink \[--debug\] \[--json\] \[--github\] <link1> <link2> <link3> \.\.\.\ndirectlink version \d\.\d\.\d\.\d \(https:\/\/github\.com\/nakilon\/directlink\)\n\z/, "--version"],
312
332
  ["DirectLink::ErrorBadLink: \"--\"\n", "--"],
313
333
  ["DirectLink::ErrorBadLink: \"-\"\n", "-"],
314
334
  ["DirectLink::ErrorBadLink: \"-\"\n", "- -"],
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.1.2
4
+ version: 0.0.1.3
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: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2018-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nethttputils