diff --git a/.gitignore b/.gitignore index 97ddd88..c0e6450 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +dist/ +build/ __pycache__/ -*.pyc -*.cache +**/*.egg-info/ +**/*.pyc +**/*.cache diff --git a/README.md b/README.md index e2110f6..a604ec7 100644 --- a/README.md +++ b/README.md @@ -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 @@ -17,9 +16,9 @@ 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] @@ -27,7 +26,8 @@ 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. diff --git a/bin/spotify-cmd b/bin/spotify-cmd index 51ae8d7..e7e01f2 100755 --- a/bin/spotify-cmd +++ b/bin/spotify-cmd @@ -1,3 +1,3 @@ -#!/usr/bin/bash +#!/usr/bin/env bash python3 "$(dirname "$0")/../src/spotify_cmd_client/main.py" "$@" diff --git a/bin/spotify-cmd-daemon b/bin/spotify-cmd-daemon index 8db76cc..8faaf6a 100755 --- a/bin/spotify-cmd-daemon +++ b/bin/spotify-cmd-daemon @@ -1,3 +1,3 @@ -#!/usr/bin/bash +#!/usr/bin/env bash python3 "$(dirname "$0")/../src/spotify_cmd_daemon/main.py" "$@" diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..1ccd119 --- /dev/null +++ b/setup.py @@ -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="maciej.ciemborowicz@gmail.com", + 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', + ], +) diff --git a/src/spotify_cmd_client/main.py b/src/spotify_cmd_client/main.py index 88315b2..cf5b01d 100644 --- a/src/spotify_cmd_client/main.py +++ b/src/spotify_cmd_client/main.py @@ -1,7 +1,7 @@ import socket import argparse import json -from client import Client +from .client import Client def main(): # Parse arguments @@ -9,10 +9,10 @@ def main(): 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') @@ -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') diff --git a/src/spotify_cmd_client/requirements.txt b/src/spotify_cmd_client/requirements.txt deleted file mode 100644 index f29afc4..0000000 --- a/src/spotify_cmd_client/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -argparse==1.4.0 diff --git a/src/spotify_cmd_daemon/main.py b/src/spotify_cmd_daemon/main.py index 79da7f6..30e3160 100644 --- a/src/spotify_cmd_daemon/main.py +++ b/src/spotify_cmd_daemon/main.py @@ -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() diff --git a/src/spotify_cmd_daemon/requirements.txt b/src/spotify_cmd_daemon/requirements.txt deleted file mode 100644 index 2054d0f..0000000 --- a/src/spotify_cmd_daemon/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -configparser==5.0.2 -spotipy==2.26.0 -daemon==1.2 diff --git a/src/spotify_cmd_daemon/spotify_controller.py b/src/spotify_cmd_daemon/spotify_controller.py index 6a34078..d7f8c46 100644 --- a/src/spotify_cmd_daemon/spotify_controller.py +++ b/src/spotify_cmd_daemon/spotify_controller.py @@ -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