video_thumb 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e2c0deaffc0f6ee237c256e84eab81b159869a9f
4
- data.tar.gz: 24319ee7d2eba9cebace79e6f04d92c2e7071e2b
2
+ SHA256:
3
+ metadata.gz: 6888ae1ea891885747b25475f3a4c10db4a76a16936d48c1a8877a2f677da472
4
+ data.tar.gz: 4e4a771830e18b4173c50a9a0d55e448cc5882e650ae5212bc440e890a062822
5
5
  SHA512:
6
- metadata.gz: 63e7aaf90ba7f2fb51b83254410a248559dd9fe144efdb0713985fbf397351575e2f2342bf0ab1766a4c99a8e856970540cba19ae89b51eb4333fed0732aa904
7
- data.tar.gz: 81545d0ceafdbfd340173c324473cd71339948841b5c4cc41eb682f8c6c6fe106cd3ab67cc7969c195c695926541fd7d77076fd82dfe6f0ff55933e148ad75a2
6
+ metadata.gz: e78be4a60f4589de74446a6f4024e3e4fb47cee74aa02337d1763459d94afada8c5bdbd4994a7a184bc4c575dd9b8322884940305fcd0d4ad3edbbd383dedea0
7
+ data.tar.gz: b67321f0c1621ca470216ea7f23b621de1d9d73cd5d5167fec03ec1a9a13678bd24ea3e8b749e3dd313dcb6f41d53f12c72bf2a1c8c970f201655cf3ce81057d
data/README.md CHANGED
@@ -82,4 +82,4 @@ VideoThumb::get("http://www.izlesene.com/video/feder-goodbye-feat-lyse/7886121")
82
82
  5. Create a new Pull Request
83
83
 
84
84
  **Thanks**
85
- [deegz](https://github.com/deegz) - [akosipc](https://github.com/akosipc)
85
+ [deegz](https://github.com/deegz) - [akosipc](https://github.com/akosipc) - [adzierzanowski](https://github.com/adzierzanowski)
@@ -3,61 +3,80 @@ require 'video_thumb/version'
3
3
  require 'nokogiri'
4
4
  require 'open-uri'
5
5
  require 'json'
6
+ require 'uri'
7
+ require 'net/http'
6
8
 
7
9
  module VideoThumb
8
- def self.get url, size = 'large'
9
- # size_parameter = { 'small', 'medium', 'large', 'max'}
10
-
11
- # youtube
12
- # default: small - 120x90
13
- # mqdefault: medium - 320x180
14
- # hqdefault: high - 480x360
15
- # sddefault: 640x480
16
- # maxresdefault: original
17
-
18
- # vimeo
19
- # thumbnail_small: 100x75
20
- # thumbnail_medium: 200x150
21
- # thumbnail_large: 640xauto
22
-
23
- case size
24
- when "small"
25
- youtube_size = 'default'
26
- vimeo_size = 'thumbnail_small'
27
- when "medium"
28
- youtube_size = 'mqdefault'
29
- vimeo_size = 'thumbnail_medium'
30
- when "large"
31
- youtube_size = 'sddefault'
32
- vimeo_size = 'thumbnail_large'
33
- when "max"
34
- youtube_size = 'maxresdefault'
35
- vimeo_size = 'thumbnail_large'
36
- else
37
- youtube_size = 'sddefault'
38
- vimeo_size = 'thumbnail_large'
39
- end
10
+ class << self
11
+ def get(url, size = 'large')
12
+ # size_parameter = { 'small', 'medium', 'large', 'max'}
40
13
 
41
- if url.include?('youtu.be') || url.include?('youtube')
42
- regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
43
- url.gsub(regex) do
44
- youtube_video_id = $4
45
- image = "https://img.youtube.com/vi/#{youtube_video_id}/#{youtube_size}.jpg"
46
- return image
14
+ # youtube
15
+ # default: small - 120x90
16
+ # mqdefault: medium - 320x180
17
+ # hqdefault: high - 480x360
18
+ # sddefault: 640x480
19
+ # maxresdefault: original
20
+
21
+ # vimeo
22
+ # thumbnail_small: 100x75
23
+ # thumbnail_medium: 200x150
24
+ # thumbnail_large: 640xauto
25
+
26
+ case size
27
+ when 'small'
28
+ youtube_size = 'default'
29
+ vimeo_size = 'thumbnail_small'
30
+ when 'medium'
31
+ youtube_size = 'mqdefault'
32
+ vimeo_size = 'thumbnail_medium'
33
+ when 'large'
34
+ youtube_size = 'sddefault'
35
+ vimeo_size = 'thumbnail_large'
36
+ when 'max'
37
+ youtube_size = 'maxresdefault'
38
+ vimeo_size = 'thumbnail_large'
39
+ else
40
+ youtube_size = 'sddefault'
41
+ vimeo_size = 'thumbnail_large'
47
42
  end
48
- elsif url.include?('vimeo')
49
- regex = /^https?:\/\/(?:.*?)\.?(vimeo)\.com\/(\d+).*$/
50
- url.gsub(regex) do
51
- vimeo_video_id = $2
52
- vimeo_video_json_url = 'http://vimeo.com/api/v2/video/%s.json' % vimeo_video_id
53
- image = JSON.parse(open(vimeo_video_json_url).read).first[vimeo_size] rescue nil
43
+
44
+ if url.include?('youtu.be') || url.include?('youtube')
45
+ regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?[A-Za-z0-9_=-]+&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
46
+ url.gsub(regex) do
47
+ youtube_video_id = Regexp.last_match(4)
48
+ image = "https://img.youtube.com/vi/#{youtube_video_id}/#{youtube_size}.jpg"
49
+ return image
50
+ end
51
+ elsif url.include?('vimeo')
52
+ regex = /^https?:\/\/(?:.*?)\.?(vimeo)\.com\/(\d+).*$/
53
+ url = get_redirect_url(url) unless regex.match?(url)
54
+ url.gsub(regex) do
55
+ vimeo_video_id = Regexp.last_match(2)
56
+ vimeo_video_json_url = format('http://vimeo.com/api/v2/video/%s.json', vimeo_video_id)
57
+ image = begin
58
+ JSON.parse(open(vimeo_video_json_url).read).first[vimeo_size]
59
+ rescue StandardError
60
+ nil
61
+ end
62
+ return image
63
+ end
64
+ elsif url.include?('izlesene')
65
+ image = Nokogiri::HTML(open(url)).css("meta[property='og:image']").at_css('meta[property="og:image"]')['content']
54
66
  return image
67
+ else
68
+ return false
55
69
  end
56
- elsif url.include?('izlesene')
57
- image = Nokogiri::HTML(open(url)).css("meta[property='og:image']").at_css('meta[property="og:image"]')['content']
58
- return image
59
- else
60
- return false
70
+ end
71
+
72
+ private
73
+
74
+ def get_redirect_url(url)
75
+ parsed_url = URI(url)
76
+ http = Net::HTTP.new(parsed_url.host, parsed_url.port)
77
+ http.use_ssl = true
78
+ location = http.get(parsed_url.path).header['location']
79
+ "#{parsed_url.scheme}://#{parsed_url.host}#{location}"
61
80
  end
62
81
  end
63
82
  end
@@ -1,3 +1,3 @@
1
1
  module VideoThumb
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -3,12 +3,22 @@ require 'video_thumb'
3
3
 
4
4
  class VideoThumbTest < Minitest::Test
5
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")
6
+ assert_equal 'https://img.youtube.com/vi/iEPTlhBmwRg/mqdefault.jpg', VideoThumb.get('http://www.youtube.com/watch?v=iEPTlhBmwRg', 'medium')
7
7
  end
8
+
8
9
  def test_vimeo_video
9
- assert_equal "http://i.vimeocdn.com/video/483188148_640.jpg", VideoThumb::get("http://vimeo.com/101419884")
10
+ assert_equal 'http://i.vimeocdn.com/video/483188148_640.jpg', VideoThumb.get('http://vimeo.com/101419884')
10
11
  end
12
+
11
13
  def test_secure_vimeo_video
12
- assert_equal "http://i.vimeocdn.com/video/483188148_640.jpg", VideoThumb::get("https://vimeo.com/101419884")
14
+ assert_equal 'http://i.vimeocdn.com/video/483188148_640.jpg', VideoThumb.get('https://vimeo.com/101419884')
15
+ end
16
+
17
+ def test_aliased_vimeo_video
18
+ assert_equal 'http://i.vimeocdn.com/video/699818221_640.jpg', VideoThumb.get('https://vimeo.com/madeinyuhara/watasinoinaihoshi')
19
+ end
20
+
21
+ def test_reversed_url_params
22
+ assert_equal 'https://img.youtube.com/vi/9BOuRUlRKzA/sddefault.jpg', VideoThumb.get('https://www.youtube.com/watch?time_continue=3&v=9BOuRUlRKzA')
13
23
  end
14
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: video_thumb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tolga Gezginiş
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2018-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubyforge_project:
119
- rubygems_version: 2.6.13
119
+ rubygems_version: 2.7.3
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Youtube, Vimeo and İzlesene thumbnails