hnarayanan / shpotify

A command-line interface to Spotify.
https://harishnarayanan.org/projects/
2.02k stars 153 forks source link

Play on other devices #132

Closed davidem closed 4 years ago

davidem commented 4 years ago

I've made options to list and play on other devices, like phones, computers, spotify connect devices, the like. It's using the authorisation part also used for listing one's playlists. Please note that i've added a few extra 'scopes', which means a possible existing 'refresh-token' needs to be removed.

Use list devices to list possible devices. Devices must be active, there's currently no history. It poops out the device id, name, type, used and volume level.

Use connect <device_id> to select and play on a device. To connect by 'name' does not work (yet)

What do you think? :)

davidem commented 4 years ago

(forgot to mention this is still a beta feature of the spotify web-api)

hnarayanan commented 4 years ago

Closing this PR because I've already merged a larger one that includes these changes.

moshed commented 4 years ago

was this ever merged into the main branch I cant seem to get it to work?

davidem commented 4 years ago

No, not yet. Harish has created a separate branch: 3.0-pre

If you use that branch, it works like this:

List possible devices for playback: ./spotify list devices 40charidofdevice0123456789abcdefghijklmn Mac Computer true 53 40charidofotherdevice0123456789abcdefghi Soundbar Speaker false 16`

To connect and play from another device: ./spotify connect 40charidofotherdevice0123456789abcdefghi`

true/false indicates if a device is active or not. The numbers show the spotify volume settings.

moshed commented 4 years ago

ahhh got it. it seems this requires user authentication and the redirect uri to http://localhost:8082/ isnt working. just freezes on the authentication page

davidem commented 4 years ago

Ah, yes... good of you to mention that. Completely forgot I had to whitelist that URL. Here's how:

Screenshot 2020-10-08 at 22 53 52
davidem commented 4 years ago

I'll add that info to the 'help' part

moshed commented 4 years ago

hmm I had added it but I just removed the app from my dashboard and readded it and now it works! thanks for your help!

moshed commented 4 years ago

did you include the removal of jq in this branch? seems it still requires it

davidem commented 4 years ago

Indeed, jq is still required. The relative ease of use of jq vs trying to parse json output with commands like grep/awk/tr/cut makes it 1:0 for jq in my opinion.

moshed commented 4 years ago

ahh got it, im trying to put a device list into my menubar so I can choose my devices easily without opening Spotify but both apps that can achieve this (bettertouchtool and bitbar) dont seem to be compatible with jq unfortunately.

davidem commented 4 years ago

I don't get it, sorry ;) I assume with bitbar/bettertouchtool you call shpotify to list your available devices / select your playback devices, right? The output you get from shpotify does not require jq, it's only used to parse the json feedback from spotify.

moshed commented 4 years ago

im not sure tbh. when I use Shpotify from the command line it works with no problems but when I attempt to create the script to select device playback form the menubar I get an error saying I need jq.

image
davidem commented 4 years ago

ah, thanks, now I think I get it :) My guess is that jq is not in $PATH of the 'user' running the script.

Best way is to add the full path to shpotify. It's fixed in my latest 3.0 version (#144) or found here: https://github.com/davidem/shpotify/tree/3.0

davidem commented 4 years ago

I've updated the JQ check. It first checks $PATH, then it checks if jq is in /usr/local/bin. @moshed: does it now work for you?

moshed commented 4 years ago

hmm still not. my script is this with the full Spotify path

#!/bin/bash
echo spotify
usr/local/bin/spotify list devices

but I still get the same jq error as before? im sure im doing something wrong as opposed to it not functioning properly because im not too savvy at this but I cant figure out what it is

davidem commented 4 years ago

Can you show me where jq is located?

Mine:

➜  ~ which jq
/usr/local/bin/jq

I'll add an option to hardlink to jq later today

moshed commented 4 years ago

same as you

moshe@Moshes-MacBook-Pro ~ % which jq
/usr/local/bin/jq
moshed commented 4 years ago

hey @davidem sorry to be a pain. do you have an idea why jq is not functioning properly when called from bitbar or better touch tool? should I be changing one of these settings?

image
davidem commented 4 years ago

Hi Moshed,

I've just installed bettertouchtool. I'll try to figure this out once and for all ;)

davidem commented 4 years ago

Hi Moshed, do you use my latest version? I've added a 'find' command a few weeks back to search for jq in /usr/local/bin, just in case it's not in PATH. It can be found here: https://github.com/davidem/shpotify/tree/3.0. Its changes have not yet been merged.

When I use bettertouchtool + my version of shpotify, it works like a charm. Note that 'list devices' also requires jq. If I disable 'find' in the script, it fails with the same error you get.

image
moshed commented 3 years ago

it works! great news!

thanks so much!