-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_pipeline.py
More file actions
215 lines (185 loc) · 6.61 KB
/
Copy pathrun_pipeline.py
File metadata and controls
215 lines (185 loc) · 6.61 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env python3
"""
Command-line interface for YouTube to Shorts pipeline
"""
import argparse
import os
import sys
from clips import YouTubeToShortsPipeline
from config import PROCESSING_CONFIG
def main():
parser = argparse.ArgumentParser(
description="YouTube to Shorts Pipeline - Convert long videos to engaging short clips"
)
# Input options - either URLs or file paths
input_group = parser.add_mutually_exclusive_group(required=True)
input_group.add_argument(
"--podcast-url", "-pu",
type=str,
help="YouTube URL for podcast video"
)
input_group.add_argument(
"--podcast", "-p",
type=str,
help="Path to podcast video file"
)
input_group.add_argument(
"--gameplay-url", "-gu",
type=str,
help="YouTube URL for gameplay video"
)
input_group.add_argument(
"--gameplay", "-g",
type=str,
help="Path to gameplay video file"
)
# Combined URL option
parser.add_argument(
"--podcast-youtube", "-py",
type=str,
help="YouTube URL for podcast video (alternative to --podcast-url)"
)
parser.add_argument(
"--gameplay-youtube", "-gy",
type=str,
help="YouTube URL for gameplay video (alternative to --gameplay-url)"
)
# Other options
parser.add_argument(
"--clips", "-n",
type=int,
default=PROCESSING_CONFIG["num_clips"],
help=f"Number of clips to generate (default: {PROCESSING_CONFIG['num_clips']})"
)
parser.add_argument(
"--output-dir", "-o",
type=str,
default="outputs",
help="Output directory for generated clips (default: outputs)"
)
parser.add_argument(
"--verbose", "-v",
action="store_true",
help="Enable verbose output"
)
parser.add_argument(
"--interactive", "-i",
action="store_true",
help="Run in interactive mode (prompt for URLs)"
)
args = parser.parse_args()
# Handle interactive mode
if args.interactive:
from clips import get_user_input
podcast_url, gameplay_url, num_clips = get_user_input()
# Initialize pipeline
pipeline = YouTubeToShortsPipeline()
# Download videos
print(f"\n📥 Downloading videos...")
podcast_path = pipeline.download_youtube_video(
podcast_url,
os.path.join(pipeline.project_root, "savedVideos"),
"podcast"
)
gameplay_path = pipeline.download_youtube_video(
gameplay_url,
os.path.join(pipeline.project_root, "gamePlayVid"),
"gameplay"
)
# Run pipeline
print(f"\n🚀 Starting pipeline...")
generated_clips = pipeline.process_pipeline(
podcast_path,
gameplay_path,
num_clips=num_clips
)
if generated_clips:
print(f"\n✅ Successfully generated {len(generated_clips)} short videos!")
print("\nGenerated clips:")
for i, clip_path in enumerate(generated_clips, 1):
print(f" {i}. {clip_path}")
else:
print("\n⚠️ No clips were generated. Try with different videos or check the logs.")
return
# Determine podcast and gameplay sources
podcast_source = args.podcast_url or args.podcast_youtube or args.podcast
gameplay_source = args.gameplay_url or args.gameplay_youtube or args.gameplay
if not podcast_source or not gameplay_source:
print("❌ Error: You must provide both podcast and gameplay sources")
print("Use --help for usage information")
sys.exit(1)
# Initialize pipeline
pipeline = YouTubeToShortsPipeline()
# Set output directory
if args.output_dir != "outputs":
pipeline.project_root = args.output_dir
pipeline.setup_directories()
print("🎬 YouTube to Shorts Pipeline")
print("=" * 40)
# Handle podcast source
if args.podcast_url or args.podcast_youtube:
podcast_url = args.podcast_url or args.podcast_youtube
print(f"Podcast URL: {podcast_url}")
try:
podcast_path = pipeline.download_youtube_video(
podcast_url,
os.path.join(pipeline.project_root, "savedVideos"),
"podcast"
)
except Exception as e:
print(f"❌ Error downloading podcast: {e}")
sys.exit(1)
else:
podcast_path = args.podcast
if not os.path.exists(podcast_path):
print(f"❌ Error: Podcast video not found: {podcast_path}")
sys.exit(1)
print(f"Podcast file: {podcast_path}")
# Handle gameplay source
if args.gameplay_url or args.gameplay_youtube:
gameplay_url = args.gameplay_url or args.gameplay_youtube
print(f"Gameplay URL: {gameplay_url}")
try:
gameplay_path = pipeline.download_youtube_video(
gameplay_url,
os.path.join(pipeline.project_root, "gamePlayVid"),
"gameplay"
)
except Exception as e:
print(f"❌ Error downloading gameplay: {e}")
sys.exit(1)
else:
gameplay_path = args.gameplay
if not os.path.exists(gameplay_path):
print(f"❌ Error: Gameplay video not found: {gameplay_path}")
sys.exit(1)
print(f"Gameplay file: {gameplay_path}")
print(f"Clips to generate: {args.clips}")
print(f"Output directory: {args.output_dir}")
print("=" * 40)
try:
# Run pipeline
generated_clips = pipeline.process_pipeline(
podcast_path,
gameplay_path,
num_clips=args.clips
)
if generated_clips:
print(f"\n✅ Successfully generated {len(generated_clips)} short videos!")
print("\nGenerated clips:")
for i, clip_path in enumerate(generated_clips, 1):
print(f" {i}. {clip_path}")
print(f"\n📁 All clips saved to: {args.output_dir}")
else:
print("\n⚠️ No clips were generated. Try with different videos or check the logs.")
except KeyboardInterrupt:
print("\n⚠️ Pipeline interrupted by user")
sys.exit(1)
except Exception as e:
print(f"\n❌ Error running pipeline: {e}")
if args.verbose:
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()