Skip to content

Commit

Permalink
Merge pull request #27 from cmathews393/refactor
Browse files Browse the repository at this point in the history
Refactor and rewrite
  • Loading branch information
cmathews393 authored Jun 22, 2024
2 parents ed3c9f1 + efeeea5 commit 36365a9
Show file tree
Hide file tree
Showing 29 changed files with 962 additions and 479 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
.toml
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
*.log
*.pyc
*pycache*
config.toml
config.toml
spotiplex.env
32 changes: 28 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
FROM python:latest

# Set environment variables
ENV SRC_DIR /usr/bin/spotiplex/
COPY ./spotiplex ${SRC_DIR}/
ENV POETRY_VERSION=1.7.1
ENV PYTHONUNBUFFERED=1
ENV CRON_SCHEDULE=@daily
ENV DOCKER=True
# Install Poetry
RUN pip install "poetry==$POETRY_VERSION"

# Copy the application source code
COPY ./spotiplex ${SRC_DIR}/spotiplex
COPY pyproject.toml poetry.lock ${SRC_DIR}/
COPY README.md ${SRC_DIR}/
# Set the working directory
WORKDIR ${SRC_DIR}

ENV PYTHONUNBUFFERED=1
# Install dependencies with Poetry
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi

# Install supercronic
RUN wget -O /usr/local/bin/supercronic https://github.com/aptible/supercronic/releases/download/v0.1.11/supercronic-linux-amd64 \
&& chmod +x /usr/local/bin/supercronic


# Copy entrypoint script
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]


RUN pip install -r requirements.txt
CMD ["python", "main.py"]
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- [Known Issues](#known-issues)
- [Disclaimer](#disclaimer)

**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).
**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).

## How To

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

### Setup (Docker Version)
Expand All @@ -36,17 +36,15 @@ Note: Tested only on Linux, Docker version 24.0.5. Other environments are "unsup
2. `touch spotiplex.env`
3. Copy the contents of `default.env` from this repo to your new `.env` file, and edit as needed.
4. `docker run --env-file spotiplex.env 0xchloe/spotiplex`
5. Re-start the container to re-sync. Manual playlist syncing can be accomplished by including manual playlists in the .env file
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

## Dependencies

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)
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

## Upcoming Planned Features

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

## Known Issues

Expand Down
6 changes: 6 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "3.7"
services:
spotiplex:
restart: unless-stopped
image: docker.io/0xchloe/spotiplex:latest
container_name: spotiplex-latest
21 changes: 11 additions & 10 deletions default.env
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
SPOTIPLEX_LIDARR_SYNC=True
USERS=
WORKERS=5
REPLACE=False
INTERVAL=86400
SPOTIPLEX_MANUAL_PLAYLISTS=
SPOTIFY_API_KEY=
SPOTIFY_API_ID=
PLEX_URL=
PLEX_TOKEN=
LIDARR_IP=
LIDARR_TOKEN=
PLEX_API_KEY=
PLEX_SERVER_URL=
PLEX_REPLACE=
LIDARR_API_KEY=
LIDARR_API_URL=
PLEX_USERS=user1,user2,user3
WORKER_COUNT=4 #unless you have issues, 4 is a safe default.
# SECONDS_INTERVAL=60 !!--DEPRECATED--!!
MANUAL_PLAYLISTS=
LIDARR_SYNC=False
CRON_SCHEDULE=0 1 * * * #Takes values that are compatible with supercronic. @daily recommended
19 changes: 19 additions & 0 deletions default_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[spotify]
client_id = ""
api_key = ""

[plex]
url = ""
api_key = ""


[lidarr]
url = ""
api_key = ""

[spotiplex]
lidarr_sync = "true"
plex_users = "" #COMMA SEPARATED LIST, NO SPACES! user1,user2 NOT user1, user2
worker_count = 16
seconds_interval = 60 #Deprecated, should be replaced with crontab generator
manual_playlists = "" #No spaces, comma separated. Might work with a mix of IDs and URLs but best to pick one format
12 changes: 12 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# Create the crontab file dynamically based on the passed environment variable
echo "${CRON_SCHEDULE} poetry run spotiplex sync-lidarr-imports" > /etc/supercronic-cron
echo "${CRON_SCHEDULE} poetry run spotiplex sync-manual-lists" >> /etc/supercronic-cron

# Run the initial commands
poetry run spotiplex sync-lidarr-imports
poetry run spotiplex sync-manual-lists

# Start supercronic with the generated crontab
exec supercronic /etc/supercronic-cron
Loading

0 comments on commit 36365a9

Please sign in to comment.