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)
|
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')
|
final_clip.write_videofile(output_path, codec='libx264', fps=24, audio_codec='aac')
|
||||||
print(f"Video created: {output_path}")
|
print(f"Video created: {output_path}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -44,12 +43,11 @@ def get_authenticated_service():
|
|||||||
os.remove('token.json')
|
os.remove('token.json')
|
||||||
creds = None
|
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 not creds or not creds.valid:
|
||||||
if creds and creds.expired and creds.refresh_token:
|
if creds and creds.expired and creds.refresh_token:
|
||||||
creds.refresh(Request())
|
creds.refresh(Request())
|
||||||
else:
|
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')
|
creds = flow.run_local_server(port=8080, access_type='offline', prompt='consent')
|
||||||
with open('token.json', 'w') as token:
|
with open('token.json', 'w') as token:
|
||||||
token.write(creds.to_json())
|
token.write(creds.to_json())
|
||||||
@@ -83,17 +81,14 @@ def upload_video_to_youtube(youtube, video_file, title, category='10', privacy_s
|
|||||||
def main():
|
def main():
|
||||||
base_dir = os.path.dirname(os.path.abspath(__file__))
|
base_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
# Get image files (for example: .jpg, .jpeg, .png)
|
|
||||||
image_extensions = ('.jpg', '.jpeg', '.png')
|
image_extensions = ('.jpg', '.jpeg', '.png')
|
||||||
image_files = [f for f in os.listdir(base_dir) if f.lower().endswith(image_extensions)]
|
image_files = [f for f in os.listdir(base_dir) if f.lower().endswith(image_extensions)]
|
||||||
if not image_files:
|
if not image_files:
|
||||||
print("Error: No image file found!")
|
print("Error: No image file found!")
|
||||||
return
|
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])
|
image_file = os.path.join(base_dir, image_files[0])
|
||||||
print(f"Found image: {image_file}")
|
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')]
|
mp3_files = [f for f in os.listdir(base_dir) if f.lower().endswith('.mp3')]
|
||||||
if not mp3_files:
|
if not mp3_files:
|
||||||
print("Error: No MP3 file not found!")
|
print("Error: No MP3 file not found!")
|
||||||
@@ -102,7 +97,6 @@ def main():
|
|||||||
output_folder = os.path.join(base_dir, "videos")
|
output_folder = os.path.join(base_dir, "videos")
|
||||||
os.makedirs(output_folder, exist_ok=True)
|
os.makedirs(output_folder, exist_ok=True)
|
||||||
|
|
||||||
# Run OAuth authorization feed once and create the YouTube service.
|
|
||||||
youtube_service = get_authenticated_service()
|
youtube_service = get_authenticated_service()
|
||||||
|
|
||||||
for mp3 in mp3_files:
|
for mp3 in mp3_files:
|
||||||
@@ -124,3 +118,4 @@ def main():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user