Skip to content

Commit 36365a9

Browse files
authored
Merge pull request #27 from cmathews393/refactor
Refactor and rewrite
2 parents ed3c9f1 + efeeea5 commit 36365a9

29 files changed

+962
-479
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.env
2+
.toml

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
*.log
77
*.pyc
88
*pycache*
9-
config.toml
9+
config.toml
10+
spotiplex.env

Dockerfile

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
FROM python:latest
22

3+
# Set environment variables
34
ENV SRC_DIR /usr/bin/spotiplex/
4-
COPY ./spotiplex ${SRC_DIR}/
5+
ENV POETRY_VERSION=1.7.1
6+
ENV PYTHONUNBUFFERED=1
7+
ENV CRON_SCHEDULE=@daily
8+
ENV DOCKER=True
9+
# Install Poetry
10+
RUN pip install "poetry==$POETRY_VERSION"
11+
12+
# Copy the application source code
13+
COPY ./spotiplex ${SRC_DIR}/spotiplex
14+
COPY pyproject.toml poetry.lock ${SRC_DIR}/
15+
COPY README.md ${SRC_DIR}/
16+
# Set the working directory
517
WORKDIR ${SRC_DIR}
618

7-
ENV PYTHONUNBUFFERED=1
19+
# Install dependencies with Poetry
20+
RUN poetry config virtualenvs.create false \
21+
&& poetry install --no-interaction --no-ansi
22+
23+
# Install supercronic
24+
RUN wget -O /usr/local/bin/supercronic https://github.com/aptible/supercronic/releases/download/v0.1.11/supercronic-linux-amd64 \
25+
&& chmod +x /usr/local/bin/supercronic
26+
27+
28+
# Copy entrypoint script
29+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
30+
RUN chmod +x /usr/local/bin/entrypoint.sh
31+
32+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
33+
834

9-
RUN pip install -r requirements.txt
10-
CMD ["python", "main.py"]

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [Known Issues](#known-issues)
99
- [Disclaimer](#disclaimer)
1010

11-
**Note:** Temporarily change-frozen, building a new app that implements similar functionality for Radarr, Sonarr, etc, using Trakt and IMDB lists or *arr tags. Will be implemented with a web interface from the start, so is naturally taking a bit more time. [New app repo is here](https://github.com/cmathews393/plex-playlist-manager).
11+
**Note:** Temporarily change-frozen (except for all the times I've updated this instead of working on Playlist Manager), building a new app that implements similar functionality for Radarr, Sonarr, etc, using Trakt and IMDB lists or *arr tags. Will be implemented with a web interface from the start, so is naturally taking a bit more time. [New app repo is here](https://github.com/cmathews393/plex-playlist-manager).
1212

1313
## How To
1414

@@ -25,7 +25,7 @@
2525
- Get Plex API key.
2626
- Get Spotify ID and API key.
2727
- Get Lidarr API key.
28-
3. Run with poetry (`cd spotiplex && poetry install`, `poetry run python main.py`)
28+
3. Run with poetry (`cd spotiplex && poetry install`, `poetry run spotiplex --help`)
2929
4. Follow CLI prompts
3030

3131
### Setup (Docker Version)
@@ -36,17 +36,15 @@ Note: Tested only on Linux, Docker version 24.0.5. Other environments are "unsup
3636
2. `touch spotiplex.env`
3737
3. Copy the contents of `default.env` from this repo to your new `.env` file, and edit as needed.
3838
4. `docker run --env-file spotiplex.env 0xchloe/spotiplex`
39-
5. Re-start the container to re-sync. Manual playlist syncing can be accomplished by including manual playlists in the .env file
39+
5. Container will run sync of Lidarr lists and manually specified lists on initial start, and every day at midnight if CRON_SCHEDULE is not set
4040

4141
## Dependencies
4242

43-
Using [python-plexapi](https://github.com/pkkid/python-plexapi), [spotipy](https://github.com/spotipy-dev/spotipy), [rtoml](https://github.com/samuelcolvin/rtoml) , [schedule](https://github.com/dbader/schedule)
43+
Using [python-plexapi](https://github.com/pkkid/python-plexapi), [spotipy](https://github.com/spotipy-dev/spotipy), [rtoml](https://github.com/samuelcolvin/rtoml), typer, supercronic, httpx
4444

4545
## Upcoming Planned Features
4646

4747
- Add to Plex-Playlist-Manager (See above)
48-
- Add fuzzy search to Plex
49-
- Troubleshoot Spotify API issues (see below)
5048

5149
## Known Issues
5250

compose.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "3.7"
2+
services:
3+
spotiplex:
4+
restart: unless-stopped
5+
image: docker.io/0xchloe/spotiplex:latest
6+
container_name: spotiplex-latest

default.env

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
SPOTIPLEX_LIDARR_SYNC=True
2-
USERS=
3-
WORKERS=5
4-
REPLACE=False
5-
INTERVAL=86400
6-
SPOTIPLEX_MANUAL_PLAYLISTS=
71
SPOTIFY_API_KEY=
82
SPOTIFY_API_ID=
9-
PLEX_URL=
10-
PLEX_TOKEN=
11-
LIDARR_IP=
12-
LIDARR_TOKEN=
3+
PLEX_API_KEY=
4+
PLEX_SERVER_URL=
5+
PLEX_REPLACE=
6+
LIDARR_API_KEY=
7+
LIDARR_API_URL=
8+
PLEX_USERS=user1,user2,user3
9+
WORKER_COUNT=4 #unless you have issues, 4 is a safe default.
10+
# SECONDS_INTERVAL=60 !!--DEPRECATED--!!
11+
MANUAL_PLAYLISTS=
12+
LIDARR_SYNC=False
13+
CRON_SCHEDULE=0 1 * * * #Takes values that are compatible with supercronic. @daily recommended

default_config.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[spotify]
2+
client_id = ""
3+
api_key = ""
4+
5+
[plex]
6+
url = ""
7+
api_key = ""
8+
9+
10+
[lidarr]
11+
url = ""
12+
api_key = ""
13+
14+
[spotiplex]
15+
lidarr_sync = "true"
16+
plex_users = "" #COMMA SEPARATED LIST, NO SPACES! user1,user2 NOT user1, user2
17+
worker_count = 16
18+
seconds_interval = 60 #Deprecated, should be replaced with crontab generator
19+
manual_playlists = "" #No spaces, comma separated. Might work with a mix of IDs and URLs but best to pick one format

entrypoint.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
# Create the crontab file dynamically based on the passed environment variable
4+
echo "${CRON_SCHEDULE} poetry run spotiplex sync-lidarr-imports" > /etc/supercronic-cron
5+
echo "${CRON_SCHEDULE} poetry run spotiplex sync-manual-lists" >> /etc/supercronic-cron
6+
7+
# Run the initial commands
8+
poetry run spotiplex sync-lidarr-imports
9+
poetry run spotiplex sync-manual-lists
10+
11+
# Start supercronic with the generated crontab
12+
exec supercronic /etc/supercronic-cron

0 commit comments

Comments
 (0)