Skip to content

Commit 8ae9c14

Browse files
committed
Updating templates and README
1 parent fe8562a commit 8ae9c14

File tree

8 files changed

+131
-33
lines changed

8 files changed

+131
-33
lines changed

README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
# Spotify To Plex (Spotiplex)
22

3-
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/C0C2PUDV8)
4-
3+
<div style="text-align: center;">
4+
<img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/cmathews393/spotify-to-plex/docker-image.yml">
5+
<img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/0xchloe/spotiplex">
6+
<img alt="GitHub Sponsors" src="https://img.shields.io/github/sponsors/cmathews393">
7+
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/cmathews393/spotify-to-plex">
8+
<img src="https://img.shields.io/liberapay/receives/0xChloe.svg?logo=liberapay">
9+
</div>
10+
<div style="text-align: center;">
11+
<a href="https://ko-fi.com/C0C2PUDV8">
12+
<img src="https://ko-fi.com/img/githubbutton_sm.svg" alt="ko-fi" style="margin: 5px;">
13+
</a>
14+
15+
</div>
516
## Table of Contents
617

718
- [How To](#how-to)
@@ -19,7 +30,7 @@
1930
1. Ensure you have Python 3 installed (if not running docker)
2031
2. Ensure you have poetry installed
2132

22-
### Setup (Script Version)
33+
### Setup (Script Version - Not Recommended)
2334

2435
1. Clone the repo.
2536
2. Configure settings for your environment:

spotiplex/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def playlists_view():
7373
playlists = web_functions.get_playlists_data()
7474
return render_template("playlists.html.j2", playlists=playlists)
7575

76+
@app.route("/support")
77+
def support_us():
78+
return render_template("support.html.j2")
7679

7780
# @app.route('')
7881

spotiplex/main.py

+30-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self):
5252
self.plex_service = PlexService()
5353
self.lidarr_api = lapi()
5454

55-
self.lidarr_sync = (self.config.get("lidarr_sync", "false")).lower()
55+
self.lidarr_sync = self.config.get("lidarr_sync", False)
5656
if (
5757
self.config.get("plex_users") != ""
5858
and self.config.get("plex_users") is not None
@@ -65,7 +65,7 @@ def __init__(self):
6565
self.replace_existing = self.config.get("replace_existing")
6666
self.seconds_interval = int(self.config.get("seconds_interval"))
6767

68-
if self.lidarr_sync == "true":
68+
if self.lidarr_sync is True:
6969
self.sync_lists = self.lidarr_api.get_lidarr_playlists()
7070
else:
7171
self.sync_lists = []
@@ -161,18 +161,41 @@ def process_playlist(
161161
print(f"Error processing playlist '{playlist}':", e)
162162

163163
def get_data_for_playlist(self):
164-
playlists_data = {}
165-
for playlist in self.sync_lists:
164+
def fetch_playlist_data(playlist):
166165
try:
167166
playlist_id = Spotiplex.extract_playlist_id(playlist)
168167
playlist_name = self.spotify_service.get_playlist_name(playlist_id)
168+
if playlist_name is None:
169+
playlist_name = f"Error processing playlist ID {playlist_id}"
169170
spotify_tracks = self.spotify_service.get_playlist_tracks(playlist_id)
170-
playlists_data[playlist_name] = spotify_tracks
171+
return playlist_name, spotify_tracks
171172
except Exception as e:
172173
print(f"Error processing playlist {playlist}: {e}")
173-
# Optionally, handle the error (e.g., by logging or skipping the problematic playlist)
174-
continue
174+
# Return a tuple indicating an error with the playlist to handle later
175+
return f"Error processing playlist ID {playlist_id}", None
176+
177+
playlists_data = {}
178+
with ThreadPoolExecutor(max_workers=self.worker_count) as executor:
179+
# Schedule the fetch_playlist_data function to be called for each playlist
180+
future_to_playlist = {
181+
executor.submit(fetch_playlist_data, playlist): playlist
182+
for playlist in self.sync_lists
183+
}
184+
185+
for future in concurrent.futures.as_completed(future_to_playlist):
186+
playlist = future_to_playlist[future]
187+
try:
188+
playlist_name, spotify_tracks = future.result()
189+
if (
190+
spotify_tracks is not None
191+
): # Ensure there was no error fetching data
192+
playlists_data[playlist_name] = spotify_tracks
193+
except Exception as e:
194+
print(f"Exception processing playlist {playlist}: {e}")
195+
continue
196+
175197
return playlists_data
198+
176199
def configurator(self):
177200
# Config for Spotiplex
178201

spotiplex/static/css/style.css

+5
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ body {
8080
color: #be5cff; /* A distinct color for the artist name */
8181
font-style: italic; /* Italicize artist name for differentiation */
8282
}
83+
84+
.playlist-error {
85+
color: red;
86+
font-style: bold;
87+
}

spotiplex/templates/base.html.j2

+18
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<li class="nav-item">
2929
<a class="nav-link" href="/playlists">Playlists</a>
3030
</li>
31+
<li class="nav-item">
32+
<a class="nav-link" href="/support">Support Us</a>
33+
</li>
34+
3135
</ul>
3236
</div>
3337
</nav>
@@ -49,7 +53,21 @@
4953
<br>
5054
Contact us: <a href="mailto:[email protected]">[email protected]</a>
5155
<br>
56+
<a href="/support">Support Spotiplex</a>
5257
</div>
5358
</footer>
5459

60+
{% if request.path != "/support" %}
61+
<script src='https://storage.ko-fi.com/cdn/scripts/overlay-widget.js'></script>
62+
<script>
63+
kofiWidgetOverlay.draw('0xchloe', {
64+
'type': 'floating-chat',
65+
'floating-chat.donateButton.text': 'Tip Me',
66+
'floating-chat.donateButton.background-color': '#794bc4',
67+
'floating-chat.donateButton.text-color': '#fff'
68+
});
69+
</script>
70+
{% endif %}
71+
72+
5573
</html>

spotiplex/templates/playlists.html.j2

+47-23
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,59 @@
33
{% block title %}Playlists - Spotiplex{% endblock %}
44

55
{% block content %}
6+
<script>
7+
var startTime = new Date();
8+
</script>
9+
610
<div class="container mt-4">
711
<h1>Playlists</h1>
812
{% for playlist_name, tracks in playlists.items() %}
9-
<div class="card mt-3">
10-
<div class="card-header" id="heading{{ loop.index }}">
11-
<h2 class="mb-0">
12-
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse" data-target="#collapse{{ loop.index }}" aria-expanded="true" aria-controls="collapse{{ loop.index }}">
13-
{{ playlist_name }}
14-
</button>
15-
</h2>
16-
</div>
13+
<div class="card mt-3">
14+
<div class="card-header" id="heading{{ loop.index }}">
15+
<h2 class="mb-0">
16+
{# Apply red color to playlist name if it contains an error #}
17+
{% if "Error processing playlist" in playlist_name %}
18+
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse"
19+
data-target="#collapse{{ loop.index }}" aria-expanded="true"
20+
aria-controls="collapse{{ loop.index }}" style="color: red;">
21+
{{ playlist_name }}
22+
</button>
23+
{% else %}
24+
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse"
25+
data-target="#collapse{{ loop.index }}" aria-expanded="true"
26+
aria-controls="collapse{{ loop.index }}">
27+
{{ playlist_name }}
28+
</button>
29+
{% endif %}
30+
</h2>
31+
</div>
1732

18-
<div id="collapse{{ loop.index }}" class="collapse" aria-labelledby="heading{{ loop.index }}">
19-
<div class="card-body">
20-
<div class="tracks">
21-
<h3>Tracks</h3>
22-
<ul>
23-
{% for track in tracks %}
24-
<li>
25-
<span class="track-name">{{ track[0] }}</span>
26-
<span class="by-text">by</span>
27-
<span class="artist-name">{{ track[1] }}</span>
28-
</li>
29-
{% endfor %}
30-
</ul>
31-
</div>
33+
{# Only populate tracks if playlist_name does not contain an error #}
34+
{% if "Error processing playlist" not in playlist_name %}
35+
<div id="collapse{{ loop.index }}" class="collapse" aria-labelledby="heading{{ loop.index }}">
36+
<div class="card-body">
37+
<div class="tracks">
38+
<h3>Tracks</h3>
39+
<ul>
40+
{% for track in tracks %}
41+
<li>
42+
<span class="track-name">{{ track[0] }}</span>
43+
<span class="by-text">by</span>
44+
<span class="artist-name">{{ track[1] }}</span>
45+
</li>
46+
{% endfor %}
47+
</ul>
3248
</div>
3349
</div>
3450
</div>
51+
{% else %}
52+
53+
{% endif %}
54+
</div>
3555
{% endfor %}
56+
3657
</div>
37-
{% endblock %}
58+
59+
60+
61+
{% endblock %}

spotiplex/templates/support.html.j2

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% extends "base.html.j2" %}
2+
3+
{% block content%}
4+
<iframe id='kofiframe' src='https://ko-fi.com/0xchloe/?hidefeed=true&widget=true&embed=true&preview=true' style='border:none;width:100%;padding:4px;background:#f9f9f9;' height='712' title='0xchloe'></iframe>
5+
{%endblock%}

spotiplex/templates/sync.html.j2

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% extends "base.html.j2" %}
2+
3+
{%block title %} Sync {%endblock%}
4+
5+
{%block content%}
6+
7+
8+
9+
{%endblock%}

0 commit comments

Comments
 (0)