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

UPDATE (6/23/2019): Kashi will now also show the lyrics on Touch Bar when watching YouTube on Chrome or Safari (demo video below).

  • In order to do this, Youtube must be on the active tab.
  • If a browser and a player are open at the same time, Kashi will prioritize the player if it is playing music.

Hi BTT community,

This is my first BTT plugin/preset. Since the community is already so great at making visually pleasing presets, I thought I'd focus on function rather than form. As an audiophile, I wanted my project to be music-related, so I ended up making "Kashi".

Kashi is a widget that display the lyrics of the current song playing on Spotify, iTunes, or Youtube on the Touch Bar. Here are some videos of it in action:

Spotify & iTunes:

YouTube:

Set-up is explained in the ReadMe, but basically there are a few Python 3 modules that need to be installed for the widget to work.

Thanks for taking the time to read this!
All questions and comments are welcome.

@nemobushido Hi I'm super excited to get your preset running. I either get an error on my touch bar that 'false is not defined', easily fixed by changed 'false' to 'False'. After that, the module just doesn't load on the touch bar.

Line: "BTTTouchBarAppleScriptStringRunOnInit"

@lithedreamer
Just confirming, but have you installed Python 3 and the required dependencies? You may need to install them globally to access them from BTT.

Also, check that the line below points to the proper path where your python3 installation lives.

"BTTShellScriptWidgetGestureConfig" : "/usr/local/bin/python3:::-c",

For debugging, you can execute the script from Terminal and see if it prints the correct lyrics in console:

python3 kashi.py

or if you are not in the same folder as the script,

python3 /folderpath/kashi.py

Uncomment (delete '#' in front of) certain lines of code to check data flow.

For example you can target the player data,

print(player_data)

or data from the API response:

print("\nHits:", hits)
print('\nGenius Artist: ' + genius_artist + '\nGenius Song: ' + genius_song + '\nGenius URL: ' + genius_url + '\n')

If Terminal shows no issue, the widget should simply work by copy pasting the JSON into the settings: kashi.json.

Thanks for getting back to me. Testing the print statements: all of them work and dispense the correct lyrics in terminal, which seems to suggest that the python modules are set up correctly (the path for python3 is also correct). Copying and pasting the JSON into the settings seems to create the same result: just blank Touch Bar space, not even a button as far as I can tell.

@lithedreamer
I see. Then it must be how your bar is set up. Can you make sure that the widget is checked "Visible", item placement is "Scrollable Main Container", and that no other widgets occupy the same space? Having a left and a right one is OK.

Please see below:

Widget is checked visible and item placement is a Scrollable Main Container. I turned off all my other widgets, so nothing should be interfering...

Hm, I'm a bit stumped. Thanks for your persistence.

Could you try creating the widget from scratch? Create a new "Run Shell Script And Show Return Value" script widget and confirm that it's showing text. Then copy+paste the .py script (Parameter = "-c").

Hello, really great work! I am just having some trouble getting the lyrics to scroll as the song play. If you could help that would be awesome!
Thanks

Hi, trying to get this to work and I keep running into this error.

File "kashi.py", line 214, in
main()
File "kashi.py", line 20, in main
player_data)
File "kashi.py", line 135, in processPlayerData
player_artist = player_data[1].lower()

IndexError: list index out of range

Hi Bowser.

Seems like the "player_data" array is completely empty in your case. That is strange because the "getBrowserAndPlayerData" function should default values to "none" if no player or browser is running.

Which means you must be having problems with the osascript module. It is responsible for running the applescripts which get the player/browser data. Make sure that all osascript and all other Python modules are correctly installed.

The best way to do this is to test the script on command line and see if your Python spits any error about the modules. E.g., you can add the line "print(player_data)" to see what is in that list.

Also, very important is to make sure your launch path, parameter, and Python path are properly specified. For me, these are:

Launch Path:
/usr/local/bin/python3

Parameters:
-c

PYTHONPATH:
PYTHONPATH=/Library/Frameworks/Python.Framework/Versions/3.7/lib/Python3.7/site-packages

The PYTHONPATH may vary for you depending on how your Python is installed.

I've been trying everything I can think of. I created a new partition and reinstalled osx along with python and the modules. Everything seems to point to the right place. When playing around in idle with the module, it sees the functions and i can call them but it cant see the data. e.g. when I called printWisdom() it recognizes that it needs an input but cant seem to get one

Hi Bowser,

Sorry for the trouble you're going through.

The printWisdom function just prints a music-related quote (static data) if there are no hits from the lyrics API, so it doesn't tell much about your configuration.. The key here is that you can't see the player data. Is the py script able to spit out the player data? Try printing the variable "player_data" (or "browser_data" if it's Youtube) after line 17 and see what comes out.

I'm also unsure if your Python is configured correctly with BetterTouchTool. You can test this simply by running a script as simple as print("Testing Python") and see if it shows up on the bar.

Let me know how it goes! Feel free to post some screenshots too. If you need remote assistance, I don't mind helping you out. Just let me know.

Imprint | Privacy Policy