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

py3: add new helper: get_replacements_list #2242

Merged
merged 3 commits into from
Jan 21, 2025

Conversation

lasers
Copy link
Contributor

@lasers lasers commented Mar 27, 2024

An alternative to PRs listed below.

I copied thresholds code. Minimal test. Allow users to be more specific.

Get placeholders_list first so we can target existing placeholders rather than all placeholders.
I don't know if this PR is the optimal solution, just an alternative.

Code untested on this player.. I tested on nvidia_smi. Sorry if you ran into issues.

This is just an idea / experiment.

Please test this.

# Ought to do dict (perform on matched string placeholders)
    replacements = {
        "artist": [
            "([\(\[][^)\]]*?(bonus|demo|edit|explicit|extended|feat|mono|remaster|stereo|version)[^)\]]*?[\)\]])",
            "([\-,;/])([^\-,;/])*(bonus|demo|edit|explicit|extended|feat|mono|remaster|stereo|version).*"
        ],
    }

# Ought to do list. (perform on all string placeholders)
    replacements = [
            "([\(\[][^)\]]*?(bonus|demo|edit|explicit|extended|feat|mono|remaster|stereo|version)[^)\]]*?[\)\]])",
            "([\-,;/])([^\-,;/])*(bonus|demo|edit|explicit|extended|feat|mono|remaster|stereo|version).*"
        ]

Solves #2234 (comment).

Closes #2234.
Closes #2237.

@lasers lasers force-pushed the replacements branch 7 times, most recently from 0596fad to 2d05477 Compare March 28, 2024 07:04
@lasers lasers marked this pull request as ready for review March 28, 2024 07:08
@lasers
Copy link
Contributor Author

lasers commented Mar 31, 2024

Ideally, we should separate this into artist and album. Who volunteer?

"([\(\[][^)\]]*?(bonus|demo|edit|explicit|extended|feat|mono|remaster|stereo|version)[^)\]]*?[\)\]])",
"([\-,;/])([^\-,;/])*(bonus|demo|edit|explicit|extended|feat|mono|remaster|stereo|version).*",

@lasers
Copy link
Contributor Author

lasers commented Oct 26, 2024

Merged verison of the two regex patterns according to GPT. Untested.

replacements = [
    r"([\(\[\-,;/][^)\],;/]*?(bonus|demo|edit|explicit|extended|feat|mono|remaster|stereo|version)[^)\],;/]*?[\)\]])"
]

@lasers lasers changed the title make self.py3.replace helper py3: add new helper: get_replacements_list Dec 23, 2024
@lasers
Copy link
Contributor Author

lasers commented Dec 23, 2024

@ultrabug Review plz.

@lasers
Copy link
Contributor Author

lasers commented Dec 24, 2024

I didn't add this for mpris and mpd_status.

I don't need this for cmus, deadbeef, moc... This PR might be better understood with more examples... is which why I added few more music modules. I can drop them... and users could contribute them later just easily... or more likely easier to leave them in... and work on mpris, mpd_status later. Idk. Modules are untested.

@ultrabug ultrabug merged commit f648cb6 into ultrabug:master Jan 21, 2025
7 checks passed
@ultrabug
Copy link
Owner

Hi @lasers sorry for the delay

I agree this approach is sane and works good enough.

I would have argued that we could have done the replace work within py3 core so that modules didn't have to all implement the same replace loop but hey, let's move forward

valdur55 added a commit to valdur55/py3status that referenced this pull request Jan 21, 2025
valdur55 added a commit to valdur55/py3status that referenced this pull request Jan 21, 2025
valdur55 added a commit to valdur55/py3status that referenced this pull request Jan 21, 2025
@valdur55
Copy link
Contributor

Used regex from spotify example config:

    replacements = {
        "album": [("\s?[\(\[\-,;/][^)\],;/]*?(bonus|demo|edit|explicit|extended|feat|mono|remaster|stereo|version)[^)\],;/]*[\)\]]?", "")],
        "title": [("\s?[\(\[\-,;/][^)\],;/]*?(bonus|demo|edit|explicit|extended|feat|mono|remaster|stereo|version)[^)\],;/]*[\)\]]?", "")]
    }

Some findings by testing it with some youtube videos:
"Queen – Bohemian Rhapsody (Official Video Remastered)" -> "Queen – Bohemian Rhapsody"
"Soul Reaver 1 & 2 Remastered - Before You Buy" -> it is broken. doesn't cut.
"Tomb Raider IV-VI Remastered - Announce Trailer | PS5 & PS4 Games" -> "Tomb Raider IV"

Generally looks promising, but most difficult part is to iron out good regex,
And it should be given to user by example.

After implementing code, got one qestion. Is there difference between using self.replacements_init vs self._replacements_init in module code?
For me public properies are meant for config parameters which comes outside of module. Code works in both ways.

@lasers lasers deleted the replacements branch January 22, 2025 07:04
@lasers
Copy link
Contributor Author

lasers commented Jan 22, 2025

"Soul Reaver 1 & 2 Remastered - Before You Buy" -> it is broken. doesn't cut.

That's why we have user-configurable regex now. I tried what I can to consolidate both regexes so the example config would look this clean. Does this issue occur the same with old regexes? If yes, then it's perfect, but the example can be changed later on.

This is also why I think it's sensible not to default replacements with existing regexes (for spotify and others).

Is there difference between using self.replacements_init vs self._replacements_init in module code?

self._replacements_init (in py3) is used to cache compiled regex objects for performance reasons since we would be searching / replacing placeholders all time. Compile once on startup. The real reason is that I just copied it.

self.replacements_init (in modules) is a list of keys from user-config replacements (dict). If it is not a dict, it will give a list of placeholders from format_player (or whatever you need replacing). It's usually one or two keys (with dict).

For me public properies are meant for config parameters which comes outside of module. Code works in both ways.

Can you explain more?

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.

3 participants