diff --git a/src/artbox/videos.py b/src/artbox/videos.py index e705279..f1f1b09 100644 --- a/src/artbox/videos.py +++ b/src/artbox/videos.py @@ -6,7 +6,7 @@ from abc import abstractmethod from moviepy.editor import AudioFileClip, VideoFileClip -from pytube import YouTube +from pytube import YouTube as PyYouTube from artbox.base import ArtBox @@ -31,7 +31,7 @@ def download(self): if not video_url: raise Exception("Argument `url` not given.") - video = YouTube(video_url) + video = PyYouTube(video_url) # Filter the stream by resolution if provided, # else get the highest resolution diff --git a/tests/__pycache__/__init__.cpython-311.pyc b/tests/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index 2bf1d76..0000000 Binary files a/tests/__pycache__/__init__.cpython-311.pyc and /dev/null differ diff --git a/tests/__pycache__/test_sounds.cpython-311-pytest-7.4.0.pyc b/tests/__pycache__/test_sounds.cpython-311-pytest-7.4.0.pyc deleted file mode 100644 index 154fb5c..0000000 Binary files a/tests/__pycache__/test_sounds.cpython-311-pytest-7.4.0.pyc and /dev/null differ diff --git a/tests/__pycache__/test_video.cpython-311-pytest-7.4.0.pyc b/tests/__pycache__/test_video.cpython-311-pytest-7.4.0.pyc deleted file mode 100644 index f044449..0000000 Binary files a/tests/__pycache__/test_video.cpython-311-pytest-7.4.0.pyc and /dev/null differ diff --git a/tests/__pycache__/test_videos.cpython-311-pytest-7.4.0.pyc b/tests/__pycache__/test_videos.cpython-311-pytest-7.4.0.pyc deleted file mode 100644 index 84ee412..0000000 Binary files a/tests/__pycache__/test_videos.cpython-311-pytest-7.4.0.pyc and /dev/null differ diff --git a/tests/data/audios/pixabay-science.mp3 b/tests/data/audios/pixabay-science.mp3 new file mode 100644 index 0000000..bd5453f Binary files /dev/null and b/tests/data/audios/pixabay-science.mp3 differ diff --git a/tests/data/notes/set1.txt b/tests/data/notes/set1.txt new file mode 100644 index 0000000..750bdf8 --- /dev/null +++ b/tests/data/notes/set1.txt @@ -0,0 +1 @@ +["E", "D#", "E", "D#", "E", "B", "D", "C", "A"] diff --git a/tests/data/videos/pixabay-fuji.mp4 b/tests/data/videos/pixabay-fuji.mp4 new file mode 100644 index 0000000..ae7582e Binary files /dev/null and b/tests/data/videos/pixabay-fuji.mp4 differ diff --git a/tests/test_sounds.py b/tests/test_sounds.py index 7d5d0b0..c0ea165 100644 --- a/tests/test_sounds.py +++ b/tests/test_sounds.py @@ -1,4 +1,7 @@ """Set of tests for the sounds module.""" +import os +import unittest + from pathlib import Path import pytest @@ -6,45 +9,61 @@ from artbox.sounds import Sound TMP_PATH = Path("/tmp/artbox") +TEST_DATA_DIR = Path(__file__).parent / "data" +os.makedirs(TMP_PATH, exist_ok=True) -@pytest.mark.fixture -def sound(): - """Create a fixture for the Sound object.""" - return Sound() +def test_notes_to_audio(): + """Test the extraction of notes from mp3 file.""" + mp3_path = TMP_PATH / "set1.mp3" + notes_path = TEST_DATA_DIR / "notes" / "set1.txt" -@pytest.mark.skip -def test_extract(sound): - """Test the extraction audio from a video.""" - videos_path = TMP_PATH / "Super Mario Theme EPIC VERSION.mp4" - output_path = TMP_PATH / "sounds" / "smb-epic-theme.mp3" - sound.extract_audio(str(videos_path), str(output_path)) + params = { + "input-path": notes_path, + "output-path": mp3_path, + "duration": 2, + } + sound = Sound(params) + sound.notes_to_audio() -@pytest.mark.skip -def test_extract_notes_from_mp3(sound): +@unittest.skip("not fully implemented") +def test_extract_notes_from_mp3(): """Test the extraction of notes from mp3 file.""" - mp3_path = TMP_PATH / "sounds" / "tok-audio.mp3" - output_notes = TMP_PATH / "notes" / "tok-audio.txt" - notes = sound.extract_notes_from_mp3(str(mp3_path), str(output_notes)) + filename = "pixabay-science" + mp3_path = TEST_DATA_DIR / "audio" / f"{filename}.mp3" + output_notes = TMP_PATH / "notes" / f"{filename}.txt" + params = { + "input-path": mp3_path, + "output-path": output_notes, + } + sound = Sound(params) + notes = sound.extract_notes_from_mp3() print("Detected notes:", notes) -@pytest.mark.skip -def test_generate_melody(sound): +@unittest.skip("not fully implemented") +def test_generate_melody(): """Test the melody generation from notes.""" notes_path = TMP_PATH / "notes" / "tok-audio.txt" - sound.generate_melody(notes_path, total_duration=3.54 * 60) + params = { + "input-path": notes_path, + "output-path": "/tmp/artbox/sound.mp3", + "duration": 3.54 * 60, + } + sound = Sound(params) + sound.generate_melody() -@pytest.mark.skip -def test_convert_to_8bit_audio(sound): +@unittest.skip("not fully implemented") +def test_convert_to_8bit_audio(): """Test the audio conversion to 8bits style.""" - videos_path = ( - TMP_PATH - / "videos" - / "The Legend of Zelda Tears of the Kingdom - Official Trailer 3.mp4" - ) + input_path = TEST_DATA_DIR / "audio" / "pixabay-science.mp3" output_path = TMP_PATH / "sounds" / "tok8bits.mp3" - sound.convert_to_8bit_audio(str(videos_path), str(output_path)) + params = { + "input-path": mp3_path, + "output-path": output_notes, + } + sound = Sound(params) + sound.convert_to_8bit_audio() diff --git a/tests/test_videos.py b/tests/test_videos.py index 0d5c105..b67c813 100644 --- a/tests/test_videos.py +++ b/tests/test_videos.py @@ -1,48 +1,61 @@ """Set of tests for the videos module.""" +import os + from pathlib import Path import pytest -from artbox.videos import Video +from artbox.videos import Video, Youtube -TMP_PATH = Path("/tmp/artbox") +TMP_PATH = Path("/tmp/artbox") +TEST_DATA_DIR = Path(__file__).parent / "data" -@pytest.mark.fixture -def video(): - """Create a fixture for the Video object.""" - return Video() +os.makedirs(TMP_PATH, exist_ok=True) -@pytest.mark.skip -def test_combine_video_and_audio(video): +def test_combine_video_and_audio(): """Test the function that combines video and audio.""" # Example usage # "The Legend of Zelda Tears of the Kingdom - Official Trailer 3.mp4" - video_path = TMP_PATH / "peachs-no-audio.mp4" - audio_path = TMP_PATH / "smb-epic-theme.mp3" - output_path = TMP_PATH / "peachs-with-music.mp4" - video.combine_video_and_audio( - str(video_path), str(audio_path), str(output_path) - ) + video_path = TEST_DATA_DIR / "videos" / "pixabay-fuji.mp4" + audio_path = TEST_DATA_DIR / "audios" / "pixabay-science.mp3" + output_path = TMP_PATH / "video+audio.mp4" + + params = { + "video-path": str(video_path), + "audio-path": str(audio_path), + "output-path": str(output_path), + } + video = Video(params) + video.combine_video_and_audio() -@pytest.mark.skip -def test_download_from_youtube(video): +def test_download_from_youtube(): """Test the method that downloads videos from youtube.""" # "https://www.youtube.com/watch?v=uHGShqcAHlQ" - for url in [ - "https://youtube.com/shorts/gmutDetnBLQ", - "https://youtube.com/watch?v=6pjbaE98ftU", - ]: - video.download_from_youtube(url) - - -@pytest.mark.skip -def test_remove_audio(video): + for i, url in enumerate( + [ + "https://youtube.com/shorts/gmutDetnBLQ", + "https://youtube.com/watch?v=6pjbaE98ftU", + ] + ): + params = {"output-path": TMP_PATH, "url": url} + youtube = Youtube(params) + youtube.download() + + +def test_remove_audio(): """Test the function that removes audio from a video.""" input_file = TMP_PATH / ( "Princess Peachs Training Course in The Super Mario Bros Movie.mp4" ) output_file = "peachs-no-audio.mp4" - video.remove_audio(input_file, TMP_PATH / output_file) + + params = { + "input-path": TEST_DATA_DIR / "videos" / "pixabay-fuji.mp4", + "output-path": TMP_PATH / "video-with-no-audio.mp4", + } + + video = Video(params) + video.remove_audio()