LRC & YouTube Player (Project abandoned as many Youtube channels are set to not allow playing their videos from outside Youtube)
This project provides a simple web interface for playing YouTube videos synchronized with LRC lyrics files. It allows users to select a song from a predefined list, load the corresponding LRC file, and display the lyrics in sync with the playing YouTube video.
You can see a live demo of the project here: https://abdelhaqueidali.github.io/LRC-And-YouTube-Player/
See https://github.com/abdelhaqueidali/Amazigh-Lyrics-Files-LRC
- Loads LRC Files: Reads LRC (Lyric) files to display time-synchronized lyrics.
- YouTube Integration: Embeds and plays YouTube videos using the YouTube Iframe API.
- Dynamic Song List: Fetches a list of songs and their associated YouTube links from a
data.txt
file. - Lyric Synchronization: Highlights the current line of lyrics in sync with the YouTube video's playback time.
- Lyric Scrolling: Automatically scrolls the lyrics to keep the current line in view.
- Lyric Seeking: Allows users to click on a lyric line to seek the YouTube video to that specific time.
- LRC Download: Provides a button to download the currently loaded LRC file.
- Responsive Design: Adapts to different screen sizes.
- Mobile Friendly Song Selection: Includes a "Show Song List" button to toggle the song list visibility, improving usability on smaller screens.
- Plain Text Lyrics Extraction: Easily copy plain text version of the lyrics.
-
Song List (data.txt): The
data.txt
file contains a list of songs. Each line in this file represents a song and should be in the formatfilename.lrc|youtube_link
. Thefilename.lrc
part specifies the name of the LRC file (located in the same directory as the HTML file), andyoutube_link
is the URL of the corresponding YouTube video.Example
data.txt
:Song1.lrc|https://www.youtube.com/watch?v=dQw4w9WgXcQ Song2.lrc|https://youtu.be/exampleVideoId
-
Loading the Song List: The JavaScript code fetches the
data.txt
file and parses it to create the song list displayed on the page. Each song in the list is a clickable element. -
Loading a Song: When a user clicks on a song in the list:
- The corresponding LRC file is fetched.
- The lyrics are parsed and displayed.
- The YouTube video is loaded using the provided YouTube link (extracting the video ID).
- The download button becomes visible.
-
LRC Parsing: The
parseLRC
function converts the LRC file content into an array of JavaScript objects. Each object contains thetime
(in seconds) and thetext
of the lyric line. The LRC format is expected to be:[mm:ss.xx]lyric text
. -
YouTube Player: The YouTube Iframe API is used to embed and control the YouTube video. The API is loaded asynchronously.
-
Lyric Synchronization: The
syncLyrics
function is called repeatedly (every 100ms) while the video is playing. It compares the current video time with the timestamps in the parsed LRC data to determine the currently playing lyric line. The currently playing line is highlighted, and the lyrics container is scrolled to keep it in view. -
Seeking: Clicking on a lyric line calls the
seekTo
function, which uses the YouTube API to seek the video to the corresponding time. -
Downloading: The download button dynamically creates a link to download the LRC file as a text file.
-
Clone the Repository:
git clone <repository_url>
(Replace
<repository_url>
with the actual URL of your GitHub repository.) -
Create
data.txt
: Create adata.txt
file in the same directory as yourindex.html
file. Populate it with your song data as described above. -
Create LRC Files: Place your
.lrc
files in the same directory asindex.html
. Make sure the filenames match those listed indata.txt
. -
Open
index.html
: Open theindex.html
file in a web browser.
index.html
: The main HTML file containing the structure of the webpage, the YouTube player, the lyrics display, and the JavaScript code.data.txt
: A text file containing the list of songs, LRC filenames, and YouTube links..lrc
files: The lyric files (e.g.,Song1.lrc
,Song2.lrc
).
- YouTube Iframe API: Used for embedding and controlling the YouTube player. The script is loaded dynamically within the
index.html
.
I welcome contributions! If you'd like to add features, improve the code, or fix bugs, please feel free to submit a pull request.
- Fork this repo
- Clone to you PC
- Do your edits
- Create a pull request
- The original concept and initial prompt were created by the owner of this repository.
- The code was generated with the assistance of AI, specifically Claude Sonnet 3.5.
- This design focuses on sharing lyrics along with associated YouTube videos without hosting the song files directly, addressing copyright concerns and supporting content creators through ad revenue.
- The extracted lyrics from the LRC can be copied after selecting a song. If you want to get the lyrics in plain text, load the song and copy the lyrics from the lyrics section. To keep the timestamps with the lyrics, click on the "Download LRC" button and open the downloaded
.lrc
file with any text editor (e.g., Notepad++).