directlink 0.0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb0c1733a9087846c343a6b85d07175868e481a3
4
+ data.tar.gz: fc43c2e7124eab4b2780d0664251e8dfcbbf520a
5
+ SHA512:
6
+ metadata.gz: ae8974d44eca18e9c1718e9b5b2ab723ad522afec45e7bf7c96730acaeb6cb09c858d8c4d85645c51629e9d43b8b5752bfdf4edd9b33a5adb81f5add10fe33c4
7
+ data.tar.gz: 9367fb91716eecc451ecba7111d8c876f95a3e3d989964ab34c3137e1c2d1321813e2c98e4c879c72a95ae56ee41cc178d85dd66b9cdf237ddedf412ee74dfe2
data/.travis.yml ADDED
@@ -0,0 +1,26 @@
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.5
12
+ - 2.4
13
+ - 2.3
14
+ - 2.2
15
+ - 2.1
16
+ - 2.0
17
+ - jruby-head
18
+ matrix:
19
+ allow_failures:
20
+ # NetHTTPUtils does not pass query params or smth
21
+ - rvm: jruby-head
22
+ os: osx
23
+ # the "Picked up _JAVA_OPTIONS: -Xmx2048m -Xms512m" output at jruby start ruins binstub tests
24
+ # TODO: -W0 does not help but probably there is another option or I should patch tests for jruby
25
+ - rvm: jruby-head
26
+ os: linux
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Victor Maslov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
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
+ ## Usage:
5
+ ```
6
+ $ directlink
7
+ usage: directlink [--debug] [--json] <link1> <link2> <link3> ...
8
+ ```
9
+ Converts `<img src=` attribute value from any Google web service to its high resolution version:
10
+ ```
11
+ $ directlink //4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/w530-h278-p/IMG_20171223_093922.jpg
12
+ https://4.bp.blogspot.com/-5kP8ndL0kuM/Wpt82UCqvmI/AAAAAAAAEjI/ZbbZWs0-kgwRXEJ9JEGioR0bm6U8MOkvQCKgBGAs/s0/IMG_20171223_093922.jpg
13
+ jpeg 4160x3120
14
+ ```
15
+ Retrieves all images from Imgur album or gallery, orders them by resolution from high to low:
16
+ ```
17
+ $ directlink https://imgur.com/a/oacI3gl
18
+ https://i.imgur.com/QpOBvRY.png
19
+ image/png 460x460
20
+ https://i.imgur.com/9j4KdkJ.png
21
+ image/png 100x100
22
+ ```
23
+ Accepts multiple input links:
24
+ ```
25
+ $ directlink https://imgur.com/a/oacI3gl https://avatars1.githubusercontent.com/u/2870363?100
26
+ https://i.imgur.com/QpOBvRY.png
27
+ image/png 460x460
28
+ https://i.imgur.com/9j4KdkJ.png
29
+ image/png 100x100
30
+
31
+ https://avatars1.githubusercontent.com/u/2870363?100
32
+ jpeg 460x460
33
+ ```
34
+ Emits JSON:
35
+ ```
36
+ $ directlink --json https://imgur.com/a/oacI3gl https://avatars1.githubusercontent.com/u/2870363?100
37
+ [
38
+ [
39
+ {
40
+ "url": "https://i.imgur.com/QpOBvRY.png",
41
+ "width": 460,
42
+ "height": 460,
43
+ "type": "image/png"
44
+ },
45
+ {
46
+ "url": "https://i.imgur.com/9j4KdkJ.png",
47
+ "width": 100,
48
+ "height": 100,
49
+ "type": "image/png"
50
+ }
51
+ ],
52
+ {
53
+ "url": "https://avatars1.githubusercontent.com/u/2870363?100",
54
+ "width": 460,
55
+ "height": 460,
56
+ "type": "jpeg"
57
+ }
58
+ ]
59
+ ```
60
+
61
+ ## Notes:
62
+ * use `DirectLink.silent = true` to supress the logger -- it is used only by `DirectLink::Imgur` yet
63
+ * methods inside `DirectLink` by design return different sets of properties -- DirectLink unites them
64
+ * methods may have arguments (`width=` in `google`) so they are public for external usage
65
+ * this gem is a 2 or 3 libraries united so don't expect tests to be full and consistent
66
+ * when known image hosting is recognized, the API will be used and you'll have to provide env vars:
67
+ `IMGUR_CLIENT_ID` or `FLICKR_API_KEY` or `_500PX_CONSUMER_KEY`
68
+ * the `DirectLink::ErrorAssert` should never happen and you might report it if it does
69
+ * style: `@@` and lambdas are used to keep things private
70
+ * style: all exceptions should be classified as `DirectLink::Error*` or `FastImage::*`
71
+ * we don't pass user input to `NetHTTPUtils` -- we contribute to gem FastImage and expect it to raise
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ export IMGUR_CLIENT_ID=0f99cd781c9d0d8
2
+ export FLICKR_API_KEY=dc2bfd348b01bdc5b09d36876dc38f3d
3
+ export _500PX_CONSUMER_KEY=ESkHTUELdcE48bezGfwzSjqVIBVTnNRIPTviTGLv
data/bin/directlink ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby -W0
2
+
3
+ # "-W0" is against Fastimage's "warning: already initialized constant URI::DEFAULT_PARSER" on Ruby 2.0 and 2.1
4
+ # that ruins binstub tests
5
+
6
+ Signal.trap :INT do
7
+ abort "\n(interrupted by SIGINT)"
8
+ end
9
+
10
+
11
+
12
+ require "directlink"
13
+ DirectLink.silent = true
14
+
15
+ # TODO: use OptionParser
16
+ debug = json = nil
17
+ loop do
18
+ case ARGV.first
19
+ when "--debug"
20
+ debug = ARGV.shift
21
+ DirectLink.silent = false
22
+ when "--json"
23
+ json = ARGV.shift
24
+ else
25
+ break
26
+ end
27
+ end
28
+ abort "usage: directlink [--debug] [--json] <link1> <link2> <link3> ..." if [nil, "-h", "--help"].include? ARGV.first
29
+
30
+ begin
31
+ if json
32
+ require "json"
33
+ t = ARGV.map do |link|
34
+ t = DirectLink link
35
+ t.is_a?(Array) ? t.map(&:to_h) : t.to_h
36
+ end
37
+ puts JSON.pretty_generate t.size == 1 ? t.first : t
38
+ else
39
+ puts( ARGV.map do |link|
40
+ t = DirectLink link
41
+ (t.is_a?(Array) ? t : [t]).map{ |s| "#{s.url}\n#{s.type} #{s.width}x#{s.height}" }.join("\n")
42
+ end.join "\n\n" )
43
+ end
44
+ rescue FastImage::UnknownImageType,
45
+ FastImage::ImageFetchFailure,
46
+ DirectLink::ErrorMissingEnvVar,
47
+ DirectLink::ErrorAssert,
48
+ DirectLink::ErrorNotFound,
49
+ DirectLink::ErrorBadLink => e
50
+ puts e.backtrace if debug
51
+ c = e.class.to_s
52
+ abort c == e.to_s ? c : "#{c}: #{e}"
53
+ end
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "directlink"
3
+ spec.version = "0.0.0.0"
4
+ spec.summary = "converts image page URL to direct link, dimensions and image type"
5
+
6
+ spec.author = "Victor Maslov aka Nakilon"
7
+ spec.email = "nakilon@gmail.com"
8
+ spec.license = "MIT"
9
+ spec.homepage = "https://github.com/nakilon/directlink"
10
+
11
+ spec.add_dependency "nethttputils", "~>0.2.0.0"
12
+ spec.add_dependency "fastimage", "~>2.1.3"
13
+ spec.add_development_dependency "minitest"
14
+
15
+ spec.require_path = "lib"
16
+ spec.bindir = "bin"
17
+ spec.executable = "directlink"
18
+ spec.test_file = "test.rb"
19
+ spec.files = `git ls-files -z`.split(?\0) - spec.test_files
20
+
21
+ spec.requirements << "you may need to create apps and provide their API tokens:"
22
+ spec.requirements << "IMGUR_CLIENT_ID, FLICKR_API_KEY, _500PX_CONSUMER_KEY"
23
+ end