Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,5 @@ music
config
Music
/docker-compose.yml
dev*
dev*
/examples/config.json
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
**v3.0.3 (26 Mar 2024)**
- Enviroment Variables removed and added docker secrets for more security

**v3.0.2 (22 Dec 2023)**
- already downloaded log entries become info instead of warning
- use `logger` instead of `logging`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Tested with versions `3.10 <= python <= 3.12`, however slightly older versions p
cd examples
```

Edit `docker-compose.yml` with your username and password.
Copy `config.example.json` to `config.json` and enter your username and password

```bash
sudo docker compose run --rm zyspotify -lsdall
Expand Down
4 changes: 4 additions & 0 deletions examples/config.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"USERNAME": "example@gmail.com",
"PASSWORD": "hunter2"
}
10 changes: 4 additions & 6 deletions examples/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ version: "3"
services:
zyspotify:
image: kaitallaoua/zyspotify

secrets:
- spotify_login
# bind to a vpn container already running if desired
# such as https://github.com/wfg/docker-openvpn-client
# network_mode: container:openvpn-client
volumes:
- ./log:/root/zyspotify_log
- ./config:/root/config
- ./Music:/root/Music
environment:

# These should be removed after the first run. since credentials cached in db
- USERNAME=example@gmail.com
- PASSWORD=hunter2
secrets:
- spotify_login: ./config.json
12 changes: 9 additions & 3 deletions zyspotify/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@
import logging
from logging.handlers import RotatingFileHandler
from logging.config import dictConfig

from json import loads
import errno

try:
__version__ = metadata.version("zyspotify")
except metadata.PackageNotFoundError:
__version__ = "unknown"

_USERNAME = os.environ.get("USERNAME", None)
_PASSWORD = os.environ.get("PASSWORD", None)
_USERNAME = None
_PASSWORD = None
with open("/run/secrets/spotify_login") as login:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick but can you use pathlib for this purpose. something like json.loads(Path('path/filename').read_text()

login = loads(login)
if "USERNAME" in login:
_USERNAME = login["USERNAME"]
if "PASSWORD" in login:
_PASSWORD = login["PASSWORD"]

GENERIC_MAX_STR_LEN = 50

Expand Down