-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube_upload.rb
executable file
·66 lines (57 loc) · 1.73 KB
/
youtube_upload.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env ruby1.9
# coding: utf-8
# Well this would indeed be a Makefile's work but make screws filenames with
# spaces and I don't want to learn rake.
require 'shellwords'
require 'yaml'
require File.dirname(__FILE__) + "/utils.rb"
yaml_file = 'uploads.yaml'
if File.exists? yaml_file
vids = YAML::load_file(yaml_file)
else
vids = []
end
added = false
Dir['**/*.{avi,mkv,mp4}'].each do |video|
unless vids.find {|v| v["file"] == video}
added = true
vids << {
"file" => video,
"title" => video.cut_ext,
"description" => "Timed by " + (
assname = video.sub(/(?<=\.)[^\.]+$/, "ass")
dir = Dir['/home/no/up/karaoke/*'].find { |dir|
Dir["#{dir}/**/*"].find {|name| File.basename(name) == File.basename(assname) }
}
dir ? File.basename(dir) : "anonymous"
),
"upload" => true,
}
end
end
vids.sort_by {|v| File.ctime v["file"] }
File.open(yaml_file, "w") {|f| f.print vids.to_yaml }
if added
puts "Found some new files; please review uploads.yaml before uploading."
exit
end
email = (ARGV[0] or (print "Email: "; gets.chomp.shellescape))
password = (ARGV[1] or (print "Password: "; gets.chomp.shellescape))
vids.each do |video|
next if video["uploaded"]
next unless video["upload"]
command = "youtube-upload #{email} #{password} "
command << video["file"].shellescape << " " << video["title"].shellescape << "' (karaoke)' "
command << video["description"].shellescape << " Music 'karaoke, anime'"
puts command
success = system(command)
if success
video["uploaded"] = true
File.open(yaml_file, "w") {|f| f.print vids.to_yaml }
sleep 600
else
puts "FAIL upload for video " + video["title"]
exit
end
end
# vim: shiftwidth=2:expandtab