Skip to content

Conversation

@cyfung1031
Copy link
Contributor

@cyfung1031 cyfung1031 commented Jan 4, 2025

  • Implement setupMain()
  • Fix getSongInfoNodes()

close #22

@cvzi

* Implement `setupMain()`
* Fix `getSongInfoNodes()`

close cvzi#22
@cvzi
Copy link
Owner

cvzi commented Jan 6, 2025

It doesn't work for me. It doesn't register a song change reliably.
One problem seems to be that in getYoutubeMainVideo() the src attribute is not set, when the first media event fires, removing [src] from the selector makes it better, but it's still unreliable.

@cyfung1031 cyfung1031 force-pushed the patch-setupMain branch 2 times, most recently from 022c629 to 7de9a70 Compare January 11, 2025 16:44
@cyfung1031
Copy link
Contributor Author

cyfung1031 commented Jan 11, 2025

OK. Reason is found. I have updated the PR code change.

1. Song Info DOM is updated after video is changed.

So this is why song change detection is unreliable.

setTimeout / mutationObserver can help. I chose mutationObserver to ensure the change must be captured.

You can confirm the song detection is working through checking the console log.

console.log('debug: Youtube Music Genius Lyrics - Song Info', songInfoNodes, nodeString)

2. Media element is updated even after Song Info DOM is changed

Now I detect the activeMedia that found in the media events. I have checked that this is the case that src is not set.

Screenshot 2025-01-12 at 1 27 44

So the PR code has been changed such that the detection would not check the src if activeElement is presented.

You can confirm the video element detection is working through checking the console log.

console.log('debug: Youtube Music Genius Lyrics - getYoutubeMainVideo()', video)

However, lyrics is not changing.

From the console logging, the song change detection (song info + video element) is successful.

Screenshot 2025-01-12 at 1 39 50

There are some other reasons that the song lyrics process could not start.

@cvzi Could you please check ?

@cvzi cvzi merged commit 53f1fd9 into cvzi:master Jan 13, 2025
2 checks passed
@cvzi
Copy link
Owner

cvzi commented Jan 13, 2025

Thanks for you work!!
I think this line is the problem: const musicIsPlaying = video && !video.paused
video.paused is still true here. Probably it could be fixed with a delay, but I don't think this line is necessary. It prevents the lyrics from showing, when a song is in the queue but the song is paused. I probably copied it from Spotify script, it can happen on Spotify if you pause the music and then open a new Spotify tab. I don't think it can happen on Youtube Music though, because a new tab starts playing even if it was paused in another tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: option to auto reload on song change

2 participants