This project is a Python-based alarm clock that plays music from a YouTube playlist. The script downloads the audio from the playlist, stores it locally, and plays it at the specified alarm time using VLC media player. It also includes robust handling for metadata management, asynchronous downloading, and validation of downloaded files.
- Download and Store Audio: Downloads audio from a YouTube playlist and stores it locally in high-quality MP3 format.
- Metadata Management: Automatically adds ID3 tags (title, artist, album) to downloaded MP3 files.
- Redundant Download Avoidance: Checks if audio has already been downloaded to avoid redundant downloads.
- Asynchronous Operations: Monitors the playlist and downloads new songs asynchronously.
- Playlist Management: Maintains a buffer of songs to ensure continuous playback without interruptions.
- Alarm Triggered Playback: Plays music at a specified alarm time, optionally starting with a set number of pre-downloaded songs.
- File Validation: Optionally validate the integrity of MP3 files in the music library.
- VLC Integration: Uses VLC media player for non-blocking audio playback with the ability to manage and monitor the playlist.
- Python 3.x
- Conda
yt-dlp
requests
ffmpeg
- VLC media player
mutagen
(for metadata handling)psutil
(for process management)
git clone https://github.com/yourusername/youtube-alarm-clock.git
cd youtube-alarm-clock
Run the provided bash script to create the Conda environment and install the necessary libraries:
./create_youtube_alarm_env.sh
If you prefer to install the dependencies manually, follow these steps:
-
Create a new Conda environment and install Python:
conda create --name youtubeAlarm python -y
-
Activate the environment:
conda activate youtubeAlarm
-
Install the required libraries:
conda install -c conda-forge yt-dlp requests ffmpeg psutil -y conda install -c anaconda logging argparse pip install mutagen python-vlc
-
Deactivate the environment:
conda deactivate
Enable VLC's HTTP interface by creating a VLC configuration file vlcrc
if it doesn't already exist:
mkdir -p ~/.config/vlc
echo 'http-host=localhost' > ~/.config/vlc/vlcrc
echo 'http-password=vlc' >> ~/.config/vlc/vlcrc
-
Activate the Conda environment:
conda activate youtubeAlarm
-
Run the script with the required arguments:
python youtube_alarm.py --hour <hour> --minute <minute> --playlist <playlist_url>
- Replace
<hour>
with the hour you want the alarm to trigger (0-23). - Replace
<minute>
with the minute you want the alarm to trigger (0-59). - Replace
<playlist_url>
with the URL of the YouTube playlist.
Example:
python youtube_alarm.py --hour 10 --minute 00 --playlist https://www.youtube.com/playlist?list=PL8FvEtnALTbRjuG8qcoMqstD5MDwV00f7
- Replace
-
Optional flags:
--test
: Start playback immediately for testing purposes.--validate
: Validate MP3 files in the music library before starting.--shuffle
: Shuffle the playlist before playing.
Example with optional flags:
python youtube_alarm.py --hour 7 --minute 30 --playlist https://www.youtube.com/playlist?list=PL8FvEtnALTbRjuG8qcoMqstD5MDwV00f7 --test --validate --shuffle
Unit tests are available to validate the functionality of both the MusicLibrary
and VLCManager
classes.
-
Run Music Library Tests:
python -m unittest discover -s tests -p "music_library_test.py"
-
Run VLC Manager Tests:
python -m unittest discover -s tests -p "vlc_test.py"
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request with your improvements.