youtube-data 0.1.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 +7 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +4 -0
- data/TODO.md +12 -0
- data/lib/youtube/extractor.rb +138 -0
- data/lib/youtube/thumbnail.rb +91 -0
- data/lib/youtube/version.rb +5 -0
- data/lib/youtube-data.rb +13 -0
- data/sig/youtube.rbs +4 -0
- data/tests/data/raw_video.html +89 -0
- data/tests/mocks.rb +29 -0
- data/tests/test_all.rb +3 -0
- data/tests/test_extractor.rb +32 -0
- metadata +60 -0
data/tests/mocks.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'net/http/response'
|
|
2
|
+
|
|
3
|
+
# Mock types for testing the `Youtube` module.
|
|
4
|
+
module Mocks
|
|
5
|
+
|
|
6
|
+
class MockResponse < Net::HTTPResponse
|
|
7
|
+
|
|
8
|
+
def stream_check # Avoid: `stream_check': undefined method `closed?' for nil:NilClass (NoMethodError)
|
|
9
|
+
return
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class MockSession
|
|
15
|
+
def initialize(url)
|
|
16
|
+
@res = MockResponse.new(1.0, 200, "OK")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def set_res_body(content)
|
|
20
|
+
@res.read_body # Update body content and set.
|
|
21
|
+
@res.body = content
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def get(path)
|
|
25
|
+
return @res
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
data/tests/test_all.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/youtube-data'
|
|
4
|
+
require_relative 'mocks'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
#https://ruby-doc.org/stdlib-3.0.2/libdoc/test-unit/rdoc/Test/Unit/Assertions.html
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestExtractor < Test::Unit::TestCase
|
|
11
|
+
def setup
|
|
12
|
+
@mock_session = Mocks::MockSession.new(nil)
|
|
13
|
+
# Copy valid video html from file into the mock sessions `get` mock response which acts the same as normal session.
|
|
14
|
+
@mock_session.set_res_body(File.read('./data/raw_video.html'))
|
|
15
|
+
# Specify mock session to use and replace actual session with `opts[:mock_session]`.
|
|
16
|
+
@extractor = Youtube::DataExtractor.new('FtutLA63Cp8', {:mock_session => @mock_session})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_response_invalid_path
|
|
20
|
+
assert_raise(Youtube::InvalidPathError) do
|
|
21
|
+
@extractor.get_raw(nil)
|
|
22
|
+
end
|
|
23
|
+
assert_raise(Youtube::InvalidPathError) do
|
|
24
|
+
@extractor.get_raw("invalid/path")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_response_valid
|
|
29
|
+
res = @extractor.get_raw('/')
|
|
30
|
+
assert_instance_of(Mocks::MockResponse, res)
|
|
31
|
+
end
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: youtube-data
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- boddz
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Extract youtube video information using ruby.
|
|
14
|
+
email:
|
|
15
|
+
- boddz.dev@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- Gemfile
|
|
21
|
+
- LICENSE.txt
|
|
22
|
+
- README.md
|
|
23
|
+
- Rakefile
|
|
24
|
+
- TODO.md
|
|
25
|
+
- lib/youtube-data.rb
|
|
26
|
+
- lib/youtube/extractor.rb
|
|
27
|
+
- lib/youtube/thumbnail.rb
|
|
28
|
+
- lib/youtube/version.rb
|
|
29
|
+
- sig/youtube.rbs
|
|
30
|
+
- tests/data/raw_video.html
|
|
31
|
+
- tests/mocks.rb
|
|
32
|
+
- tests/test_all.rb
|
|
33
|
+
- tests/test_extractor.rb
|
|
34
|
+
homepage: https://github.com/boddz
|
|
35
|
+
licenses:
|
|
36
|
+
- MIT
|
|
37
|
+
metadata:
|
|
38
|
+
allowed_push_host: https://rubygems.org
|
|
39
|
+
homepage_uri: https://github.com/boddz
|
|
40
|
+
source_code_uri: https://github.com/boddz
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 2.6.0
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubygems_version: 3.4.10
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 4
|
|
59
|
+
summary: A youtube data scraper.
|
|
60
|
+
test_files: []
|