Update main.py
This commit is contained in:
committed by
GitHub
parent
269492ad62
commit
68c63580ec
@@ -24,7 +24,6 @@ def create_video_from_media(image_path, audio_path, output_path):
|
||||
|
||||
final_clip = mp.CompositeVideoClip([background, image_clip]).set_audio(audio_clip)
|
||||
|
||||
# Video create and save settings
|
||||
final_clip.write_videofile(output_path, codec='libx264', fps=24, audio_codec='aac')
|
||||
print(f"Video created: {output_path}")
|
||||
except Exception as e:
|
||||
@@ -44,12 +43,11 @@ def get_authenticated_service():
|
||||
os.remove('token.json')
|
||||
creds = None
|
||||
|
||||
# If token is unavailable or invaild, start OAuth feed (offline access and by adding consent)
|
||||
if not creds or not creds.valid:
|
||||
if creds and creds.expired and creds.refresh_token:
|
||||
creds.refresh(Request())
|
||||
else:
|
||||
flow = InstalledAppFlow.from_client_secrets_file('client_secret.json', SCOPES)
|
||||
flow = InstalledAppFlow.from_client_secrets_file('client_secret.json', SCOPES) # You can change to how you'd like.
|
||||
creds = flow.run_local_server(port=8080, access_type='offline', prompt='consent')
|
||||
with open('token.json', 'w') as token:
|
||||
token.write(creds.to_json())
|
||||
@@ -83,17 +81,14 @@ def upload_video_to_youtube(youtube, video_file, title, category='10', privacy_s
|
||||
def main():
|
||||
base_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Get image files (for example: .jpg, .jpeg, .png)
|
||||
image_extensions = ('.jpg', '.jpeg', '.png')
|
||||
image_files = [f for f in os.listdir(base_dir) if f.lower().endswith(image_extensions)]
|
||||
if not image_files:
|
||||
print("Error: No image file found!")
|
||||
return
|
||||
# We are going to use first image file which is we found on the same directory.
|
||||
image_file = os.path.join(base_dir, image_files[0])
|
||||
print(f"Found image: {image_file}")
|
||||
|
||||
# We are going to use all of audio files which is we found on the same directory.
|
||||
mp3_files = [f for f in os.listdir(base_dir) if f.lower().endswith('.mp3')]
|
||||
if not mp3_files:
|
||||
print("Error: No MP3 file not found!")
|
||||
@@ -102,7 +97,6 @@ def main():
|
||||
output_folder = os.path.join(base_dir, "videos")
|
||||
os.makedirs(output_folder, exist_ok=True)
|
||||
|
||||
# Run OAuth authorization feed once and create the YouTube service.
|
||||
youtube_service = get_authenticated_service()
|
||||
|
||||
for mp3 in mp3_files:
|
||||
@@ -124,3 +118,4 @@ def main():
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user