Skip to content

Commit

Permalink
close video after conversion from mp4 to mp3
Browse files Browse the repository at this point in the history
  • Loading branch information
irahorecka committed Feb 25, 2024
1 parent be605bc commit cfd0f8f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ def run(self):
for index, key_value in enumerate(self.videos_dict.items()) # dict is naturally sorted in iteration
)
utils.map_threads(utils.thread_query_youtube, video_properties)
time.sleep(1)
shutil.rmtree(mp4_path) # remove mp4 dir
time1 = time.time()

Expand Down
2 changes: 0 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test functions in utils/ directory"""
import os
import sys
import time
import unittest

# get base directory and import util files
Expand Down Expand Up @@ -207,7 +206,6 @@ def tearDown(self):

if os.path.exists(self.test_mp4_dirpath):
# remove mp4 dir if it exists
time.sleep(1)
shutil.rmtree(self.test_mp4_dirpath)

# TODO: add tests for mp3 and mp4 annotations -- above tests are for high-level functions.
Expand Down
6 changes: 4 additions & 2 deletions utils/download_youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_youtube_mp4():
# remove illegal characters from song title - otherwise clipped by pytube
for char in illegal_char:
mp4_filename = mp4_filename.replace(char, "")

mp4_filename += ".mp4" # add extension for downstream file recognition
stream.download(mp4_path, filename=f"{mp4_filename}")
if save_as_mp4:
Expand All @@ -72,9 +72,11 @@ def get_youtube_mp3(mp4_filename):
try:
video = VideoFileClip(os.path.join(mp4_path, mp4_filename))
video.audio.write_audiofile(os.path.join(download_path, mp3_filename))
set_song_metadata(download_path, song_properties, mp3_filename, False)
except Exception as e:
print(e)
set_song_metadata(download_path, song_properties, mp3_filename, False)
finally:
video.close()

return get_youtube_mp4()

Expand Down

0 comments on commit cfd0f8f

Please sign in to comment.