appydave-tools 0.9.4 → 0.9.5

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
  SHA256:
3
- metadata.gz: 8b6d7348b11097175604d3e0dfa967ad9667a36955b825f3ada9042229d35b86
4
- data.tar.gz: 91997ead7011056d971b85e7680ee8a099dee006b944210e0766db23d2a40986
3
+ metadata.gz: ed51cab9a76cb09289bbcfa80eb759c3f5d70f656043d25bce0b106f74757aef
4
+ data.tar.gz: c498125bae1ee080aebe7fd88c0d7c4ceabcb477c0cbd59d8d741c880010bfe6
5
5
  SHA512:
6
- metadata.gz: 8c454d6b2b206b188cff7529094e9cf5b1895933083e7d712e43d55289e3d93be06b0307bb9dd66f13b4910e625e8108b88e58660df15eeb96abaa28f4e439a6
7
- data.tar.gz: 1d1c25c9cf722bea8db372b6edca5d2fa3da909d097b0401e7f12e5d66a2dbb6dc15fe001f0b42a8e484ca4866f7755cd86d1f090608960bc4b980aacd34992b
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
 
@@ -11,8 +11,8 @@ class YouTubeVideoManagerCLI
11
11
 
12
12
  def initialize
13
13
  @commands = {
14
- 'get' => method(:fetch_video_details)
15
- # Additional commands can be added here
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
- manager = Appydave::Tools::YouTubeManager::GetVideo.new
34
- manager.get(options[:video_id])
33
+ get_video = Appydave::Tools::YouTubeManager::GetVideo.new
34
+ get_video.get(options[:video_id])
35
35
 
36
- if manager.video?
36
+ if get_video.video?
37
37
  # json = JSON.pretty_generate(details)
38
38
  # puts json
39
39
 
40
- # report = Appydave::Tools::YouTubeManager::Reports::VideoDetailsReport.new
41
- # report.print(manager.data)
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 Get details for a YouTube video'
75
- # Additional commands can be listed here
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Appydave
4
4
  module Tools
5
- VERSION = '0.9.4'
5
+ VERSION = '0.9.5'
6
6
  end
7
7
  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
- else
94
- puts "An error occurred while downloading caption #{caption.id} with format #{format}: #{error.message}"
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
- puts "An error occurred while downloading caption #{caption.id} with format #{format}: #{e.message}"
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
- # attribute :captions, :array, default: []
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
- # def initialize(attributes = {})
38
- # super
39
- # self.captions = attributes[:captions].map { |caption| Captions.new(caption) } if attributes[:captions]
40
- # end
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[:id]
16
- log.kv 'Title', data[:title]
17
- log.kv 'Published At', data[:published_at]
18
- log.kv 'View Count', data[:view_count]
19
- log.kv 'Like Count', data[:like_count]
20
- log.kv 'Dislike Count', data[:dislike_count]
21
- log.kv 'Comment Count', data[:comment_count]
22
- log.kv 'Privacy Status', data[:privacy_status]
23
- log.kv 'Channel ID', data[:channel_id]
24
- log.kv 'Channel Title', data[:channel_title]
25
- log.kv 'Embeddable', data[:embeddable]
26
- log.kv 'License', data[:license]
27
- log.kv 'Recording Location', data[:recording_location]
28
- log.kv 'Recording Date', data[:recording_date]
29
- log.kv 'Tags', data[:tags]&.join(', ')
30
- log.kv 'Description', data[:description][0..100]
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
@@ -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.4",
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.4",
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appydave-tools",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "AppyDave YouTube Automation Tools",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
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
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-12 00:00:00.000000000 Z
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