video_thumb 0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f8e8986ae87d879cd7525849c2150559328c63d
4
+ data.tar.gz: 1c32ed0cc3621675af1ec422be77b27a182f5682
5
+ SHA512:
6
+ metadata.gz: 17006a8c20939a5fc298c1fd4179bd212ab810878040e336936d3a27817b69623140d1631153c6f0290b7cff34bb22df962b8cc1c61ffabd983dd747bfd56417
7
+ data.tar.gz: a2e4da6fee449ea5e72860f80911c4e53a9a713f0a2bd4111e245b8d7a96e7974a2fbaf3ed0cefa44333da79f3ec6792e3866f444a3dd8967535a33b8764fbe7
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in video_thumb.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tolga Gezginiş
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Youtube and Vimeo thumbnails
2
+
3
+ Get the thumbnails from Youtube and Vimeo videos for Ruby.
4
+
5
+ And it may support more video hoster with your [contributions](#contributing).
6
+
7
+ ## Installation
8
+
9
+ Add it to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'video_thumb'
13
+ ```
14
+
15
+ and run on terminal:
16
+
17
+ $ bundle
18
+
19
+ or install the gem on terminal.
20
+
21
+ $ gem install video_thumb
22
+
23
+ ## Parameters
24
+
25
+ **url**
26
+
27
+ > Youtube or Vimeo video link
28
+ > http://www.youtube.com/watch?v=iEPTlhBmwRg
29
+ > or
30
+ > http://vimeo.com/101419884
31
+
32
+ **size**
33
+ > **default** *= large*
34
+ > **small** *(Youtube: 120x90, Vimeo: 100x75)*
35
+ > **medium** *(Youtube: 320x180, Vimeo: 200x150)*
36
+ > **large** *(Youtube: 640x480, Vimeo: 640xauto)*
37
+ > **max** *(Youtube: original, Vimeo: 640xauto)*
38
+
39
+
40
+
41
+ ## Usage
42
+
43
+ ```ruby
44
+ require 'video_thumb'
45
+ VideoThumb::get("http://vimeo.com/101419884")
46
+ # returns large thumbnail from Vimeo video
47
+ # http://i.vimeocdn.com/video/483188148_640.jpg
48
+
49
+ VideoThumb::get("http://www.youtube.com/watch?v=iEPTlhBmwRg", "medium")
50
+ # returns medium thumbnail from Youtube video
51
+ # https://img.youtube.com/vi/iEPTlhBmwRg/mqdefault.jpg
52
+ ```
53
+
54
+
55
+ **Rails 4**
56
+ ```ruby
57
+ VideoThumb::get("http://vimeo.com/101419884")
58
+ # returns large thumbnail from Vimeo video
59
+ # http://i.vimeocdn.com/video/483188148_640.jpg
60
+
61
+ VideoThumb::get("http://www.youtube.com/watch?v=iEPTlhBmwRg", "medium")
62
+ # returns medium thumbnail from Youtube video
63
+ # https://img.youtube.com/vi/iEPTlhBmwRg/mqdefault.jpg
64
+ ```
65
+
66
+ ## Dependencies
67
+ - open-uri
68
+ - json
69
+
70
+
71
+ ## Contributing
72
+ <a name="contributing"></a>
73
+ 1. Fork it ( https://github.com/tgezginis/video_thumb/fork )
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.test_files = FileList['test/*_test.rb']
6
+ end
7
+
8
+ task default: :test
@@ -0,0 +1,3 @@
1
+ module VideoThumb
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,58 @@
1
+ require 'video_thumb/version'
2
+
3
+ require 'open-uri'
4
+ require 'json'
5
+
6
+ module VideoThumb
7
+ def self.get url, size = 'large'
8
+ # size_parameter = { 'small', 'medium', 'large', 'max'}
9
+
10
+ # youtube
11
+ # default: small - 120x90
12
+ # mqdefault: medium - 320x180
13
+ # hqdefault: high - 480x360
14
+ # sddefault: 640x480
15
+ # maxresdefault: original
16
+
17
+ # vimeo
18
+ # thumbnail_small: 100x75
19
+ # thumbnail_medium: 200x150
20
+ # thumbnail_large: 640xauto
21
+
22
+ if size == "small"
23
+ youtube_size = 'default'
24
+ vimeo_size = 'thumbnail_small'
25
+ elsif size == "medium"
26
+ youtube_size = 'mqdefault'
27
+ vimeo_size = 'thumbnail_medium'
28
+ elsif size == "large"
29
+ youtube_size = 'sddefault'
30
+ vimeo_size = 'thumbnail_large'
31
+ elsif size == "max"
32
+ youtube_size = 'maxresdefault'
33
+ vimeo_size = 'thumbnail_large'
34
+ else
35
+ youtube_size = 'sddefault'
36
+ vimeo_size = 'thumbnail_large'
37
+ end
38
+
39
+ if url.include? 'youtube'
40
+ regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
41
+ url.gsub(regex) do
42
+ youtube_video_id = $4
43
+ image = "https://img.youtube.com/vi/#{youtube_video_id}/#{youtube_size}.jpg"
44
+ return image
45
+ end
46
+ elsif url.include? 'vimeo'
47
+ regex = /^http:\/\/(?:.*?)\.?(vimeo)\.com\/(watch\?[^#]*v=(\w+)|(\d+)).*$/
48
+ url.gsub(regex) do
49
+ vimeo_video_id = $2
50
+ vimeo_video_json_url = 'http://vimeo.com/api/v2/video/%s.json' % vimeo_video_id
51
+ image = JSON.parse(open(vimeo_video_json_url).read).first[vimeo_size] rescue nil
52
+ return image
53
+ end
54
+ else
55
+ return false
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,11 @@
1
+ require 'minitest/autorun'
2
+ require 'video_thumb'
3
+
4
+ class VideoThumbTest < Minitest::Test
5
+ def test_youtube_video
6
+ assert_equal "https://img.youtube.com/vi/iEPTlhBmwRg/mqdefault.jpg", VideoThumb::get("http://www.youtube.com/watch?v=iEPTlhBmwRg", "medium")
7
+ end
8
+ def test_vimeo_video
9
+ assert_equal "http://i.vimeocdn.com/video/483188148_640.jpg", VideoThumb::get("http://vimeo.com/101419884")
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'video_thumb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "video_thumb"
8
+ spec.version = VideoThumb::VERSION
9
+ spec.authors = ["Tolga Gezginiş"]
10
+ spec.email = ["tolga@gezginis.com"]
11
+ spec.summary = %q{Youtube and Vimeo thumbnails}
12
+ spec.description = %q{Get the thumbnails from Youtube and Vimeo videos}
13
+ spec.homepage = "https://github.com/tgezginis/video_thumb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "json"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest"
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: video_thumb
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Tolga Gezginiş
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Get the thumbnails from Youtube and Vimeo videos
70
+ email:
71
+ - tolga@gezginis.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/video_thumb.rb
82
+ - lib/video_thumb/version.rb
83
+ - test/video_thumb_test.rb
84
+ - video_thumb.gemspec
85
+ homepage: https://github.com/tgezginis/video_thumb
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.4.3
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Youtube and Vimeo thumbnails
109
+ test_files:
110
+ - test/video_thumb_test.rb