youtube-music icon indicating copy to clipboard operation
youtube-music copied to clipboard

[DEPRECATED] [lyrics] "Song" type lyrics can be changed/translated now

Open DereC4 opened this issue 1 year ago • 12 comments

  • #1085 for more information about the different types
  • I've made it so that the lyrics from the "Song" type can be intercepted and changed, useful because previously they would skip all the lyric and translation plugin options. For example, the song below would have lyrics in Japanese even if my Romanization option was enabled.
  • That has changed

image

DereC4 avatar Mar 29 '23 03:03 DereC4

You don't need to create a new function, just change the selector

Araxeus avatar Mar 29 '23 16:03 Araxeus

Those changes are fine:

- module.exports = () => {
+ module.exports = (options) => {
-		if (!tabs.lyrics?.hasAttribute("disabled")) {
+		if (!(tabs.lyrics?.hasAttribute("disabled") || options.romanizedLyrics)) {

For the rest (choosing the right container in Music type videos) you can just change the Selector in checkLyricsContainer like so:

function checkLyricsContainer(callback = () => {}) {
	const lyricsContainers = [
		document.querySelector(
			'ytmusic-tab-renderer[page-type="MUSIC_PAGE_TYPE_TRACK_LYRICS"] > ytmusic-message-renderer',
		),
		document.querySelector(
			'ytmusic-section-list-renderer[page-type="MUSIC_PAGE_TYPE_TRACK_LYRICS"] .non-expandable.description.ytmusic-description-shelf-renderer',
		),
	];
	lyricsContainers.forEach((lyricsContainer) => {
		if (lyricsContainer) {
			callback();
			setLyrics(lyricsContainer);
			lyricsContainer.style.display = "block"; // fix youtube hiding the lyrics sometimes
		}
	});
}

I've tested this on my pc and it seems to work fine, here's a screenshot of the full changes:

image

Araxeus avatar Mar 29 '23 16:03 Araxeus

BTW there is a bug because of the extra spacing in setLyrics, in particular line 84 below - before the ${

https://github.com/th-ch/youtube-music/blob/3b6d66cddc5cdcda82c0798a2fba2652e7cc3df9/plugins/lyrics-genius/front.js#L81-L93

needs to be like this:

		function setLyrics(lyricsContainer) {
			lyricsContainer.innerHTML = 
`<div id="contents" class="style-scope ytmusic-section-list-renderer description ytmusic-description-shelf-renderer genius-lyrics">
${
hasLyrics
	? lyrics.trim().replace(/(?:\r\n|\r|\n)/g, "<br/>")
	: "Could not retrieve lyrics from genius"
}

</div>
<yt-formatted-string class="footer style-scope ytmusic-description-shelf-renderer" style="align-self: baseline"></yt-formatted-string>`;
			if (hasLyrics) {
				lyricsContainer.querySelector('.footer').textContent = 'Source: Genius';
				enableLyricsTab();
			}
		}

Araxeus avatar Mar 29 '23 16:03 Araxeus

got it, will change soon

DereC4 avatar Mar 30 '23 08:03 DereC4

image I tried building it myself but it doesn't work This is a feature I really wanted. Is this an unfinished feature?

jang-geon avatar Apr 16 '23 02:04 jang-geon

image I tried building it myself but it doesn't work This is a feature I really wanted. Is this an unfinished feature?

oh i never changed it to the updated because of e;xams;x will get to it soon

DereC4 avatar Apr 17 '23 17:04 DereC4

Also I like your taste in music haha

DereC4 avatar Apr 24 '23 04:04 DereC4

image

@jang-geon Seems to be working on my part; it is possible since the song you're playing is from a fairly recent anime, it has not been uploaded to the database as romanji lyrics. As a result, Youtube fallbacks and uses the lyrics it can find, which are in Japanese. (Really good anime tho!)

DereC4 avatar Apr 24 '23 04:04 DereC4

image

DereC4 avatar Apr 24 '23 04:04 DereC4

Am glad the romanization toggle was included in the last version!

DereC4 avatar May 21 '23 16:05 DereC4

@th-ch Any luck on merging this? I hope the next release can include this change!

DereC4 avatar Jul 12 '23 20:07 DereC4

Any luck on merging this? I hope the next release can include this change!

Could you rewrite this PR? There have been a lot of changes to the master branch, including the change from JavaScript to TypeScript.

JellyBrick avatar Oct 08 '23 15:10 JellyBrick

Can we merge this yet? We've updated it and rebased it

@DereC4 The plugin system has been completely rewritten since this PR was created. So, you'll need to rewrite your code based on the current code base.

see https://github.com/th-ch/youtube-music/tree/master/src/plugins/lyrics-genius

JellyBrick avatar Feb 19 '24 06:02 JellyBrick

Can we merge this yet? We've updated it and rebased it

@DereC4 The plugin system has been completely rewritten since this PR was created. So, you'll need to rewrite your code based on the current code base.

see https://github.com/th-ch/youtube-music/tree/master/src/plugins/lyrics-genius

That's so sad because I worked on this back when I had more time and now job and classes have ramped up again. The original request only changed around 3 files though, if anyone could do the updating

DereC4 avatar Feb 19 '24 08:02 DereC4

I'll do the updating later this day, I've been busy the past few months so my lyric plugin got delayed.

ArjixWasTaken avatar Feb 19 '24 08:02 ArjixWasTaken

I'll do the updating later this day, I've been busy the past few months so my lyric plugin got delayed.

sounds awesome

DereC4 avatar Feb 19 '24 22:02 DereC4

I am afraid, simply updating the code to use the new plugin API won't cut it. Besides, it doesn't make much sense to have a different plugin for every lyric provider. (since having multiple lyric providers is my goal)

So I will be rewriting this from scratch, ofc I'll give credit where it's due. Is it ok if I close this PR?

ArjixWasTaken avatar Feb 19 '24 22:02 ArjixWasTaken

I am afraid, simply updating the code to use the new plugin API won't cut it. Besides, it doesn't make much sense to have a different plugin for every lyric provider. (since having multiple lyric providers is my goal)

So I will be rewriting this from scratch, ofc I'll give credit where it's due. Is it ok if I close this PR?

Yeah I'll close the PR myself but i thought the plugin itself was staying the same with Lyrics Genius. I'd really appreciate the credit though once u finish

best of luck

(hard to believe this PR has been open for almost a year)

DereC4 avatar Feb 19 '24 22:02 DereC4