-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
196 lines (170 loc) Β· 7.3 KB
/
main.go
File metadata and controls
196 lines (170 loc) Β· 7.3 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Package main is the entry point for the gopherupload application.
// This CLI application allows users to upload videos to YouTube
// after authenticating with Google.
package main
import (
"fmt"
"os"
"github.com/charmbracelet/lipgloss"
"github.com/rajathjn/gopherupload/cmd/auth"
"github.com/rajathjn/gopherupload/cmd/uploader"
)
// Define styles for the CLI interface
var (
titleStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#FF5F87")).
Border(lipgloss.RoundedBorder()).
Padding(0, 1).
MarginBottom(1)
subtitleStyle = lipgloss.NewStyle().
Italic(true).
Foreground(lipgloss.Color("#5F87FF"))
commandStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#5FFFAF"))
optionStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#FFFF87"))
descriptionStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#D7D7D7"))
errorStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#FF0000"))
successStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#00FF00"))
)
// main is the entry point of the application.
// It parses command-line arguments and routes to the appropriate handlers.
func main() {
args := os.Args[1:]
if len(args) == 0 {
printUsage()
os.Exit(1)
}
switch args[0] {
case "login":
fmt.Println(subtitleStyle.Render("π Starting Google authentication process..."))
if err := auth.Login(); err != nil {
fmt.Println(errorStyle.Render(fmt.Sprintf("Login error: %v", err)))
os.Exit(1)
}
fmt.Println(successStyle.Render("π Login successful! You're ready to upload videos!"))
case "upload":
if len(args) < 2 {
fmt.Println(errorStyle.Render("Error: Please specify a directory path"))
fmt.Println(descriptionStyle.Render("Usage: gopherupload upload <directory>"))
os.Exit(1)
}
handleUpload(args[1])
case "help":
printExtendedHelp()
default:
printUsage()
os.Exit(1)
}
}
// printUsage displays styled help information showing available commands and options.
func printUsage() {
fmt.Println(commandStyle.Render("Usage:"), descriptionStyle.Render("gopherupload <command> [options]"))
fmt.Println()
fmt.Println(commandStyle.Render("Commands:"))
fmt.Println(optionStyle.Render(" - login:"), descriptionStyle.Render("Authenticate with Google (you'll need this first!)"))
fmt.Println(optionStyle.Render(" - upload <directory>:"), descriptionStyle.Render("Upload a video from the specified directory"))
fmt.Println(descriptionStyle.Render(" The directory should contain:"))
fmt.Println(descriptionStyle.Render(" - One .mp4 video file (required)"))
fmt.Println(descriptionStyle.Render(" - metadata.json with YouTube settings (optional)"))
fmt.Println(descriptionStyle.Render(" - thumbnail.png for custom thumbnail (optional)"))
fmt.Println(optionStyle.Render(" - help:"), descriptionStyle.Render("Show extended help with examples"))
fmt.Println()
fmt.Println(subtitleStyle.Render("π‘ Tip:"), descriptionStyle.Render("Start with 'gopherupload login' to authenticate!"))
}
// printExtendedHelp displays detailed help information with examples
func printExtendedHelp() {
fmt.Println(titleStyle.Render("π¬ GopherUpload - YouTube Video Uploader"))
fmt.Println(subtitleStyle.Render("A simple CLI tool to upload videos to YouTube with metadata and scheduling support"))
fmt.Println()
fmt.Println(commandStyle.Render("How It Works:"))
fmt.Println(descriptionStyle.Render("1. First, authenticate with Google using 'gopherupload login'"))
fmt.Println(descriptionStyle.Render("2. Prepare your video directory with:"))
fmt.Println(descriptionStyle.Render(" - A single .mp4 video file"))
fmt.Println(descriptionStyle.Render(" - Optional: metadata.json for title, description, tags, schedule"))
fmt.Println(descriptionStyle.Render(" - Optional: thumbnail.png for custom thumbnail"))
fmt.Println(descriptionStyle.Render("3. Upload with 'gopherupload upload <directory>'"))
fmt.Println()
fmt.Println(commandStyle.Render("Examples:"))
fmt.Println(optionStyle.Render("- Upload a video:"))
fmt.Println(descriptionStyle.Render(" gopherupload upload \"outputs/Procedural Zen #14\""))
fmt.Println()
fmt.Println(commandStyle.Render("metadata.json Format:"))
fmt.Println(descriptionStyle.Render(` {
"youtube": {
"title": "My Video Title",
"description": "Video description here",
"tags": ["tag1", "tag2"],
"hashtags": ["#shorts", "#tutorial"],
"schedule": {
"publish_date": "2025-12-31",
"publish_time": "10:00"
}
}
}`))
fmt.Println()
fmt.Println(commandStyle.Render("Fallback Behavior:"))
fmt.Println(descriptionStyle.Render("- If metadata.json is missing, the video filename becomes the title"))
fmt.Println(descriptionStyle.Render("- If schedule is missing or in the past, video uploads as public immediately"))
fmt.Println(descriptionStyle.Render("- Empty fields use defaults from config.json"))
fmt.Println()
fmt.Println(commandStyle.Render("Troubleshooting:"))
fmt.Println(descriptionStyle.Render("- If you encounter authentication issues, try 'gopherupload login' again"))
fmt.Println(descriptionStyle.Render("- Make sure your directory contains exactly one .mp4 file"))
fmt.Println()
}
// handleUpload processes the upload command.
// It detects files in the directory and initiates the upload process.
func handleUpload(dirPath string) {
fmt.Println(subtitleStyle.Render("π Preparing to upload video..."))
// Detect files in the directory
videoPath, metadataPath, thumbnailPath, err := uploader.DetectFiles(dirPath)
if err != nil {
fmt.Println(errorStyle.Render(fmt.Sprintf("Error: %v", err)))
os.Exit(1)
}
fmt.Println(optionStyle.Render("πΉ Video:"), descriptionStyle.Render(videoPath))
if metadataPath != "" {
fmt.Println(optionStyle.Render("π Metadata:"), descriptionStyle.Render(metadataPath))
} else {
fmt.Println(optionStyle.Render("π Metadata:"), descriptionStyle.Render("Not found, using filename as title"))
}
if thumbnailPath != "" {
fmt.Println(optionStyle.Render("πΌοΈ Thumbnail:"), descriptionStyle.Render(thumbnailPath))
}
// Load metadata (or generate from filename)
metadata, err := uploader.LoadMetadata(metadataPath, videoPath)
if err != nil {
fmt.Println(errorStyle.Render(fmt.Sprintf("Error loading metadata: %v", err)))
os.Exit(1)
}
fmt.Println()
fmt.Println(subtitleStyle.Render("π Upload Details:"))
fmt.Println(optionStyle.Render(" Title:"), descriptionStyle.Render(metadata.Title))
if metadata.Description != "" {
fmt.Println(optionStyle.Render(" Description:"), descriptionStyle.Render(metadata.Description))
}
if len(metadata.Tags) > 0 {
fmt.Println(optionStyle.Render(" Tags:"), descriptionStyle.Render(fmt.Sprintf("%v", metadata.Tags)))
}
if metadata.ScheduledTime != nil {
fmt.Println(optionStyle.Render(" Scheduled:"), descriptionStyle.Render(metadata.ScheduledTime.Format("2006-01-02 15:04 MST")))
} else {
fmt.Println(optionStyle.Render(" Privacy:"), descriptionStyle.Render("public (immediate)"))
}
fmt.Println()
// Perform the upload
fmt.Println(subtitleStyle.Render("β¬οΈ Uploading to YouTube..."))
if err := uploader.UploadVideo(videoPath, thumbnailPath, metadata); err != nil {
fmt.Println(errorStyle.Render(fmt.Sprintf("Upload failed: %v", err)))
os.Exit(1)
}
fmt.Println(successStyle.Render("π Upload completed successfully!"))
}