appydave-tools 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/bin/youtube_manager.rb +52 -11
- data/lib/appydave/tools/version.rb +1 -1
- data/lib/appydave/tools/youtube_manager/authorization.rb +3 -1
- data/lib/appydave/tools/youtube_manager/get_video.rb +34 -15
- data/lib/appydave/tools/youtube_manager/models/youtube_details.rb +62 -12
- data/lib/appydave/tools/youtube_manager/reports/video_details_report.rb +21 -16
- data/lib/appydave/tools/youtube_manager/update_video.rb +53 -0
- data/lib/appydave/tools.rb +1 -0
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed51cab9a76cb09289bbcfa80eb759c3f5d70f656043d25bce0b106f74757aef
|
4
|
+
data.tar.gz: c498125bae1ee080aebe7fd88c0d7c4ceabcb477c0cbd59d8d741c880010bfe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1520df315b862ca20f306e4e0e0f6ec06b05372858252f3f143e9ba0a7f10fdea18aacc368dd887ad308cdd559ee8664c4b1ad0922d70c89800dfb21124d2a27
|
7
|
+
data.tar.gz: 2b1e3fb4877bb919b3786e56042d2fde5850d85f8e78d7fa6cf2226dc08edc2bd61dac81e73c4de14e181bc784675d981e59277bbabdd31e34c937e2aef6336b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.9.4](https://github.com/klueless-io/appydave-tools/compare/v0.9.3...v0.9.4) (2024-06-12)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* move youtube management data to activemodel ([12d3351](https://github.com/klueless-io/appydave-tools/commit/12d3351b2243c436d0f59e2f2822d9d82cc6ebd6))
|
7
|
+
|
1
8
|
## [0.9.3](https://github.com/klueless-io/appydave-tools/compare/v0.9.2...v0.9.3) (2024-06-12)
|
2
9
|
|
3
10
|
|
data/bin/youtube_manager.rb
CHANGED
@@ -11,8 +11,8 @@ class YouTubeVideoManagerCLI
|
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@commands = {
|
14
|
-
'get' => method(:fetch_video_details)
|
15
|
-
|
14
|
+
'get' => method(:fetch_video_details),
|
15
|
+
'update' => method(:update_video_details)
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
@@ -30,23 +30,39 @@ class YouTubeVideoManagerCLI
|
|
30
30
|
|
31
31
|
def fetch_video_details(args)
|
32
32
|
options = parse_options(args, 'get')
|
33
|
-
|
34
|
-
|
33
|
+
get_video = Appydave::Tools::YouTubeManager::GetVideo.new
|
34
|
+
get_video.get(options[:video_id])
|
35
35
|
|
36
|
-
if
|
36
|
+
if get_video.video?
|
37
37
|
# json = JSON.pretty_generate(details)
|
38
38
|
# puts json
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
report = Appydave::Tools::YouTubeManager::Reports::VideoDetailsReport.new
|
41
|
+
report.print(get_video.data)
|
42
42
|
|
43
|
-
report = Appydave::Tools::YouTubeManager::Reports::VideoContentReport.new
|
44
|
-
report.print(manager.data)
|
43
|
+
# report = Appydave::Tools::YouTubeManager::Reports::VideoContentReport.new
|
44
|
+
# report.print(manager.data)
|
45
45
|
else
|
46
46
|
log.error "Video not found! Maybe it's private or deleted. ID: #{options[:video_id]}"
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
def update_video_details(args)
|
51
|
+
options = parse_update_options(args)
|
52
|
+
|
53
|
+
get_video = Appydave::Tools::YouTubeManager::GetVideo.new
|
54
|
+
get_video.get(options[:video_id])
|
55
|
+
|
56
|
+
update_video = Appydave::Tools::YouTubeManager::UpdateVideo.new(get_video.data)
|
57
|
+
|
58
|
+
update_video.title(options[:title]) if options[:title]
|
59
|
+
update_video.description(options[:description]) if options[:description]
|
60
|
+
update_video.tags(options[:tags]) if options[:tags]
|
61
|
+
update_video.category_id(options[:category_id]) if options[:category_id]
|
62
|
+
|
63
|
+
update_video.save
|
64
|
+
end
|
65
|
+
|
50
66
|
def parse_options(args, command)
|
51
67
|
options = { video_id: nil }
|
52
68
|
OptionParser.new do |opts|
|
@@ -68,11 +84,36 @@ class YouTubeVideoManagerCLI
|
|
68
84
|
options
|
69
85
|
end
|
70
86
|
|
87
|
+
def parse_update_options(args)
|
88
|
+
options = { video_id: nil }
|
89
|
+
OptionParser.new do |opts|
|
90
|
+
opts.banner = 'Usage: youtube_video_manager.rb update [options]'
|
91
|
+
|
92
|
+
opts.on('-v', '--video-id ID', 'YouTube Video ID') { |v| options[:video_id] = v }
|
93
|
+
opts.on('-t', '--title TITLE', 'Video Title') { |t| options[:title] = t }
|
94
|
+
opts.on('-d', '--description DESCRIPTION', 'Video Description') { |d| options[:description] = d }
|
95
|
+
opts.on('-g', '--tags TAGS', 'Video Tags (comma-separated)') { |g| options[:tags] = g.split(',') }
|
96
|
+
opts.on('-c', '--category-id CATEGORY_ID', 'Video Category ID') { |c| options[:category_id] = c }
|
97
|
+
|
98
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
99
|
+
puts opts
|
100
|
+
exit
|
101
|
+
end
|
102
|
+
end.parse!(args)
|
103
|
+
|
104
|
+
unless options[:video_id]
|
105
|
+
puts 'Missing required options. Use -h for help.'
|
106
|
+
exit
|
107
|
+
end
|
108
|
+
|
109
|
+
options
|
110
|
+
end
|
111
|
+
|
71
112
|
def print_help
|
72
113
|
puts 'Usage: youtube_video_manager.rb [command] [options]'
|
73
114
|
puts 'Commands:'
|
74
|
-
puts ' get
|
75
|
-
|
115
|
+
puts ' get Get details for a YouTube video'
|
116
|
+
puts ' update Update details for a YouTube video'
|
76
117
|
puts "Run 'youtube_video_manager.rb [command] --help' for more information on a command."
|
77
118
|
end
|
78
119
|
end
|
@@ -12,7 +12,9 @@ module Appydave
|
|
12
12
|
SCOPE = [
|
13
13
|
'https://www.googleapis.com/auth/youtube.readonly',
|
14
14
|
'https://www.googleapis.com/auth/youtube',
|
15
|
-
'https://www.googleapis.com/auth/youtube.force-ssl'
|
15
|
+
'https://www.googleapis.com/auth/youtube.force-ssl',
|
16
|
+
'https://www.googleapis.com/auth/youtubepartner',
|
17
|
+
'https://www.googleapis.com/auth/youtubepartner-channel-audit'
|
16
18
|
].freeze
|
17
19
|
|
18
20
|
def self.authorize
|
@@ -26,6 +26,8 @@ module Appydave
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def build_data(video)
|
29
|
+
category_title = get_category_title(video.snippet.category_id)
|
30
|
+
|
29
31
|
data = {
|
30
32
|
id: video.id,
|
31
33
|
title: video.snippet.title,
|
@@ -33,6 +35,13 @@ module Appydave
|
|
33
35
|
published_at: video.snippet.published_at,
|
34
36
|
channel_id: video.snippet.channel_id,
|
35
37
|
channel_title: video.snippet.channel_title,
|
38
|
+
category_id: video.snippet.category_id,
|
39
|
+
tags: video.snippet.tags,
|
40
|
+
thumbnails: video.snippet.thumbnails.to_h,
|
41
|
+
default_audio_language: video.snippet.default_audio_language,
|
42
|
+
default_language: video.snippet.default_language,
|
43
|
+
live_broadcast_content: video.snippet.live_broadcast_content,
|
44
|
+
category_title: category_title,
|
36
45
|
view_count: video.statistics.view_count,
|
37
46
|
like_count: video.statistics.like_count,
|
38
47
|
dislike_count: video.statistics.dislike_count,
|
@@ -42,30 +51,35 @@ module Appydave
|
|
42
51
|
license: video.status.license,
|
43
52
|
recording_location: video.recording_details&.location,
|
44
53
|
recording_date: video.recording_details&.recording_date,
|
45
|
-
tags: video.snippet.tags,
|
46
|
-
thumbnails: video.snippet.thumbnails.to_h,
|
47
54
|
duration: video.content_details.duration,
|
48
55
|
definition: video.content_details.definition,
|
49
56
|
caption: video.content_details.caption,
|
50
57
|
licensed_content: video.content_details.licensed_content
|
51
58
|
}
|
59
|
+
get_captions(video.id) # Fetch captions and associate them
|
52
60
|
# HAVE NOT FIGURED OUT THE PERMISSION ISSUE WITH THIS YET
|
53
61
|
# captions: get_captions(video.id) # Fetch captions and associate them
|
54
62
|
@data = Appydave::Tools::YouTubeManager::Models::YouTubeDetails.new(data)
|
55
63
|
end
|
56
64
|
|
65
|
+
def get_category_title(category_id)
|
66
|
+
response = @service.list_video_categories('snippet', id: category_id)
|
67
|
+
category = response.items.first
|
68
|
+
category&.snippet&.title
|
69
|
+
end
|
70
|
+
|
57
71
|
def get_captions(video_id)
|
58
|
-
captions_response = @service.list_captions('snippet', video_id)
|
72
|
+
captions_response = @service.list_captions('id,snippet', video_id)
|
59
73
|
captions_response.items.map do |caption|
|
60
|
-
puts "Caption ID: #{caption.id}"
|
61
|
-
puts "Language: #{caption.snippet.language}"
|
62
|
-
puts "Status: #{caption.snippet.status}"
|
63
|
-
puts "Track Kind: #{caption.snippet.track_kind}"
|
64
|
-
puts "Name: #{caption.snippet.name}"
|
65
|
-
puts "Is Auto-Synced: #{caption.snippet.is_auto_synced}"
|
66
|
-
puts "Is CC: #{caption.snippet.is_cc}"
|
67
|
-
puts "Is Draft: #{caption.snippet.is_draft}"
|
68
|
-
puts "Last Updated: #{caption.snippet.last_updated}"
|
74
|
+
# puts "Caption ID: #{caption.id}"
|
75
|
+
# puts "Language: #{caption.snippet.language}"
|
76
|
+
# puts "Status: #{caption.snippet.status}"
|
77
|
+
# puts "Track Kind: #{caption.snippet.track_kind}"
|
78
|
+
# puts "Name: #{caption.snippet.name}"
|
79
|
+
# puts "Is Auto-Synced: #{caption.snippet.is_auto_synced}"
|
80
|
+
# puts "Is CC: #{caption.snippet.is_cc}"
|
81
|
+
# puts "Is Draft: #{caption.snippet.is_draft}"
|
82
|
+
# puts "Last Updated: #{caption.snippet.last_updated}"
|
69
83
|
|
70
84
|
next unless caption.snippet.status == 'serving'
|
71
85
|
|
@@ -83,6 +97,7 @@ module Appydave
|
|
83
97
|
def download_caption(caption)
|
84
98
|
content = ''
|
85
99
|
formats = %w[srv1 vtt srt ttml] # Try multiple formats to find a compatible one
|
100
|
+
success = false
|
86
101
|
formats.each do |format|
|
87
102
|
break if content.present?
|
88
103
|
|
@@ -90,14 +105,18 @@ module Appydave
|
|
90
105
|
@service.download_caption(caption.id, tfmt: format) do |result, error|
|
91
106
|
if error.nil?
|
92
107
|
content = result
|
93
|
-
|
94
|
-
|
108
|
+
success = true
|
109
|
+
# else
|
110
|
+
# log.info "An error occurred while downloading caption #{caption.id} with format #{format}: #{error.message}"
|
95
111
|
end
|
96
112
|
end
|
97
113
|
rescue Google::Apis::ClientError => e
|
98
|
-
|
114
|
+
log.error "An error occurred while downloading caption #{caption.id} with format #{format}: #{e.message}"
|
99
115
|
end
|
100
116
|
end
|
117
|
+
|
118
|
+
log.error 'Error occurred while downloading captions, make sure you have the correct permissions.' unless success
|
119
|
+
|
101
120
|
content
|
102
121
|
end
|
103
122
|
end
|
@@ -12,11 +12,21 @@ module Appydave
|
|
12
12
|
include ActiveModel::Attributes
|
13
13
|
|
14
14
|
attribute :id, :string
|
15
|
-
attribute :title, :string
|
16
|
-
attribute :description, :string
|
17
|
-
attribute :published_at, :datetime
|
18
|
-
attribute :channel_id, :string
|
19
|
-
attribute :channel_title, :string
|
15
|
+
attribute :title, :string # snippet
|
16
|
+
attribute :description, :string # snippet
|
17
|
+
attribute :published_at, :datetime # snippet
|
18
|
+
attribute :channel_id, :string # snippet
|
19
|
+
attribute :channel_title, :string # snippet
|
20
|
+
attribute :category_id, :string # snippet
|
21
|
+
|
22
|
+
attribute :default_audio_language # snippet
|
23
|
+
attribute :default_language # snippet
|
24
|
+
attribute :live_broadcast_content # snippet
|
25
|
+
|
26
|
+
attribute :tags, array: true # snippet
|
27
|
+
attribute :thumbnails, :hash # snippet
|
28
|
+
|
29
|
+
attribute :category_title, :string
|
20
30
|
attribute :view_count, :integer
|
21
31
|
attribute :like_count, :integer
|
22
32
|
attribute :dislike_count, :integer
|
@@ -26,18 +36,58 @@ module Appydave
|
|
26
36
|
attribute :license, :string
|
27
37
|
attribute :recording_location, :string
|
28
38
|
attribute :recording_date, :datetime
|
29
|
-
attribute :tags, array: true
|
30
|
-
attribute :thumbnails, :hash
|
31
39
|
attribute :duration, :string
|
32
40
|
attribute :definition, :string
|
33
41
|
attribute :caption, :boolean
|
34
42
|
attribute :licensed_content, :boolean
|
35
|
-
|
43
|
+
attribute :captions, :array # , default: []
|
44
|
+
|
45
|
+
def initialize(attributes = {})
|
46
|
+
super
|
47
|
+
self.captions = attributes[:captions].map { |caption| Captions.new(caption) } if attributes[:captions]
|
48
|
+
end
|
49
|
+
|
50
|
+
def map_video_snippet
|
51
|
+
{
|
52
|
+
title: title,
|
53
|
+
description: description,
|
54
|
+
category_id: category_id,
|
55
|
+
tags: tags || [],
|
56
|
+
thumbnails: thumbnails
|
57
|
+
}
|
58
|
+
end
|
36
59
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
60
|
+
def to_h
|
61
|
+
{
|
62
|
+
id: id,
|
63
|
+
title: title,
|
64
|
+
description: description,
|
65
|
+
published_at: published_at,
|
66
|
+
channel_id: channel_id,
|
67
|
+
channel_title: channel_title,
|
68
|
+
category_id: category_id,
|
69
|
+
category_title: category_title,
|
70
|
+
default_audio_language: default_audio_language,
|
71
|
+
default_language: default_language,
|
72
|
+
live_broadcast_content: live_broadcast_content,
|
73
|
+
tags: tags,
|
74
|
+
thumbnails: thumbnails,
|
75
|
+
view_count: view_count,
|
76
|
+
like_count: like_count,
|
77
|
+
dislike_count: dislike_count,
|
78
|
+
comment_count: comment_count,
|
79
|
+
privacy_status: privacy_status,
|
80
|
+
embeddable: embeddable,
|
81
|
+
license: license,
|
82
|
+
recording_location: recording_location,
|
83
|
+
recording_date: recording_date,
|
84
|
+
duration: duration,
|
85
|
+
definition: definition,
|
86
|
+
caption: caption,
|
87
|
+
licensed_content: licensed_content
|
88
|
+
}
|
89
|
+
# captions: captions.map(&:to_h)
|
90
|
+
end
|
41
91
|
end
|
42
92
|
end
|
43
93
|
end
|
@@ -12,22 +12,27 @@ module Appydave
|
|
12
12
|
# log.heading 'Video Details Report'
|
13
13
|
# log.subheading 'Video Details Report'
|
14
14
|
log.section_heading 'Video Details Report'
|
15
|
-
log.kv 'ID', data
|
16
|
-
log.kv 'Title', data
|
17
|
-
log.kv '
|
18
|
-
log.kv '
|
19
|
-
log.kv '
|
20
|
-
log.kv '
|
21
|
-
log.kv '
|
22
|
-
log.kv '
|
23
|
-
log.kv '
|
24
|
-
log.kv 'Channel
|
25
|
-
log.kv '
|
26
|
-
log.kv '
|
27
|
-
log.kv '
|
28
|
-
log.kv '
|
29
|
-
log.kv '
|
30
|
-
log.kv '
|
15
|
+
log.kv 'ID', data.id
|
16
|
+
log.kv 'Title', data.title
|
17
|
+
log.kv 'Description', data.description[0..100]
|
18
|
+
log.kv 'Published At', data.published_at
|
19
|
+
log.kv 'View Count', data.view_count
|
20
|
+
log.kv 'Like Count', data.like_count
|
21
|
+
log.kv 'Dislike Count', data.dislike_count
|
22
|
+
log.kv 'Comment Count', data.comment_count
|
23
|
+
log.kv 'Privacy Status', data.privacy_status
|
24
|
+
log.kv 'Channel ID', data.channel_id
|
25
|
+
log.kv 'Channel Title', data.channel_title
|
26
|
+
log.kv 'Category ID', data.category_id
|
27
|
+
log.kv 'Category Title', data.category_title
|
28
|
+
log.kv 'Default Audio Language', data.default_audio_language
|
29
|
+
log.kv 'Default Language', data.default_language
|
30
|
+
log.kv 'Live Broadcast Content', data.live_broadcast_content
|
31
|
+
log.kv 'Embeddable', data.embeddable
|
32
|
+
log.kv 'License', data.license
|
33
|
+
log.kv 'Recording Location', data.recording_location
|
34
|
+
log.kv 'Recording Date', data.recording_date
|
35
|
+
log.kv 'Tags', data.tags&.join(', ')
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Appydave
|
4
|
+
module Tools
|
5
|
+
module YouTubeManager
|
6
|
+
# Update YouTube video details
|
7
|
+
class UpdateVideo < YouTubeBase
|
8
|
+
attr_reader :video_details
|
9
|
+
attr_reader :snippet
|
10
|
+
|
11
|
+
def initialize(video_details)
|
12
|
+
super()
|
13
|
+
@video_details = video_details
|
14
|
+
end
|
15
|
+
|
16
|
+
def title(title)
|
17
|
+
video_details.title = title
|
18
|
+
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def description(description)
|
23
|
+
video_details.description = description
|
24
|
+
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def tags(tags)
|
29
|
+
video_details.tags = tags
|
30
|
+
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def category_id(category_id)
|
35
|
+
video_details.category_id = category_id
|
36
|
+
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def save
|
41
|
+
snippet = video_details.map_video_snippet
|
42
|
+
|
43
|
+
video = Google::Apis::YoutubeV3::Video.new(
|
44
|
+
id: video_details.id,
|
45
|
+
snippet: snippet
|
46
|
+
)
|
47
|
+
|
48
|
+
@service.update_video('snippet', video)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/appydave/tools.rb
CHANGED
@@ -50,6 +50,7 @@ require 'appydave/tools/youtube_manager/models/captions'
|
|
50
50
|
require 'appydave/tools/youtube_manager/youtube_base'
|
51
51
|
require 'appydave/tools/youtube_manager/authorization'
|
52
52
|
require 'appydave/tools/youtube_manager/get_video'
|
53
|
+
require 'appydave/tools/youtube_manager/update_video'
|
53
54
|
require 'appydave/tools/youtube_manager/reports/video_details_report'
|
54
55
|
require 'appydave/tools/youtube_manager/reports/video_content_report'
|
55
56
|
|
data/package-lock.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "appydave-tools",
|
3
|
-
"version": "0.9.
|
3
|
+
"version": "0.9.5",
|
4
4
|
"lockfileVersion": 3,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "appydave-tools",
|
9
|
-
"version": "0.9.
|
9
|
+
"version": "0.9.5",
|
10
10
|
"devDependencies": {
|
11
11
|
"@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
|
12
12
|
"@semantic-release/changelog": "^6.0.3",
|
data/package.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appydave-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- lib/appydave/tools/youtube_manager/models/youtube_details.rb
|
201
201
|
- lib/appydave/tools/youtube_manager/reports/video_content_report.rb
|
202
202
|
- lib/appydave/tools/youtube_manager/reports/video_details_report.rb
|
203
|
+
- lib/appydave/tools/youtube_manager/update_video.rb
|
203
204
|
- lib/appydave/tools/youtube_manager/youtube_base.rb
|
204
205
|
- package-lock.json
|
205
206
|
- package.json
|