forked from porjo/youtubeuploader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
85 lines (77 loc) · 1.79 KB
/
log.go
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"strings"
youtube "google.golang.org/api/youtube/v3"
)
func printfString(msg string, val string) {
if val != "" {
fmt.Printf(msg, val)
}
}
func logf(msg string, a ...interface{}) {
if f.Log {
fmt.Printf(msg, a...)
}
}
func logfString(msg string, val string) {
if f.Log && val != "" {
fmt.Printf(msg, val)
}
}
func videoBasics(o *youtube.Video) string {
var ans = ""
p := o.Snippet
s := o.Status
if p.DefaultLanguage != "" {
ans += fmt.Sprintf(", &%v", p.DefaultLanguage)
}
if p.CategoryId != "" {
ans += fmt.Sprintf(", #%v", p.CategoryId)
}
if s.PrivacyStatus != "" {
ans += fmt.Sprintf(", :%v", s.PrivacyStatus)
}
if s.License != "" {
ans += fmt.Sprintf(", $%v", s.License)
} else {
ans += fmt.Sprintf(", $%v", "standard")
}
if s.PublicStatsViewable {
ans += ", public stats"
} else {
ans += ", private stats"
}
if s.PublishAt != "" {
ans += fmt.Sprintf(", T:%v", s.PublishAt)
}
if ans != "" {
ans = ans[2:]
}
return ans
}
func videoRecordingDetails(o *youtube.VideoRecordingDetails) string {
var ans = ""
if o.LocationDescription != "" {
ans += fmt.Sprintf(" \"%v\"", o.LocationDescription)
}
if o.Location != nil {
ans += fmt.Sprintf(" (%v, %v)", o.Location.Latitude, o.Location.Longitude)
}
if o.RecordingDate != "" {
ans += fmt.Sprintf(" on %v", o.RecordingDate)
}
return ans
}
func logUploadFlags(y *youtube.Video) {
if !f.Log {
return
}
fmt.Printf("%v\n", y.Snippet.Title)
fmt.Printf(" - %v\n", videoBasics(y))
printfString(" @%v\n", videoRecordingDetails(y.RecordingDetails))
fmt.Printf(" - %v\n", shortString(strings.Join(y.Snippet.Tags, ","), 60))
printfString("\n%v\n\n", shortString(y.Snippet.Description, 256))
printfString(" -> id: %v\n", f.ClientID)
printfString(" -> token: %v\n\n", f.ClientToken)
}