youtuberb 0.1.3 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/Gemfile.lock +8 -4
- data/README.md +40 -3
- data/Rakefile +10 -1
- data/lib/you_tube/client.rb +5 -4
- data/lib/you_tube/collection.rb +1 -1
- data/lib/you_tube/objects/search_result.rb +30 -0
- data/lib/you_tube/objects/video.rb +8 -1
- data/lib/you_tube/resources/channels.rb +3 -2
- data/lib/you_tube/resources/search.rb +10 -0
- data/lib/you_tube/resources/videos.rb +20 -6
- data/lib/you_tube/version.rb +1 -1
- data/lib/you_tube.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ad415df9db8764f52eb113801d854187d73b737fefb7fa9b3bb0335eb5de93d
|
4
|
+
data.tar.gz: 30dfe24653e307396757d023e89b414a6ee4ffd080985a2709e817cb4e5c9626
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11e24c67431887e27a22bcb20c2d0dcd347f266247f634697916f23a4dcf9a193a820220d1598ef471ab91ab9d9ffd3e7776552e22500e564b8edd400f7774c7
|
7
|
+
data.tar.gz: f97e03dab51aadaa65f5ebf76b7416a4bf1f81b2b7416e3fa8d48e851f5162597a783e6ff1605d478583951b07ba3be6df38a5b8ed4f1f4c7eef45157c947faf
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
youtuberb (0.1
|
4
|
+
youtuberb (0.2.1)
|
5
5
|
faraday (~> 2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
base64 (0.2.0)
|
10
11
|
dotenv (2.7.6)
|
11
|
-
faraday (2.
|
12
|
-
|
12
|
+
faraday (2.8.1)
|
13
|
+
base64
|
14
|
+
faraday-net_http (>= 2.0, < 3.1)
|
13
15
|
ruby2_keywords (>= 0.0.4)
|
14
|
-
faraday-net_http (
|
16
|
+
faraday-net_http (3.0.2)
|
17
|
+
minitest (5.20.0)
|
15
18
|
rake (13.0.6)
|
16
19
|
ruby2_keywords (0.0.5)
|
17
20
|
|
@@ -20,6 +23,7 @@ PLATFORMS
|
|
20
23
|
|
21
24
|
DEPENDENCIES
|
22
25
|
dotenv
|
26
|
+
minitest (~> 5.0)
|
23
27
|
rake (~> 13.0)
|
24
28
|
youtuberb!
|
25
29
|
|
data/README.md
CHANGED
@@ -16,10 +16,14 @@ gem 'youtuberb'
|
|
16
16
|
|
17
17
|
### Set Client Details
|
18
18
|
|
19
|
-
Firstly you'll need to set an API Key
|
20
|
-
An Access Token will be an OAuth2 token generated after authentication.
|
19
|
+
Firstly you'll need to set an API Key. A user Access Token is required to access private data.
|
20
|
+
An Access Token will be an OAuth2 token generated after authentication.
|
21
21
|
|
22
22
|
```ruby
|
23
|
+
# To access public data, just an API Key is required
|
24
|
+
@client = YouTube::Client.new(api_key: "")
|
25
|
+
|
26
|
+
# Or to access data for a user, an Access Token is also required
|
23
27
|
@client = YouTube::Client.new(api_key: "", access_token: "")
|
24
28
|
```
|
25
29
|
|
@@ -41,15 +45,32 @@ An Access Token will be an OAuth2 token generated after authentication.
|
|
41
45
|
```ruby
|
42
46
|
# Get a single video
|
43
47
|
@client.videos.list(id: "abc123")
|
48
|
+
# => #<YouTube::Video...
|
44
49
|
|
45
50
|
# Get multiple videos
|
46
|
-
@client.videos.list(
|
51
|
+
@client.videos.list(ids: ["abc123", "123abc"])
|
52
|
+
# => #<YouTube::Collection...
|
47
53
|
|
48
54
|
# Liked videos for the currently authenticated user
|
49
55
|
@client.videos.liked
|
56
|
+
# => #<YouTube::Collection...
|
50
57
|
|
51
58
|
# Get a video owned by the current user. This retrieves extra information so will only work on videos owned by the current user.
|
52
59
|
@client.videos.retrieve(id: "abc123")
|
60
|
+
# => #<YouTube::Video...
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Getting a list of Videos for a Channel
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
# First, grab the Channel details
|
67
|
+
channel = @client.channels.retrieve(id: "channel_id")
|
68
|
+
|
69
|
+
# Then use the Playlist Items endpoint to get the Videos
|
70
|
+
@client.playlist_items.list playlist_id: channel.contentDetails.relatedPlaylists.uploads
|
71
|
+
|
72
|
+
# Or use the Search endpoint
|
73
|
+
@client.search.list channelId: channel.id
|
53
74
|
```
|
54
75
|
|
55
76
|
### Playlists
|
@@ -69,6 +90,7 @@ An Access Token will be an OAuth2 token generated after authentication.
|
|
69
90
|
@client.playlists.update(id: "playlist_id", title: "My Playlist", privacy_status: "public")
|
70
91
|
@client.playlists.delete(id: "playlist_id")
|
71
92
|
```
|
93
|
+
|
72
94
|
### Playlist Items
|
73
95
|
|
74
96
|
```ruby
|
@@ -85,6 +107,21 @@ An Access Token will be an OAuth2 token generated after authentication.
|
|
85
107
|
@client.playlist_items.delete(id: "playlist_id")
|
86
108
|
```
|
87
109
|
|
110
|
+
### Search
|
111
|
+
|
112
|
+
For a full list of parameters, see the [YouTube API Docs](https://developers.google.com/youtube/v3/docs/search/list).
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
# Search YouTube for a term
|
116
|
+
@client.search.list(q: "search term")
|
117
|
+
|
118
|
+
# Restrict the search to a channel
|
119
|
+
@client.search.list(channelId: "channel")
|
120
|
+
|
121
|
+
# Search a channel for videos only and ordered by date
|
122
|
+
@client.search.list(channelId: "channel", type: "video", order: "date")
|
123
|
+
```
|
124
|
+
|
88
125
|
## Contributing
|
89
126
|
|
90
127
|
Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/youtuberb.
|
data/Rakefile
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
|
-
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :test
|
13
|
+
|
data/lib/you_tube/client.rb
CHANGED
@@ -4,13 +4,10 @@ module YouTube
|
|
4
4
|
|
5
5
|
attr_reader :api_key, :access_token, :adapter
|
6
6
|
|
7
|
-
def initialize(api_key:, access_token
|
7
|
+
def initialize(api_key:, access_token: nil, adapter: Faraday.default_adapter)
|
8
8
|
@api_key = api_key
|
9
9
|
@access_token = access_token
|
10
10
|
@adapter = adapter
|
11
|
-
|
12
|
-
# Test stubs for requests
|
13
|
-
@stubs = stubs
|
14
11
|
end
|
15
12
|
|
16
13
|
def channels
|
@@ -29,6 +26,10 @@ module YouTube
|
|
29
26
|
PlaylistItemsResource.new(self)
|
30
27
|
end
|
31
28
|
|
29
|
+
def search
|
30
|
+
SearchResource.new(self)
|
31
|
+
end
|
32
|
+
|
32
33
|
def connection
|
33
34
|
@connection ||= Faraday.new(BASE_URL) do |conn|
|
34
35
|
conn.request :authorization, :Bearer, access_token
|
data/lib/you_tube/collection.rb
CHANGED
@@ -7,7 +7,7 @@ module YouTube
|
|
7
7
|
|
8
8
|
new(
|
9
9
|
data: body["items"].map { |attrs| type.new(attrs) },
|
10
|
-
total: body["
|
10
|
+
total: body["items"].count,
|
11
11
|
next_page_token: body["nextPageToken"],
|
12
12
|
prev_page_token: body["prevPageToken"],
|
13
13
|
# cursor: body.dig("pagination", "cursor")
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module YouTube
|
2
|
+
class SearchResult < Object
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
super options
|
6
|
+
|
7
|
+
if options["id"]
|
8
|
+
self.video_id = options["id"]["videoId"] || nil
|
9
|
+
self.playlist_id = options["id"]["playlistId"] || nil
|
10
|
+
end
|
11
|
+
|
12
|
+
if options["snippet"]
|
13
|
+
self.title = options["snippet"]["title"]
|
14
|
+
self.description = options["snippet"]["description"]
|
15
|
+
self.published_at = options["snippet"]["publishedAt"]
|
16
|
+
self.channel_id = options["snippet"]["channelId"]
|
17
|
+
|
18
|
+
if options["snippet"]["thumbnails"]
|
19
|
+
thumb = options["snippet"]["thumbnails"]
|
20
|
+
self.thumbnail_default = thumb["default"]["url"] if thumb["default"]
|
21
|
+
self.thumbnail_medium = thumb["medium"]["url"] if thumb["medium"]
|
22
|
+
self.thumbnail_high = thumb["high"]["url"] if thumb["high"]
|
23
|
+
self.thumbnail_standard = thumb["standard"]["url"] if thumb["standard"]
|
24
|
+
self.thumbnail_maxres = thumb["maxres"]["url"] if thumb["maxres"]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -9,7 +9,7 @@ module YouTube
|
|
9
9
|
self.description = options["snippet"]["description"]
|
10
10
|
self.published_at = options["snippet"]["publishedAt"]
|
11
11
|
self.channel_id = options["snippet"]["channelId"]
|
12
|
-
|
12
|
+
|
13
13
|
if options["snippet"]["thumbnails"]
|
14
14
|
thumb = options["snippet"]["thumbnails"]
|
15
15
|
self.thumbnail_default = thumb["default"]["url"] if thumb["default"]
|
@@ -23,6 +23,13 @@ module YouTube
|
|
23
23
|
# Is a Video is blocked in any countries?
|
24
24
|
if options["contentDetails"]
|
25
25
|
self.blocked = !options["contentDetails"]["regionRestriction"].nil?
|
26
|
+
self.age_restricted = !options["contentDetails"]["contentRating"].nil? && options["contentDetails"]["contentRating"]["ytRating"] == "ytAgeRestricted"
|
27
|
+
end
|
28
|
+
|
29
|
+
if options["liveStreamingDetails"]
|
30
|
+
self.live_stream = options["liveStreamingDetails"]["actualStartTime"].present?
|
31
|
+
else
|
32
|
+
self.live_stream = false
|
26
33
|
end
|
27
34
|
|
28
35
|
if options["status"]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module YouTube
|
2
2
|
class ChannelsResource < Resource
|
3
3
|
|
4
|
-
PARTS = "id,snippet,status,statistics"
|
4
|
+
PARTS = "id,snippet,status,statistics,contentDetails"
|
5
5
|
|
6
6
|
# Retrieve the channel of the currently authenticated user
|
7
7
|
def mine
|
@@ -9,12 +9,13 @@ module YouTube
|
|
9
9
|
return nil if response.body["pageInfo"]["totalResults"] == 0
|
10
10
|
Channel.new(response.body["items"][0])
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
# Retrieve a Channel by its ID or Username
|
14
14
|
def retrieve(id: nil, username: nil)
|
15
15
|
attrs = {}
|
16
16
|
attrs[:id] = id if id
|
17
17
|
attrs[:forUsername] = username if username
|
18
|
+
raise ArgumentError, "Must provide either an ID or Username" if attrs.empty?
|
18
19
|
|
19
20
|
response = get_request "channels", params: attrs.merge({part: PARTS})
|
20
21
|
return nil if response.body["pageInfo"]["totalResults"] == 0
|
@@ -1,13 +1,27 @@
|
|
1
1
|
module YouTube
|
2
2
|
class VideosResource < Resource
|
3
3
|
|
4
|
-
PARTS = "id,contentDetails,
|
5
|
-
AUTH_PARTS = "id,contentDetails,fileDetails,processingDetails,
|
6
|
-
|
4
|
+
PARTS = "id,snippet,contentDetails,liveStreamingDetails,statistics,status"
|
5
|
+
AUTH_PARTS = "id,snippet,contentDetails,fileDetails,processingDetails,statistics,status,suggestions"
|
6
|
+
|
7
7
|
# Retrieves Videos by ID. Can be comma separated to retrieve multiple.
|
8
|
-
def list(id:)
|
9
|
-
|
10
|
-
|
8
|
+
def list(id: nil, ids: nil)
|
9
|
+
raise "Either id or ids is required" unless !id.nil? || !ids.nil?
|
10
|
+
|
11
|
+
if id
|
12
|
+
response = get_request("videos", params: {id: id, part: PARTS})
|
13
|
+
elsif ids
|
14
|
+
response = get_request("videos", params: {id: ids.join(","), part: PARTS})
|
15
|
+
end
|
16
|
+
|
17
|
+
body = response.body["items"]
|
18
|
+
if body.count == 1
|
19
|
+
Video.new body[0]
|
20
|
+
elsif body.count > 1
|
21
|
+
Collection.from_response(response, type: Video)
|
22
|
+
else
|
23
|
+
return nil
|
24
|
+
end
|
11
25
|
end
|
12
26
|
|
13
27
|
# Retrieves liked Videos for the currently authenticated user
|
data/lib/you_tube/version.rb
CHANGED
data/lib/you_tube.rb
CHANGED
@@ -15,10 +15,12 @@ module YouTube
|
|
15
15
|
autoload :VideosResource, "you_tube/resources/videos"
|
16
16
|
autoload :PlaylistsResource, "you_tube/resources/playlists"
|
17
17
|
autoload :PlaylistItemsResource, "you_tube/resources/playlist_items"
|
18
|
+
autoload :SearchResource, "you_tube/resources/search"
|
18
19
|
|
19
20
|
autoload :Channel, "you_tube/objects/channel"
|
20
21
|
autoload :Video, "you_tube/objects/video"
|
21
22
|
autoload :Playlist, "you_tube/objects/playlist"
|
22
23
|
autoload :PlaylistItem, "you_tube/objects/playlist_item"
|
24
|
+
autoload :SearchResult, "you_tube/objects/search_result"
|
23
25
|
|
24
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: youtuberb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Perry
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -47,11 +47,13 @@ files:
|
|
47
47
|
- lib/you_tube/objects/channel.rb
|
48
48
|
- lib/you_tube/objects/playlist.rb
|
49
49
|
- lib/you_tube/objects/playlist_item.rb
|
50
|
+
- lib/you_tube/objects/search_result.rb
|
50
51
|
- lib/you_tube/objects/video.rb
|
51
52
|
- lib/you_tube/resource.rb
|
52
53
|
- lib/you_tube/resources/channels.rb
|
53
54
|
- lib/you_tube/resources/playlist_items.rb
|
54
55
|
- lib/you_tube/resources/playlists.rb
|
56
|
+
- lib/you_tube/resources/search.rb
|
55
57
|
- lib/you_tube/resources/videos.rb
|
56
58
|
- lib/you_tube/version.rb
|
57
59
|
- lib/youtuberb.rb
|
@@ -77,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
79
|
- !ruby/object:Gem::Version
|
78
80
|
version: '0'
|
79
81
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
82
|
+
rubygems_version: 3.5.1
|
81
83
|
signing_key:
|
82
84
|
specification_version: 4
|
83
85
|
summary: A Ruby library for interacting with the YouTube API
|