video_thumb 0.1.5 → 0.2.0

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
- SHA1:
3
- metadata.gz: e2c0deaffc0f6ee237c256e84eab81b159869a9f
4
- data.tar.gz: 24319ee7d2eba9cebace79e6f04d92c2e7071e2b
2
+ SHA256:
3
+ metadata.gz: f99d53fc27df6cd785476fac9e619afaee8c070c04326d81a6e729210ac82076
4
+ data.tar.gz: 90b759636f8dd3c4a49908bb03c99073f94b714cb002e59a4d888dc05d44cbf3
5
5
  SHA512:
6
- metadata.gz: 63e7aaf90ba7f2fb51b83254410a248559dd9fe144efdb0713985fbf397351575e2f2342bf0ab1766a4c99a8e856970540cba19ae89b51eb4333fed0732aa904
7
- data.tar.gz: 81545d0ceafdbfd340173c324473cd71339948841b5c4cc41eb682f8c6c6fe106cd3ab67cc7969c195c695926541fd7d77076fd82dfe6f0ff55933e148ad75a2
6
+ metadata.gz: 6c6934fdd10cd4e13d6de036a8ac161be0c0f58c36ca778c67fb94baddcf0d448343bd0a2d92efb38dc2dcbb72deb88a4fb3ee4f6576880be16d7aaaa73a547c
7
+ data.tar.gz: 313150e20480a40fb449e9db1cdfab7a7495c3565b4f12e9121a3ac18f3dff20ae873bd20b73ef390bd4f9d5a80fe680e6fff464bb374a3ad7e0cc757cccd745
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)
@@ -1,3 +1,3 @@
1
1
  module VideoThumb
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/video_thumb.rb CHANGED
@@ -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('https://vimeo.com/api/v2/video/%s.json', vimeo_video_id)
57
+ image = begin
58
+ JSON.parse(URI.open(vimeo_video_json_url).read).first[vimeo_size]
59
+ rescue OpenURI::HTTPError
60
+ nil
61
+ end
62
+ return image
63
+ end
64
+ elsif url.include?('izlesene')
65
+ image = Nokogiri::HTML(URI.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
@@ -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 'https://i.vimeocdn.com/video/483188148-c2e6e58357c4d88f05c53949868a19ff76d7237f71f48947dd0b28276ab3d61b-d_640', 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 'https://i.vimeocdn.com/video/483188148-c2e6e58357c4d88f05c53949868a19ff76d7237f71f48947dd0b28276ab3d61b-d_640', VideoThumb.get('https://vimeo.com/101419884')
15
+ end
16
+
17
+ def test_aliased_vimeo_video
18
+ assert_equal 'https://i.vimeocdn.com/video/699818221-17cfe596d47c3751e58295209cb575361fc964f385b9be553834b19345dcae4a-d_640', 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.2.0
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: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -115,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.6.13
118
+ rubygems_version: 3.0.3.1
120
119
  signing_key:
121
120
  specification_version: 4
122
121
  summary: Youtube, Vimeo and İzlesene thumbnails