Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Lyrics Aligment #1107

Open
3 tasks done
SpikeNew7774 opened this issue Jan 14, 2025 · 0 comments
Open
3 tasks done

Better Lyrics Aligment #1107

SpikeNew7774 opened this issue Jan 14, 2025 · 0 comments
Assignees
Labels
Suggestion New feature or request

Comments

@SpikeNew7774
Copy link

What are you Suggesting?

an Improvement

What is the context behind this Suggestion?

Your extension (Beautiful Lyrics) on some songs, parses them with Aligment issues.
This means that when a line that's being Sung by a different artist in the song, the line may not be correctly aligned to the "Opposite Side".

For comparison:

Beautiful Lyrics:

image

Apple Music Lyrics:

image

What is your Suggestion?

So that's why I want to contribute by providing this code that has "Better Aligment" (Compared to Beautiful Lyric's current parser) on parsing Apple's TTML format (The source format of fetched lyrics).

The following code is only for the API

const Agents = ttml.tt.head.metadata["ttm:agent"];
const PostAgents = (Agents != null ? (Array.isArray(Agents) ? Agents : [Agents]) : []);

const DoesOtherAgentExist = (array) => {
  const OtherAgent = array.filter(a => a.type === "other");
  if (OtherAgent.length > 0) return true;
  return false;
}

const TrackAgents = (PostAgents.length > 0 ? PostAgents.map((agent, _ , arr) => {
  const agentType = agent.type;
  const agentId = agent["xml:id"];

  const OppositeAligned = DoesOtherAgentExist(arr) ? (agentId === "v2" || (agentId === "v2000" && agentType === "other")) : (agentId === "v2" || agentType === "group");

  return {
    Type: agentType,
    Id: agentId,
    OppositeAligned
  }
}) : [])

const IsOppositeAligned = (div) => {
  let divTtmAgent = div["ttm:agent"];
  if (!divTtmAgent) {
    const divp = Array.isArray(div) ? div : [div];
    if (divp.length > 0) {
      if (divp[0].p[0]) {
        const firstPAgent = divp[0].p[0];
        if (firstPAgent["ttm:agent"]) divTtmAgent = firstPAgent["ttm:agent"];
      }
    }
  }

  const TrackAgent = TrackAgents.filter(a => a.Id === divTtmAgent);

  if (TrackAgent.length > 0) {
    return TrackAgent[0]?.OppositeAligned ?? false;
  }
  return false;
}

The most crucial part is this:

const OppositeAligned = DoesOtherAgentExist(arr) ? (agentId === "v2" || (agentId === "v2000" && agentType === "other")) : (agentId === "v2" || agentType === "group");

It checks if there's and agent with the type of "other", if there is, it makes the line "OppositeAligned" when the agentId equals to "v2" or if agentId equals to "v2000" and agentType is "other". If there isnt an "other" agent, it make the line "OppositeAligned" when the agentId equals to "v2" or the agentType equals to "group".

After all this is just a suggestion, and doesn't ACTUALLY need to be included in the API. 😊

Suggestion Checklist

  • You clearly titled/explained your Suggestion.
  • You accurately described/contextualized the reasoning behind your Suggestion.
  • IF applicable to your Suggestion, you provided visual examples/references to accurately represent what you are Suggesting.
@SpikeNew7774 SpikeNew7774 added the Suggestion New feature or request label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Suggestion New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants