ajayyy / DeArrow

Crowdsourcing better titles and thumbnails on YouTube
https://dearrow.ajay.app
GNU General Public License v3.0
1.24k stars 33 forks source link

Move title formatting logic to maze-utils (or a separate library) #241

Open netux opened 3 months ago

netux commented 3 months ago

Hello. I'm working on a plugin to add DeArrow features to Grayjay. One thing I'd like to do is have the automatic Title Case conversion that the official extension has, ideally using the same algorithm behind it.

While I could take the files under src/titles, change them to be standalone, and compile them along with my plugin; that sounds like a lot of work to maintain, which I'd like to avoid. I was thinking just having it as a separate module would make my life so much easier, biggest hurdle being updating the library every so often.

If this logic were in maze-utils, I could just install that library, import the relevant files in my code, and - through some tree-shaking magic - hopefully get rid of most of the irrelevant bulk of maze-utils in my built plugin.

ajayyy commented 3 months ago

One problem is it currently contains language detection logic which uses extension specific APIs, but maybe it would work fine by just checking if typeof chrome != undefined

netux commented 3 months ago

One problem is it currently contains language detection logic which uses extension specific APIs, but maybe it would work fine by just checking if typeof chrome != undefined

Could probably use something less tied to extension logic. E.g. wrapping all the title helpers in a class that takes in some configuration (language, titleFormatting, shouldCleanEmojis, etc.). If it needs to dynamic, then something like a provider model could work?

class TitleFormatting {
  constructor(
    public language: string | () => string,
    public formatting: TitleFormatting () => TitleFormatting,
    public shouldCleanEmojis: boolean | () => boolean
  ) {}

  ...
}

Glad to see you are onboard with the idea. If it's too low prio, I'd be willing to do this myself.

netux commented 3 months ago

Closing in favor of ajayyy/DeArrowFormatting#1

netux commented 2 months ago

Oh, I just realized I closed the wrong thing 🤦 Don't code at 1am.