preadly-bulbasaur 0.2.1 → 0.3.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
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2279477cdf112255d8e1fc39cfed178ecb592aa8
|
4
|
+
data.tar.gz: 74718795d096dffe94e27a5cf20798de4516adb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ab87a531d9fb0fdb6c51c4e17c8afe3dee513b03dafd14ee68094c563649ba7cb4ba8ab097bcf3b1c2be18108a222af59321e785e7b36903e2d6e4cbdc8459d
|
7
|
+
data.tar.gz: c646b121b54cde24f7f381e5b4c4e0fb0845f93ce1b62e323ad39bdf790e0729355dc567326cb9e0f2d24a7618a894ea67c4e2400b80d575257ebb8ea5c2e521
|
@@ -2,8 +2,8 @@ module Bulbasaur
|
|
2
2
|
|
3
3
|
class ExtractImagesFromYoutube
|
4
4
|
|
5
|
-
EXTRACT_URL_PATTERN = /www\.youtube
|
6
|
-
EXTRACT_VID_PATTERN = /(?<=v
|
5
|
+
EXTRACT_URL_PATTERN = /www\.youtube(?:-nocookie)?\.com\/(?:v|embed)\/[a-zA-Z0-9-]+/i
|
6
|
+
EXTRACT_VID_PATTERN = /(?<=v|embed)\/(?<vid>[a-zA-Z0-9-]+)/i
|
7
7
|
|
8
8
|
def initialize(html)
|
9
9
|
@html = html
|
@@ -13,8 +13,7 @@ module Bulbasaur
|
|
13
13
|
images = Array.new
|
14
14
|
@html.scan(EXTRACT_URL_PATTERN).each do |video|
|
15
15
|
vid = get_vid(video)
|
16
|
-
|
17
|
-
images << { url: url_image }
|
16
|
+
images << { url: image_url(vid), url_fallback: image_url_fallback(vid) }
|
18
17
|
end
|
19
18
|
images
|
20
19
|
end
|
@@ -25,8 +24,13 @@ module Bulbasaur
|
|
25
24
|
EXTRACT_VID_PATTERN.match(video)[:vid]
|
26
25
|
end
|
27
26
|
|
28
|
-
def
|
27
|
+
def image_url(vid)
|
28
|
+
"http://img.youtube.com/vi/#{vid}/maxresdefault.jpg"
|
29
|
+
end
|
30
|
+
|
31
|
+
def image_url_fallback(vid)
|
29
32
|
"http://img.youtube.com/vi/#{vid}/0.jpg"
|
30
33
|
end
|
34
|
+
|
31
35
|
end
|
32
36
|
end
|
data/lib/bulbasaur/version.rb
CHANGED
@@ -30,7 +30,49 @@ RSpec.describe Bulbasaur::ExtractImagesFromYoutube do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "Does return youtube url" do
|
33
|
-
expect(subject.first[:url]).to eq "http://img.youtube.com/vi/123idfake321/
|
33
|
+
expect(subject.first[:url]).to eq "http://img.youtube.com/vi/123idfake321/maxresdefault.jpg"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "Does return youtube url fallback" do
|
37
|
+
expect(subject.first[:url_fallback]).to eq "http://img.youtube.com/vi/123idfake321/0.jpg"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "When has on youtube video with path 'v'" do
|
42
|
+
|
43
|
+
let(:html) do
|
44
|
+
%Q(<iframe width="560" height="315" src="https://www.youtube-nocookie.com/v/video-1" frameborder="0" allowfullscreen></iframe>)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "Does return array with 1 image" do
|
48
|
+
expect(subject.size).to eq 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it "Does return youtube url" do
|
52
|
+
expect(subject.first[:url]).to eq "http://img.youtube.com/vi/video-1/maxresdefault.jpg"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "Does return youtube url fallback" do
|
56
|
+
expect(subject.first[:url_fallback]).to eq "http://img.youtube.com/vi/video-1/0.jpg"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "When has on youtube video with domais no-cookies" do
|
61
|
+
|
62
|
+
let(:html) do
|
63
|
+
%Q(<iframe width="560" height="315" src="https://www.youtube-nocookie.com/v/video-6" frameborder="0" allowfullscreen></iframe>)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "Does return array with 1 image" do
|
67
|
+
expect(subject.size).to eq 1
|
68
|
+
end
|
69
|
+
|
70
|
+
it "Does return youtube url" do
|
71
|
+
expect(subject.first[:url]).to eq "http://img.youtube.com/vi/video-6/maxresdefault.jpg"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "Does return youtube url fallback" do
|
75
|
+
expect(subject.first[:url_fallback]).to eq "http://img.youtube.com/vi/video-6/0.jpg"
|
34
76
|
end
|
35
77
|
end
|
36
78
|
|
@@ -44,15 +86,36 @@ RSpec.describe Bulbasaur::ExtractImagesFromYoutube do
|
|
44
86
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/video1" frameborder="0" allowfullscreen></iframe>
|
45
87
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/video2" frameborder="0" allowfullscreen></iframe>
|
46
88
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/video3" frameborder="0" allowfullscreen></iframe>
|
89
|
+
<iframe width="560" height="315" src="https://www.youtube.com/embed/video-4" frameborder="0" allowfullscreen></iframe>
|
90
|
+
<iframe width="560" height="315" src="https://www.youtube.com/v/video-5" frameborder="0" allowfullscreen></iframe>
|
91
|
+
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/v/video-6" frameborder="0" allowfullscreen></iframe>
|
47
92
|
)
|
48
93
|
end
|
49
94
|
|
50
|
-
it "Does return array with
|
51
|
-
expect(subject.size).to eq
|
95
|
+
it "Does return array with 7 images" do
|
96
|
+
expect(subject.size).to eq 7
|
52
97
|
end
|
53
98
|
|
54
99
|
it "Does return youtube urls" do
|
55
|
-
expect(subject.map{ |video| video[:url] }).to include
|
100
|
+
expect(subject.map{ |video| video[:url] }).to include(
|
101
|
+
"http://img.youtube.com/vi/video0/maxresdefault.jpg",
|
102
|
+
"http://img.youtube.com/vi/video1/maxresdefault.jpg",
|
103
|
+
"http://img.youtube.com/vi/video2/maxresdefault.jpg",
|
104
|
+
"http://img.youtube.com/vi/video3/maxresdefault.jpg",
|
105
|
+
"http://img.youtube.com/vi/video-4/maxresdefault.jpg",
|
106
|
+
"http://img.youtube.com/vi/video-4/maxresdefault.jpg",
|
107
|
+
"http://img.youtube.com/vi/video-6/maxresdefault.jpg")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "Does return youtube urls fallback" do
|
111
|
+
expect(subject.map{ |video| video[:url_fallback] }).to include(
|
112
|
+
"http://img.youtube.com/vi/video0/0.jpg",
|
113
|
+
"http://img.youtube.com/vi/video1/0.jpg",
|
114
|
+
"http://img.youtube.com/vi/video2/0.jpg",
|
115
|
+
"http://img.youtube.com/vi/video3/0.jpg",
|
116
|
+
"http://img.youtube.com/vi/video-4/0.jpg",
|
117
|
+
"http://img.youtube.com/vi/video-4/0.jpg",
|
118
|
+
"http://img.youtube.com/vi/video-6/0.jpg")
|
56
119
|
end
|
57
120
|
end
|
58
121
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: preadly-bulbasaur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magno Costa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.4.6
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Bulbasaur is a helper for crawler operations used in Pread.ly
|
@@ -126,3 +126,4 @@ test_files:
|
|
126
126
|
- spec/bulbasaur/utils/normalize_url_spec.rb
|
127
127
|
- spec/bulbasaur_spec.rb
|
128
128
|
- spec/spec_helper.rb
|
129
|
+
has_rdoc:
|