Skip to content

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

@ClaireCJS

Description

@ClaireCJS

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions