podcast-to-youtube 0.2.0 → 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 +4 -4
- data/bin/podcast-to-youtube +26 -24
- data/lib/podcast-to-youtube.rb +81 -23
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57b82537f13f35c6432a322663f7360e910f9157
|
4
|
+
data.tar.gz: 082524dcc9f62e39f7ff2ff2d1c9cd97ffca0e9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29c53c0dd2944e10e94c9fea6b3031fa7e90bd6e4545fd43a05256a07707e04438c4fc7070f37bafeb76f873cacda22bf5ee47655176bd6eacf7b7a63075c0f2
|
7
|
+
data.tar.gz: efb9857a5df38a23b5f7ea228909731a12bbe9af4885ec0bce6328f1f1dc92cfb4a5d7bd9e7358b8f95668851954f9c89cb67f0071f63853ab40136febfb3c71
|
data/bin/podcast-to-youtube
CHANGED
@@ -9,34 +9,36 @@ require 'optparse'
|
|
9
9
|
options = {}
|
10
10
|
|
11
11
|
opt_parser = OptionParser.new do |opt|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
12
|
+
opt.banner = "Usage: podcast-to-youtube COMMAND [OPTIONS]"
|
13
|
+
opt.separator ""
|
14
|
+
opt.separator "Commands"
|
15
|
+
opt.separator " upload: upload an existing podcast feed to youtube"
|
16
|
+
opt.separator ""
|
17
|
+
opt.separator "Options"
|
18
|
+
|
19
|
+
opt.on("-f","--feedurl URL","podcast feed url") do |feedurl|
|
20
|
+
options[:feedurl] = feedurl
|
21
|
+
end
|
22
|
+
|
23
|
+
opt.on("-s","--clientsecretfile SECRET","path to the client_secret.json") do |clientsecretfile|
|
24
|
+
options[:clientsecretfile] = clientsecretfile
|
25
|
+
end
|
26
|
+
|
27
|
+
opt.on("-c","--videocategoryid ID","youtube video category id for the uploaded vides") do |videocategoryid|
|
28
|
+
options[:videocategoryid] = videocategoryid
|
29
|
+
end
|
30
|
+
|
31
|
+
opt.on("-h","--help","print this help") do
|
32
|
+
puts opt_parser
|
33
|
+
end
|
34
34
|
end
|
35
35
|
|
36
36
|
opt_parser.parse!
|
37
37
|
|
38
38
|
if ARGV[0] == "upload"
|
39
|
-
|
39
|
+
uploader = PodcastUploader.new
|
40
|
+
uploader.authenticate_youtube(options[:clientsecretfile])
|
41
|
+
uploader.upload(options[:feedurl], options[:videocategoryid])
|
40
42
|
else
|
41
|
-
|
43
|
+
puts opt_parser
|
42
44
|
end
|
data/lib/podcast-to-youtube.rb
CHANGED
@@ -7,28 +7,32 @@ require 'rubygems'
|
|
7
7
|
require 'json'
|
8
8
|
|
9
9
|
class PodcastUploader
|
10
|
-
def self.upload(podcast_feed_url, client_secret_file_path = 'client_secret.json', video_category_id = '28')
|
11
|
-
|
12
|
-
if File.file?(client_secret_file_path)
|
13
|
-
client_secret = JSON.parse(File.read(client_secret_file_path))
|
14
|
-
else
|
15
|
-
raise "Please provide client_secret.json. This is required for the Youtube API authentication. More information can be found in the Readme."
|
16
|
-
end
|
17
10
|
|
18
|
-
|
19
|
-
|
11
|
+
@client_secret
|
12
|
+
@client_secret_file_path
|
13
|
+
@account
|
14
|
+
|
15
|
+
def authenticate_youtube(client_secret_file_path = 'client_secret.json')
|
16
|
+
load_configuration client_secret_file_path
|
20
17
|
|
21
18
|
puts "connecting to youtube account"
|
22
19
|
Yt.configure do |config|
|
23
|
-
|
24
|
-
|
20
|
+
config.client_id = @client_secret['installed']['client_id']
|
21
|
+
config.client_secret = @client_secret['installed']['client_secret']
|
22
|
+
end
|
23
|
+
# check for refresh token in config file
|
24
|
+
if !@client_secret['installed']['refresh_token'].nil?
|
25
|
+
puts "using refresh token"
|
26
|
+
authenticate_youtube_by_refresh_token
|
27
|
+
else
|
28
|
+
# otherwise authenticate with oauth2
|
29
|
+
authenticate_youtube_by_access_token
|
30
|
+
save_configuration
|
25
31
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
auth_code = gets.chomp
|
31
|
-
account = Yt::Account.new authorization_code: auth_code, redirect_uri: redirect_uri
|
32
|
+
end
|
33
|
+
|
34
|
+
def upload(podcast_feed_url, video_category_id, privacy = :private)
|
35
|
+
feed = parse_feed podcast_feed_url
|
32
36
|
|
33
37
|
feed.entries.reverse_each do |entry|
|
34
38
|
|
@@ -56,17 +60,17 @@ class PodcastUploader
|
|
56
60
|
|
57
61
|
if(convertCMD_status)
|
58
62
|
# upload to youtube
|
59
|
-
video_description =
|
63
|
+
video_description = generate_video_description(entry, feed)
|
60
64
|
video_title = "#{feed.title} - #{entry.title}"
|
61
|
-
if account.videos.any? {|video| video.title == video_title }
|
65
|
+
if @account.videos.any? {|video| video.title == video_title }
|
62
66
|
puts "do not upload video, as it is already online"
|
63
67
|
else
|
64
68
|
puts "uploading videofile to Youtube"
|
65
69
|
# refresh authentication if expired
|
66
|
-
if account.authentication.expired?
|
67
|
-
|
70
|
+
if @account.authentication.expired?
|
71
|
+
authenticate_youtube_by_refresh_token
|
68
72
|
end
|
69
|
-
account.upload_video videofile, privacy_status:
|
73
|
+
@account.upload_video videofile, privacy_status: privacy, title: video_title, description: video_description, category_id: video_category_id, tags: %w(podcast)
|
70
74
|
end
|
71
75
|
else
|
72
76
|
raise "generating videofile #{videofile} failed"
|
@@ -75,6 +79,60 @@ class PodcastUploader
|
|
75
79
|
raise "downloading audiofile or coverart failed"
|
76
80
|
end
|
77
81
|
end
|
78
|
-
|
79
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def authenticate_youtube_by_refresh_token
|
87
|
+
puts "reauthenticate youtube with refresh token"
|
88
|
+
begin
|
89
|
+
@account = Yt::Account.new refresh_token: @client_secret['installed']['refresh_token']
|
90
|
+
rescue
|
91
|
+
puts "authentication with refresh token failed"
|
92
|
+
authenticate_youtube_by_access_token
|
93
|
+
end
|
94
|
+
save_configuration
|
95
|
+
end
|
96
|
+
|
97
|
+
def authenticate_youtube_by_access_token
|
98
|
+
puts "authenticate youtube by access token"
|
99
|
+
redirect_uri = 'urn:ietf:wg:oauth:2.0:oob' # special redirect uri to make the user copy the auth_code to the application
|
100
|
+
puts "open this url in a browser"
|
101
|
+
puts Yt::Account.new(scopes: ['youtube'], redirect_uri: redirect_uri).authentication_url
|
102
|
+
puts "paste the authentication code here and press enter"
|
103
|
+
auth_code = STDIN.gets.chomp
|
104
|
+
@account = Yt::Account.new authorization_code: auth_code, redirect_uri: redirect_uri
|
105
|
+
end
|
106
|
+
|
107
|
+
def parse_feed(podcast_feed_url)
|
108
|
+
puts "parsing feed"
|
109
|
+
return Feedjira::Feed.fetch_and_parse podcast_feed_url
|
110
|
+
end
|
111
|
+
|
112
|
+
def load_configuration(file_path)
|
113
|
+
puts "loading configuration"
|
114
|
+
if File.file?(file_path)
|
115
|
+
@client_secret = JSON.parse(File.read(file_path))
|
116
|
+
@client_secret_file_path = file_path
|
117
|
+
else
|
118
|
+
raise "Could not find config file at #{file_path}. This is required for the Youtube API authentication. More information can be found in the Readme."
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def save_configuration
|
123
|
+
puts "saving current configuration"
|
124
|
+
@client_secret['installed']['refresh_token'] = @account.authentication.refresh_token
|
125
|
+
File.write(@client_secret_file_path, @client_secret.to_json)
|
126
|
+
end
|
127
|
+
|
128
|
+
def generate_video_description(entry, feed)
|
129
|
+
video_description = "#{entry.itunes_summary}\n\n"
|
130
|
+
video_description += "Mehr Infos und Links zur Episode: #{entry.url}\n"
|
131
|
+
video_description += "Veröffentlicht: #{entry.published}\n"
|
132
|
+
video_description += "Episode herunterladen (Audio): #{entry.url}\n\n"
|
133
|
+
video_description += "Podcast Webseite: #{feed.url}\n"
|
134
|
+
video_description += "Podcast Abonnieren: #{feed.url}\n"
|
135
|
+
video_description += "Podcast Author: #{feed.itunes_author}"
|
136
|
+
return video_description
|
137
|
+
end
|
80
138
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: podcast-to-youtube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Trauth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: feedjira
|
@@ -75,9 +75,9 @@ require_paths:
|
|
75
75
|
- lib
|
76
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - "
|
78
|
+
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
80
|
+
version: 1.9.3
|
81
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
83
|
- - ">="
|