Code Monkey home page Code Monkey logo

pytify's Introduction

Pytify

Donate Code Climate

Pytify logo

Search and start songs from the CLI.
Linux and OS X support.

Spotify must be running in the background in order to use this cli remote

Python 3 support. For Python 2 support use this release: v2.1.0

Image of terminal

Installation

$ pip install pytify

Python 2

$ pip install pytify==2.1.0

Linux you need to install python-dbus package.

$ # Example using apt-get
$ apt-get install python-dbus

Credentials

This package now must use credentials in order to search for songs.

Support for client credentials flow. Please follow these steps:

  1. Register app: https://developer.spotify.com/my-applications/#!/applications
  2. Edit your ~/.bashrc to export following values:
export SPOTIPY_CLIENT_ID='your-spotify-client-id'
export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'

Features

  • Commands
  • Auto suggest (based on history)
  • Tab through history
  • Search history
  • Search and play songs
  • CLI commands
  • VIM navigation bindings

Clone repo

$ git clone https://github.com/bjarneo/Pytify.git
$ cd Pytify
$ sudo python setup.py install

Usage

# To start the app type
$ pytify

# next song
$ pytify -n

# prev song
$ pytify -p

# play and pause song
$ pytify -pp

# Current playing song
$ pytify -c

Commands
commands

Commands:
 current              print current song
 help                 list all commands 
 next                 play next song 
 pp                   play or pause song 
 stop                 stop 
 prev                 play previous song 
 history              last five search results 

Install dev dependencies

pip version must be > 9

$ pip install -r requirements.txt

Dependencies

* requests
* prompt-toolkit

Contributing

Contributions are appreciated.

Contributors

  • @joined - OS X
  • @adam410 - OS X issue
  • @Newky - Better structure
  • @ymski - OS X
  • @wohlfea - Made it compatible with python 3.5
  • @ddiddi - Added search phrase history browsing. (auto complete)
  • @kmatt - Minor UX changes
  • @bharath123 - Updated Pytify to use prompt_toolkit v2
  • .... and other.. please add your name and code update!

Logo

Logo by theodorosploumis. Thank you very much!

Donation

If this project has been helpful in any way, and you want to treat me a cup of coffee, please donate :)

paypal

pytify's People

Contributors

baif666 avatar bharath-123 avatar bjarneo avatar ddiddi avatar dependabot[bot] avatar drewrey avatar gijstimmers avatar joined avatar lucaskolstad avatar magnusknutas avatar nathantym avatar newky avatar theodorosploumis avatar wohlfea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytify's Issues

Not beeing able to change song

I have installed Pytify with pip on Arch Linux.
pityfy -x commands (n,p,pp,c) are working fine, but when I use the search function I can't change to the selected song.

dbus issues [linux]

Dbus times out.

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

Ubuntu 16.10
Spotify version 1.0.38.171.g5e1cd7b2, Copyright (c) 2016, Spotify Ltd

Crashing after 'search'

After searching I get the following error message:

'tracks'
Traceback (most recent call last):
File "/usr/local/bin/pytify", line 11, in
load_entry_point('pytify==3.3.2', 'console_scripts', 'pytify')()
File "/usr/local/lib/python3.5/dist-packages/pytify-3.3.2-py3.5.egg/pytify/cli.py", line 85, in main
File "/usr/local/lib/python3.5/dist-packages/pytify-3.3.2-py3.5.egg/pytify/cli.py", line 19, in init
File "/usr/local/lib/python3.5/dist-packages/pytify-3.3.2-py3.5.egg/pytify/cli.py", line 61, in run
File "/usr/local/lib/python3.5/dist-packages/pytify-3.3.2-py3.5.egg/pytify/cli.py", line 80, in interaction
File "/usr/local/lib/python3.5/dist-packages/pytify-3.3.2-py3.5.egg/pytify/cli.py", line 22, in list_songs
File "/usr/local/lib/python3.5/dist-packages/pytify-3.3.2-py3.5.egg/pytify/song_list.py", line 37, in init
File "/usr/lib/python3.5/curses/init.py", line 94, in wrapper
return func(stdscr, *args, **kwds)
File "/usr/local/lib/python3.5/dist-packages/pytify-3.3.2-py3.5.egg/pytify/song_list.py", line 79, in display
_curses.error: addwstr() returned ERR

And pytify stops...

I looked at some help with this 'addwstr() ERR' and found that might be an issue with libncurses5 or libncursesw5 dependencies. I upgraded both (tried reinstalling only one or both, simlink etc etc) but it not worked at all

Do somebody can help me?

Getting 'tracks' after entering query

Running Spotify 1.0.49.125.g72ee7853 with Pytify 3.3.2 on Ubuntu 17.04.

Installed via pip3.

Problem: after entering my query, pytify returns the string 'tracks'. That's it, no search results or whatsoever.

$ pytify
pytify 3.3.2 [https://github.com/bjarneo/Pytify]
user@laptop - Search:
> ensiferum
'tracks'

The normal commands work:

$ pytify
pytify 3.3.2 [https://github.com/bjarneo/Pytify]
user@laptop - Search:
> /current
Ensiferum - March of War [One Man Army]
user@laptop - Search:
> /pp
user@laptop - Search:
> /pp
user@laptop - Search:
> /next
user@laptop - Search:
> /current
Ensiferum - Axe of Judgement [One Man Army]

Exception after searching

Ive install python using brew on mac osx:

$ brew install python

This install python 2.7

Next I install pytify and I run the pytify command. After I type in a search keyword im getting the following exception

 ~  pytify
pytify 3.3.2 [https://github.com/bjarneo/Pytify]
[email protected] - Search:
> kensington
Traceback (most recent call last):
  File "/usr/local/bin/pytify", line 9, in <module>
    load_entry_point('pytify==3.3.2', 'console_scripts', 'pytify')()
  File "/usr/local/lib/python2.7/site-packages/pytify/cli.py", line 85, in main
    App()
  File "/usr/local/lib/python2.7/site-packages/pytify/cli.py", line 19, in __init__
    self.run()
  File "/usr/local/lib/python2.7/site-packages/pytify/cli.py", line 61, in run
    self.interaction()
  File "/usr/local/lib/python2.7/site-packages/pytify/cli.py", line 80, in interaction
    self.list_songs(list=self.pytify.list())
  File "/usr/local/lib/python2.7/site-packages/pytify/cli.py", line 22, in list_songs
    SongList(list)
  File "/usr/local/lib/python2.7/site-packages/pytify/song_list.py", line 37, in __init__
    curses.wrapper(self.display)
  File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/local/lib/python2.7/site-packages/pytify/song_list.py", line 79, in display
    stdscr.addstr(index, 1, str(item), mode)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 37: ordinal not in range(128)

Help needed :)

Thanks

Error if no song has been started yet

~  pytify
pytify 3.5.2 [https://github.com/bjarneo/Pytify]
Traceback (most recent call last):
  File "/usr/local/bin/pytify", line 11, in <module>
    load_entry_point('pytify==3.5.2', 'console_scripts', 'pytify')()
  File "/usr/local/lib/python3.6/dist-packages/pytify/cli.py", line 85, in main
    App()
  File "/usr/local/lib/python3.6/dist-packages/pytify/cli.py", line 19, in __init__
    self.run()
  File "/usr/local/lib/python3.6/dist-packages/pytify/cli.py", line 61, in run
    self.interaction()
  File "/usr/local/lib/python3.6/dist-packages/pytify/cli.py", line 72, in interaction
    search_input = custom_prompt(self.pytify.get_current_playing())
  File "/usr/local/lib/python3.6/dist-packages/pytify/linux.py", line 32, in get_current_playing
    return self.metadata.get_current_playing()
  File "/usr/local/lib/python3.6/dist-packages/pytify/dbus/metadata.py", line 23, in get_current_playing
    playing['artist'] = value[0]
IndexError: list index out of range

Problem with .service files

Hi,

This app doesn't work.

When I'm launching it, I get the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/song", line 70, in <module>
    app()
  File "/usr/local/bin/song", line 7, in app
    spotify = Spotify.Spotify()
  File "/home/guillaume/bin/PythonSpotify/Spotify.py", line 17, in __init__
    dbus.SessionBus().get_object('org.mpris.MediaPlayer2.spotify', '/org/mpris/MediaPlayer2'),
  File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 241, in get_object
    follow_name_owner_changes=follow_name_owner_changes)
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 248, in __init__
    self._named_service = conn.activate_name_owner(bus_name)
  File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 180, in activate_name_owner
    self.start_service_by_name(bus_name)
  File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 278, in start_service_by_name
    'su', (bus_name, flags)))
  File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.mpris.MediaPlayer2.spotify was not provided by any .service files

ImportError: No module named 'pytifylib'

Installation went fine with pip, dependecy check is okay:

Requirement already satisfied (use --upgrade to upgrade): requests in /usr/lib/python3.5/site-packages

When I try to run pytify I got this error:

Traceback (most recent call last):
  File "/usr/bin/pytify", line 9, in <module>
    load_entry_point('pytify==2.0.5', 'console_scripts', 'pytify')()
  File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 568, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2720, in load_entry_point
    return ep.load()
  File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2380, in load
    return self.resolve()
  File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2386, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3.5/site-packages/pytify/cli.py", line 2, in <module>
    import pytifylib
ImportError: No module named 'pytifylib'

I'm using Arch Linux, python2 and python 3 packages are installed.

Add requirements.txt things.

It would be great, if you can add requirements.txt file.

For easy installing development version of this application:
pip install -r requirements.txt

import error

installed via pip just now

python v3.5.2
pip v9.0.1
python-dbus [installed]
OS => arch linux
kernel => 4.8.13
architecture => x86_64

Traceback here

Some errors occured. Try restart or start Spotify.

When I run pytify in CLI:


$ pytify

Some errors occured. Try restart or start Spotify. 

I install following the tutorial and I did it in Mint, python3.4.3
I don't know what happened, and I will try to fix it myself if there are more information.

For compatibility

use pip install pytify==2.1.0

instead of pip install pytify , which installs the latest build

need spotipy/__init__.py file ?

Traceback (most recent call last):
  File "./cli.py", line 4, in <module>
    from spotipy import spotipy
ImportError: No module named spotipy

Erroring out after entering song number

Type song number and press <enter> to play. Press <enter> for new search.
> 2
22:32: syntax error: A identifier can’t go after this identifier. (-2740)

After doing a quick google, it looks like it has to do with osascript.

Update to prompt toolkit 2

My package manager and pip only provide version 2 of the prompt-toolkit library. This version, among possibly other things, removed the AbortAction method, which causes pytify to fail. Other changes are listed in this changelog.

Implement Oauth / auth

Create a dotfile (.pytifyrc) where people can add their config. Like Oauth keys.

Then we can add more functionality to Pytify.

Python 3 support

Looks like this library would be fairly easy to add python 3 support to. I get an error on line 49 of the cli.py file (where we print).

Looks like an unicode error

I get the following string while I search, I have configured environment variables:

➜  ~ pytify
pytify 3.3.2 [https://github.com/bjarneo/Pytify]
youser - Search:
> i like me better
u'tracks'
youser - Search:
>
 exit: ctrl+d | clear: ctrl+c

Error when i try to run Pytify

Hi everyone.
i'll be quick, when i try to run it returns an IndexError.
Here is the output.
Traceback (most recent call last): File "/usr/local/bin/pytify", line 8, in <module> sys.exit(main()) File "/home/emaa/.local/lib/python3.8/site-packages/pytify/cli.py", line 88, in main App() File "/home/emaa/.local/lib/python3.8/site-packages/pytify/cli.py", line 19, in __init__ self.run() File "/home/emaa/.local/lib/python3.8/site-packages/pytify/cli.py", line 58, in run print(self.pytify.get_current_playing()) File "/home/emaa/.local/lib/python3.8/site-packages/pytify/linux.py", line 32, in get_current_playing return self.metadata.get_current_playing() File "/home/emaa/.local/lib/python3.8/site-packages/pytify/dbus/metadata.py", line 23, in get_current_playing playing['artist'] = value[0] IndexError: list index out of range

I've got a project in my mind so i'll be very greatful if you help me to solve this issue.

Getting 'bool' object is not subscriptable after entering query

Might be related to #54 .

Running Spotify 1.0.49.125.g72ee7853 on Ubuntu 17.04 with pytify, latest git version:

$ git log --pretty=format:'%H' -n 1 
77cf8b767029a00b94764747eadf3db25855aa54

Searching for anything gives an error: 'bool' object is not subscriptable. Other commands work fine.

$ pytify
pytify 3.3.2 [https://github.com/bjarneo/Pytify]
user@laptop - Search:
> ensiferum
Search went wrong? Please try again.
'bool' object is not subscriptable
user@laptop - Search:
> /pp
user@laptop - Search:
> /current
Ensiferum - Axe of Judgement [One Man Army]
user@laptop - Search:
> /pp

Encoding using pytify -c

I used this to print the current song in my tmux status-bar. I encountered a problem with the encoding, not being able to print some foreign characters (åäö in my case) in song titles.
I solved this by:
PYTHONIOENCODING=utf_8 pytify -c
Not sure there's a configuration issue with my system or the script uses another encoding (haven't been able to find that in the source though). Anyway, if anyone wants to use it for the same purposes that's how I solved it.

https://www.reddit.com/r/programming/comments/5hlrcu/spotify_as_a_cli_remote_search_for_and_start_songs/db1yhiv/

Playlist support

Currently it doesn't seem possible to find & play playlists through the search function

17:18: syntax error: Expected end of line but found unknown token. (-2741)

I got this error every time I type a number in order to play a song. Example:

What artist / song are you searching for?
> sinatra
#   | Artist                    | Song                           | Album                         
--- | ------------------------- | ------------------------------ | ------------------------------
1.  | Frank Sinatra             | Let It Snow! Let It Snow! Let  | Christmas Songs By Sinatra    
2.  | Frank Sinatra             | Santa Claus Is Comin' to Town  | Christmas Songs By Sinatra   
...
15. | Frank Sinatra             | Have Yourself a Merry Little C | Christmas Songs By Sinatra    
Last five search results:
sinatra

Type song number and press <enter> to play. Press <enter> for new search.
> 1
17:18: syntax error: Expected end of line but found unknown token. (-2741)

Playing: Frank Sinatra - Let It Snow! Let It Snow! Let

I am running cly.py on virtualenv, python 2.7.8 and Mac OS X Yosemite.
The song I selected didn't play

Logo

We need a logo! Up for grabs!

Must be clean. Simple.

The challenge of automation

I have a bash script file that is set to run automatically: https://github.com/c7v/work_run/blob/master/work_run.sh and I start Spotify before work.I was hoping that there would be music on Spotify at exactly 9:00, which would let me know if I'm not at the computer about the start of work hours. I was planning to run music in Spotify via cron using a script:

#!/bin/sh
/usr/bin/bash -i -c '/usr/local/bin/pytify -pp'

as a result, the script worked, but the music did not turn on, the following error was issued:

Date: Tue, 22 Feb 2022 10:53:01 +0400 (+04)

bash: не удаётся задать группу процесса терминала (21894): Неприменимый к данному устройству ioctl
bash: этот командный процессор не может управлять заданиями
bash: не удаётся задать группу процесса терминала (21894): Неприменимый к данному устройству ioctl
bash: этот командный процессор не может управлять заданиями

Some errors occured. Try restart or start Spotify. Pytify is just a cli application which controls Spotify. So you can't use Pytify without Spotify.

How can I start Spotify music at 9 am automatically?

Thanks for the help and software! ❤️

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.