forked from RayVentura/ShortGPT
-
Notifications
You must be signed in to change notification settings - Fork 3
/
final_upload.py
36 lines (30 loc) · 1.47 KB
/
final_upload.py
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
import re
import os
from typing_extensions import Text
directory = "videos/"
file_names = os.listdir(directory)
# Filter files that are txt or mp4
file_names = [f for f in file_names if os.path.isfile(os.path.join(directory, f)) and (f.endswith('.txt') or f.endswith('.mp4'))]
# Sort the file names by modification time in descending order
file_names.sort(key=lambda x: os.path.getmtime(os.path.join(directory, x)), reverse=True)
# Get the latest txt and mp4 file names
latest_files = {}
for file in file_names:
if file.endswith('.txt') and 'txt' not in latest_files:
latest_files['txt'] = file
elif file.endswith('.mp4') and 'mp4' not in latest_files:
latest_files['mp4'] = file
if len(latest_files) == 2:
break
# Get the text file content and extract title and description
text_file = latest_files.get('txt')
video_file = latest_files.get('mp4')
with open(os.path.join(directory, text_file), 'r') as file:
content = file.read()
title_match = re.search(r'---Youtube title---\n(.*?)\n', content, flags=re.DOTALL)
title = title_match.group(1) if title_match else None
description_match = re.search(r'---Youtube description---\n([\s\S]*)', content)
description = description_match.group(1) if description_match else None
# Run the upload script with the latest mp4 and txt files
if video_file and text_file:
os.system(f'python3 upload.py --file="{directory}{video_file}" --privacyStatus="public" --title="{title}" --description="{description}"')