This repository contains a Python script for downloading and playing audio from YouTube Music using the yt-dlp
and ytmusicapi
libraries. The program enables users to search for songs on YouTube Music, download the audio in .wav
format, and play the audio locally.
- Song Search: Search for songs on YouTube Music using the song's name.
- Audio Download: Download the audio in
.wav
format from the most relevant song result. - Audio Playback: Play the downloaded
.wav
file using theplaysound
module. - Download Folder Customization: Set a custom folder where downloaded audio files will be saved.
Before using this script, you need to install the following Python libraries:
yt-dlp
ytmusicapi
playsound
ffmpeg
You also need to have ffmpeg
installed and accessible via your system's PATH
. You can download ffmpeg
from here.
-
Clone this repository to your local machine:
git clone https://github.com/flaryx32/YTMusic-DL.git cd YTMusic-DL
-
Install the required Python libraries:
pip install yt-dlp ytmusicapi playsound
-
Download and install
ffmpeg
from ffmpeg.org. -
Make sure the
ffmpeg
executable is available in your system'sPATH
or provide the path to it when initializing the class.
-
Import the
YoutubeMusicDownloader
class:from YoutubeMusicDownloader import YoutubeMusicDownloader
-
Initialize the downloader, optionally providing a path to
ffmpeg
and a download folder:downloader = YoutubeMusicDownloader(ffmpeg_path='/path/to/ffmpeg', download_folder='/path/to/download/folder')
-
Use the
search_download_play
method to search for a song, download it, and play the audio:downloader.search_download_play("Song Title")
-
Set a custom download folder if needed:
downloader.set_download_folder("/path/to/new/download/folder")
downloader = YoutubeMusicDownloader()
downloader.search_download_play("Imagine by John Lennon")
downloader = YoutubeMusicDownloader()
downloader.set_download_folder("/Users/yourname/Music")
downloader.search_download_play("Bohemian Rhapsody by Queen")
downloader = YoutubeMusicDownloader(ffmpeg_path="/usr/local/bin/ffmpeg")
downloader.search_download_play("Shape of You by Ed Sheeran")
This software is intended for personal use only. It is the user's responsibility to ensure that their usage of this program complies with all local laws and regulations, including those related to downloading copyrighted content.
Downloading audio from YouTube Music or any other platform may violate the platform's terms of service. This project is for educational purposes, and the author does not endorse any illegal use of this software.
This code is released under a custom license that allows free private usage but prohibits modifications, commercial usage, and redistribution without explicit permission.
All rights to the code are owned by @flaryx32.
For contributions, please create a pull request. All changes should be tested locally before submitting.