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

title / artist fail if winamp scrolling title feature is enabled #4

Open
ClaireCJS opened this issue Aug 22, 2024 · 1 comment
Open

Comments

@ClaireCJS
Copy link

ClaireCJS commented Aug 22, 2024

Hi, I just wanted to report a bug in that WinampRPC currently fails to get the track/title information correctly if you have the winamp option on that scrolls the title.

I'm not comfortable with submitting pull requests, I'm a bit old school in that I'd rather manually describe the fix.

I ended up having to write a function which i put in winamp.py (but not in the class definition) that unbreaks this, and wanted to share it with you.
However, my solution is incomplete because it only works if you change Winamp's advanced title formatting to separate the artist and title with an endash (–) instead of a hyphen (-). I did this because bands and songs can both have hyphens in them, and I didn't want to figure out the splitting code, sorry.

def extract_band_and_track_from_raw_title(trackinfo_raw: str) -> Tuple[str, str]:
    import re

    # Remove everything up to and including "*** "
    trackinfo_stripped = re.sub(r'^.*\*\*\* \d+\. ', '', trackinfo_raw)

    # Remove the number followed by a period
    trackinfo_stripped = re.sub(r'^\d+\. ', '', trackinfo_stripped)

    # Strip off " - Winamp" and anything after it
    trackinfo_stripped = re.sub(r' - Winamp.*$', '', trackinfo_stripped)
    #print(f"Stripped Info: {trackinfo_stripped}")

    # Split on "–" (endash) to get artist and track name
    if '–' in trackinfo_stripped:
        artist, track = trackinfo_stripped.split('–', 1)
        artist = artist.strip()
        track  = track.strip()
        #print(f"\tArtist = '{artist}'")
        #print(f"\tSong   = '{track}'")
        return artist, track
    else:
        print(f"can't find endash in {trackinfo_stripped}")
        return "N/A", "N/A"

Then, get_track_title was modified to use this new function:

    def get_track_title(self) -> str:
        """
        Get the current track title.

        :return: Currently playing track title in format that is seen in Winamp's Window text. Usually in format
        '{track number}. {artist} - {track name} - Winamp'

        :raises ConnectionError: If a connection to Winamp client is not established.
        """
        self.__ensure_connection()

        #return win32gui.GetWindowText(self.window_id)
        trackinfo_raw = win32gui.GetWindowText(self.window_id)
        artist, title = extract_band_and_track_from_raw_title(trackinfo_raw)
        return title

And get_trackinfo_raw was introduced as a way to access the buggy title (i.e., the titles you fetch now in their unprocessed state):

    def get_trackinfo_raw(self) -> str:
        """
        Get the current raw track title.

        :return: Currently playing track title in format that is seen in Winamp's Window text. Usually in format
        '{track number}. {artist} - {track name} - Winamp'

        :raises ConnectionError: If a connection to Winamp client is not established.
        """
        self.__ensure_connection()
        return win32gui.GetWindowText(self.window_id)

I collected all the titles for a particular song and created some test data to test my function out:

def test_examples():
    # Example trackinfo_raw strings
    examples = [
        "The Coathangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "Coathangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "hangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "rs - Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "e Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        " - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "namp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "*** 4809. The Coathangers – Excuse Me? - Winamp ***",
        "9. The Coathangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "e Coathangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "thangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "ers - Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        " Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "se Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "inamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "p *** 4809. The Coathangers – Excuse Me? - Winamp",
        "809. The Coathangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "The Coathangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "oathangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "ngers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        " - Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "cuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        " Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "mp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "4809. The Coathangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        " The Coathangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "Coathangers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "angers – Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "s - Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "Excuse Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "e Me? - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        " - Winamp *** 4809. The Coathangers – Excuse Me? - Winamp",
        "namp *** 4809. The Coathangers – Excuse Me? - Winamp"
    ]

    for example in examples:
        band_name, track_name = extract_band_and_track_from_raw_title(example)
        print(f"Input: {example}")
        print(f"Band Name: {band_name}\nTrack Name: {track_name}\n")

Once I got that working, I ran it on winamp and advanced tracks many times, and it got the artist and title correct 100% of the time.

@ClaireCJS
Copy link
Author

Sample test run:

< 2:38a> <5%> C:\bat>experimental-winamp-monitor.py


trackinfo_raw=651. Jemina Pearl – Ecstatic Appeal - Winamp *** 3651. Jemina Pearl – Ecstatic Appeal - Winamp
    artist=Jemina Pearl
     title=Ecstatic Appeal

trackinfo_raw=Jemina Pearl – Ecstatic Appeal - Winamp *** 3651. Jemina Pearl – Ecstatic Appeal - Winamp
    artist=Jemina Pearl
     title=Ecstatic Appeal

trackinfo_raw=a Pearl – Ecstatic Appeal - Winamp *** 3651. Jemina Pearl – Ecstatic Appeal - Winamp
    artist=Jemina Pearl
     title=Ecstatic Appeal

trackinfo_raw=rl – Ecstatic Appeal - Winamp *** 3651. Jemina Pearl – Ecstatic Appeal - Winamp
    artist=Jemina Pearl
     title=Ecstatic Appeal

trackinfo_raw=Ecstatic Appeal - Winamp *** 3651. Jemina Pearl – Ecstatic Appeal - Winamp
    artist=Jemina Pearl
     title=Ecstatic Appeal

trackinfo_raw=tic Appeal - Winamp *** 3651. Jemina Pearl – Ecstatic Appeal - Winamp
    artist=Jemina Pearl
     title=Ecstatic Appeal

trackinfo_raw=ppeal - Winamp *** 3651. Jemina Pearl – Ecstatic Appeal - Winamp
    artist=Jemina Pearl
     title=Ecstatic Appeal

trackinfo_raw=3652. Surgical Meth Machine – Spudnik - Winamp
    artist=Surgical Meth Machine
     title=Spudnik

trackinfo_raw=. Surgical Meth Machine – Spudnik - Winamp *** 3652. Surgical Meth Machine – Spudnik - Winamp
    artist=Surgical Meth Machine
     title=Spudnik

trackinfo_raw=gical Meth Machine – Spudnik - Winamp *** 3652. Surgical Meth Machine – Spudnik - Winamp
    artist=Surgical Meth Machine
     title=Spudnik

trackinfo_raw= Meth Machine – Spudnik - Winamp *** 3652. Surgical Meth Machine – Spudnik - Winamp
    artist=Surgical Meth Machine
     title=Spudnik

trackinfo_raw= Machine – Spudnik - Winamp *** 3652. Surgical Meth Machine – Spudnik - Winamp
    artist=Surgical Meth Machine
     title=Spudnik

trackinfo_raw=hine – Spudnik - Winamp *** 3652. Surgical Meth Machine – Spudnik - Winamp
    artist=Surgical Meth Machine
     title=Spudnik

trackinfo_raw=3653. Gwar – Phantom Limb - Winamp
    artist=Gwar
     title=Phantom Limb

trackinfo_raw=653. Gwar – Phantom Limb - Winamp *** 3653. Gwar – Phantom Limb - Winamp
    artist=Gwar
     title=Phantom Limb

trackinfo_raw=Gwar – Phantom Limb - Winamp *** 3653. Gwar – Phantom Limb - Winamp
    artist=Gwar
     title=Phantom Limb

trackinfo_raw=– Phantom Limb - Winamp *** 3653. Gwar – Phantom Limb - Winamp
    artist=Gwar
     title=Phantom Limb

trackinfo_raw=antom Limb - Winamp *** 3653. Gwar – Phantom Limb - Winamp
    artist=Gwar
     title=Phantom Limb

trackinfo_raw= Limb - Winamp *** 3653. Gwar – Phantom Limb - Winamp
    artist=Gwar
     title=Phantom Limb
Traceback (most recent call last):
  File "C:\bat\experimental-winamp-monitor.py", line 203, in <module>
    time.sleep(1)
KeyboardInterrupt
^C
< 2:39a> <12%> C:\bat>

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

No branches or pull requests

1 participant