Skip to content

Commit 43ef77e

Browse files
committed
Added : Merge Audio & Video Files into a one video, Delete Seperate FIles after merging.
1 parent fd3e10a commit 43ef77e

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,5 @@ cython_debug/
161161

162162
.mp4
163163
.mp3
164-
/vids
164+
/vids
165+
/outputs

FileChecker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import os
2+
print("\nCurrent Working Directory: ", os.getcwd())
3+
print( os.path.isfile('vids\Gwa Gwa Gwa Sound Effect.mp3') )
4+
5+
print("\n", os.path.join(os.getcwd(), "vids","Gwa Gwa Gwa Sound Effect.mp3"))

downloader.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pytube import YouTube
2-
import pathlib
2+
import os
3+
from modules import vidmerge
34

45

56
print(f"===============================\n Python YouTube Downloader v2.0\n===============================\n")
@@ -10,31 +11,33 @@
1011

1112
yt = YouTube(videoURL)
1213

14+
mediaPath = f"{os.getcwd()}/vids"
1315

14-
print("-------VIDEOS-------")
15-
16+
# print("-------VIDEOS-------")
1617
for count, stream in enumerate(yt.streams.filter(only_video=True, mime_type="video/mp4"), start=1):
1718
print(f"{count}) Res: {stream.resolution} | Size:{stream.filesize_mb} mb")
1819
# print(stream)
1920

2021
userInput = input(str("Enter Res: "))
2122

2223
for stream in yt.streams.filter(only_video=True, mime_type="video/mp4", res=userInput):
23-
stream.download(filename=f"{yt.title}.mp4", output_path=f"{pathlib.Path(__file__).parent.resolve()}/vids")
24+
stream.download(filename=f"{yt.title}.mp4", output_path=mediaPath)
2425
print(userInput, ": MP4 Downloaded.✔")
2526

2627

2728

28-
print("-------AUDIOS-------")
29-
29+
# print("-------AUDIOS-------")
3030
for stream in yt.streams.filter(only_audio=True, abr="128kbps"):
31-
stream.download(filename=f"{yt.title}.mp3", output_path=f"{pathlib.Path(__file__).parent.resolve()}/vids")
31+
stream.download(filename=f"{yt.title}.mp3", output_path=mediaPath)
3232
print(stream.abr,": MP3 Downloaded. ✔")
3333

34-
35-
3634

35+
# Merge the Audio & Video File
36+
vidmerge.merge(title=yt.title)
3737

38+
# Remove Seperate Media Files
39+
os.remove(f"{mediaPath}/{yt.title}.mp4")
40+
os.remove(f"{mediaPath}/{yt.title}.mp3")
3841

3942

4043

modules/vidmerge.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
import os
3+
from moviepy.editor import VideoFileClip, AudioFileClip
4+
5+
def merge(title):
6+
7+
input_video = os.path.join(os.getcwd(), "vids",f"{title}.mp4")
8+
input_audio = os.path.join(os.getcwd(), "vids",f"{title}.mp3")
9+
10+
# Load the video and audio clips
11+
video_clip = VideoFileClip(input_video)
12+
audio_clip = AudioFileClip(input_audio)
13+
14+
# Combine them
15+
final_clip = video_clip.set_audio(audio_clip)
16+
17+
# Write the final clip to a new file
18+
final_clip.write_videofile(f"vids/{title} output.mp4", codec="libx264")
19+
20+
21+
22+
23+
24+
25+
26+
27+

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
yt_dlp==2023.12.30
1+
ffmpeg_python==0.2.0
2+
python_ffmpeg==2.0.10
3+
pytube==15.0.0

0 commit comments

Comments
 (0)