Kashi: Show Current Song Lyrics on Touch Bar (Spotify / iTunes / Youtube)

I receive the same errors no matter which instance the widget is calling. I do have all required packages as well as the kashi.py file in the site-packages directory

@rebelraiders101: The json file is just to easily insert the widget. All widgets on BTT can be represented in JSON. It's not necessary if you already have the widget set up. You're right in that all you need to do is paste the contents of the py file in "Script".

@jrosenkrantz: Thanks for the screen. Can you try Launch Path as "/Library/Python/3.7/lib/python" ?

Thanks for the clarification! I'm very unfamiliar with json and python (mechanical engineer not computer lol). After thinking that I got it all figured out, I'm getting this error:

Traceback (most recent call last):
File "", line 212, in
File "", line 11, in main
File "", line 103, in getBrowserAndPlayerData
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/osascript/init.py", line 14, in run
path = temp.tempfile()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/temp/init.py", line 15, in tempfile
f, path = tempfile.mkstemp()
AttributeError: 'function' object has no attribute 'mkstemp'

I've double checked the launch path and variables path and have installed the dependencies, so I'm not sure what's going on. I would really appreciate any help with this! :slight_smile:

That path is progress... not receiving the same error, only "Error/Nothing was returned"

how do I download python 3?

I can't remember for sure but Python 3 is included with the Catalina build, or if not then definitely with Xcode. You can also download it from python.org or install with homebrew in Terminal

brew install python3

in Terminal, which python3 which will return the current version and whereis python3 will return the location

Hi
This returns
zsh: command not found: brew
Thanks

You will need to install the Homebrew package manager from https://brew.sh

1 Like

I've never seen that error, and it may be a new bug.

If you want to try to debug the temp module's init.py file yourself, you can just open it in a text editor. The bug seems to be a basic name conflict for the word "tempfile".

"tempfile" is imported as a module with that name:

import tempfile

But then the code tries to define a function also under the same name:

def tempfile():
    f, path = tempfile.mkstemp()
    os.close(f)
    return path

This creates a conflict. When the osascript dependency tries to interpret path = temp.tempfile() it calls into this function and can't find the correct "tempfile" reference, causing the error.

To remove the error, I would first rename the imported module to a different name:

import tempfile as tempfilelib

Then I would change all instances of tempfile in init.py EXCEPT the function name to the new name, so the previous function may look like the below. You should not change the function name because that will require you to edit the function's name in osascript init.py, where it is being called.

def tempfile():
    f, path = tempfilelib.mkstemp()
    os.close(f)
    return path

Another thing you could do is update your osascript to see if this bug has already been fixed. Please let me know if you make any progress!

What happens if you run the script from the command prompt while Spotify is running?

python3 kashi.py in the folder where the script is located.

Could you please provide the output when you do that?

I'm interested to know if that's an error from BTT or from the script itself.

Hi there,
I got a problem when I test "python Kashi.py" in my terminal while playing music with Spotify,

Traceback (most recent call last):
  File "/Users/zfh/Dropbox/Mac/Desktop/Kashi-master/kashi.py", line 211, in <module>
    main()
  File "/Users/zfh/Dropbox/Mac/Desktop/Kashi-master/kashi.py", line 60, in main
    lyrics = parseAndFormat(genius_url)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/zfh/Dropbox/Mac/Desktop/Kashi-master/kashi.py", line 180, in parseAndFormat
    lyricstext = source_soup.find('div', class_='lyrics').get_text()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_text'```
Could you help me with this matter?
I really need the lyrics on touchbar
Thanks

I'm having the same problem. It seems like the scraping method is not working anymore. I modified the parseAndFormat(url) function and added an if-else statement and the TouchBar prints out "Lyrics not found".

def parseAndFormat(url):
    source_soup = BeautifulSoup(requests.get(url).text, 'html.parser')  # Parse HTML
    lyrics_div = source_soup.find('div', class_='lyrics')
    if lyrics_div:
        # Get text from the lyrics <div>
        lyricstext = lyrics_div.get_text()
        # Remove song sections in brackets
        lyricstext = re.sub(r'\[.*\n*.*\]', '', lyricstext).strip()
        # Remove parentheticals
        lyricstext = re.sub(r'\(.*\n*.*\)', '', lyricstext).strip()
        while '\n\n' in lyricstext:  # Line breaks, flatten, and replace
            lyricstext = lyricstext.replace('\n\n', '\n')
        lyricstext = lyricstext.replace('\n', ', ').replace('?,', '?').replace('!,', '!').replace(' ,', ',').replace(
            ' .', '.').replace('.,', '.').replace(',.', '.').replace('...', '..').replace('...', '..').replace('  ', ' ')
        return lyricstext
    else:
        return "Lyrics not found"

Perhaps this is something you can fix @nemobushido