Skip to content

Commit

Permalink
Create pip package.
Browse files Browse the repository at this point in the history
  • Loading branch information
ciembor committed Dec 24, 2023
1 parent f735260 commit 4c61ad4
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 32 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
dist/
build/
__pycache__/
*.pyc
*.cache
**/*.egg-info/
**/*.pyc
**/*.cache
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# spotify-cmd v0.1.0
# 💚 spotify-cmd v0.1.2

`spotify-cmd` is a Spotify client that allows controlling the playback of albums and playlists from a *user's library* (based on names or Spotify URIs) and individual tracks (based solely on Spotify URIs). The application is intended for use with [spotifyd](https://github.com/Spotifyd/spotifyd), but it works with any Spotify-enabled device.
`spotify-cmd` is a Spotify client that allows controlling the playback of **albums and playlists from a user's library** (based on names or Spotify URIs) and individual tracks (based solely on Spotify URIs). The application is intended for use with [spotifyd](https://github.com/Spotifyd/spotifyd), but it works with any Spotify-enabled device.

## Installation

Ensure you have Python 3 installed. Then, install the project dependencies using `pip3`:
Ensure you have Python 3 installed. Then, install the project using `pip3`:

```bash
pip3 install -r ./src/spotify-cmd-daemon/requirements.txt
pip3 install -r ./src/spotify-cmd/requirements.txt
pip3 install spotify-cmd
```

## Configuration
Expand All @@ -17,17 +16,18 @@ The application configuration should be located in `~/.config/spotify-cmd/config

```ini
[SPOTIFY]
client_id = your_client_id # Required. Your Spotify application's client ID.
client_secret = your_client_secret # Required. Your Spotify application's client secret.
device_name = your_device_name # Required. The name of your Spotify playback device.
client_id = your_client_id
client_secret = your_client_secret
device_name = your_device_name
redirect_uri = http://localhost:8888/callback

[SPOTIFY_CMD_DAEMON]
socket_path = /tmp/spotify-cmd-daemon.sock
socket_buffer_size = 1024
```

* **client_id**, **client_secret**, and **device_name** are required. Obtain these by creating an app at the [Spotify Developer Dashboard](https://developer.spotify.com/dashboard/applications).
* **client_id**, **client_secret** are required. Obtain these by creating an app at the [Spotify Developer Dashboard](https://developer.spotify.com/dashboard/applications).
* **device_name** is required. `spotify-cmd-daemon` will force to use it even if other is currently active.
* **redirect_uri** is used for Spotify authentication. If not set, it defaults to 'http://localhost:8888/callback'.
* **socket_path** specifies the Unix socket path for the daemon. Defaults to '/tmp/spotify-cmd-daemon.sock'.
* **socket_buffer_size** defines the buffer size for socket communication. Defaults to 1024.
Expand Down
2 changes: 1 addition & 1 deletion bin/spotify-cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/bash
#!/usr/bin/env bash

python3 "$(dirname "$0")/../src/spotify_cmd_client/main.py" "$@"
2 changes: 1 addition & 1 deletion bin/spotify-cmd-daemon
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/bash
#!/usr/bin/env bash

python3 "$(dirname "$0")/../src/spotify_cmd_daemon/main.py" "$@"
46 changes: 46 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
from setuptools import setup, find_packages

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()

setup(
name="spotify-cmd",
version="0.1.2",
packages=find_packages(),
install_requires=[
'argparse==1.4.0',
'configparser==5.0.2',
'spotipy==2.23.0',
'daemon==1.2'
],
entry_points={
'console_scripts': [
'spotify-cmd = src.spotify_cmd_client.main:main',
'spotify-cmd-daemon = src.spotify_cmd_daemon.main:main'
]
},
author="Maciej Ciemborowicz",
author_email="[email protected]",
description="Command line Spotify client",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/ciembor/spotify-cmd",
license="GNU General Public License v3.0",
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: End Users/Desktop',
'Topic :: Multimedia :: Sound/Audio :: Players',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
],
)
21 changes: 10 additions & 11 deletions src/spotify_cmd_client/main.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import socket
import argparse
import json
from client import Client
from .client import Client

def main():
# Parse arguments
parser = argparse.ArgumentParser(description='Client for controlling Spotify playback through a spotify-cmd-daemon.')
subparsers = parser.add_subparsers(dest='command', required=True)

# Basic commands
subparsers.add_parser('play', help='start playback')
subparsers.add_parser('pause', help='pause playback')
subparsers.add_parser('next', help='play next track')
subparsers.add_parser('previous', help='play previous track')
play_parser = subparsers.add_parser('play', help='start playback')
pause_parser = subparsers.add_parser('pause', help='pause playback')
next_parser = subparsers.add_parser('next', help='play next track')
prev_parser = subparsers.add_parser('previous', help='play previous track')

# Set commands
set_parser = subparsers.add_parser('set', help='player settings')
Expand All @@ -34,17 +34,16 @@ def main():
get_subparsers.add_parser('albums', help='get albums')

# Play specific item
play_parser = subparsers.add_parser('play', help='play specific item')
play_subparsers = play_parser.add_subparsers(dest='play_type')
play_type_parser = play_parser.add_subparsers(dest='play_type')

play_playlist_parser = play_subparsers.add_parser('playlist', help='play a specific playlist')
play_playlist_parser = play_type_parser.add_parser('playlist', help='play a specific playlist')
play_playlist_parser.add_argument('name', type=str, help='playlist name')

play_album_parser = play_subparsers.add_parser('album', help='play a specific album')
play_album_parser = play_type_parser.add_parser('album', help='play a specific album')
play_album_parser.add_argument('name', type=str, help='album name')

play_album_parser = play_subparsers.add_parser('uri', help='play resource by spotify URI')
play_album_parser.add_argument('uri', type=str, help='spotify uri')
play_uri_parser = play_type_parser.add_parser('uri', help='play resource by spotify URI')
play_uri_parser.add_argument('uri', type=str, help='spotify uri')

parser.add_argument('--format', choices=['json', 'text', 'verbose'], default='text', help='output format')

Expand Down
1 change: 0 additions & 1 deletion src/spotify_cmd_client/requirements.txt

This file was deleted.

4 changes: 2 additions & 2 deletions src/spotify_cmd_daemon/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import argparse
import os
import daemon
from spotify_controller import SpotifyController
from socket_server import SocketServer
from .spotify_controller import SpotifyController
from .socket_server import SocketServer

def signal_handler(sig, frame, server):
server.stop_server()
Expand Down
3 changes: 0 additions & 3 deletions src/spotify_cmd_daemon/requirements.txt

This file was deleted.

4 changes: 2 additions & 2 deletions src/spotify_cmd_daemon/spotify_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import spotipy
from spotipy.oauth2 import SpotifyOAuth
from spotipy.exceptions import SpotifyException
import operations
from operations.helpers import get_resource_uri
from . import operations
from .operations.helpers import get_resource_uri
from config import Config
from socket_message import SocketMessage

Expand Down

0 comments on commit 4c61ad4

Please sign in to comment.