@@ -21,9 +21,7 @@ def __init__(self):
21
21
"plex_users" : os .environ .get ("USERS" , "" ),
22
22
"worker_count" : int (os .environ .get ("WORKERS" , 1 )),
23
23
"seconds_interval" : int (os .environ .get ("INTERVAL" , 86400 )),
24
- "manual_playlists" : os .environ .get (
25
- "SPOTIPLEX_MANUAL_PLAYLISTS" , "False"
26
- ),
24
+ "manual_sync" : os .environ .get ("SPOTIPLEX_MANUAL_PLAYLISTS" , "False" ),
27
25
}
28
26
write_config ("spotiplex" , spotiplex_config )
29
27
@@ -63,10 +61,20 @@ def __init__(self):
63
61
if self .lidarr_sync == "true" :
64
62
self .sync_lists = self .lidarr_api .get_lidarr_playlists ()
65
63
else :
66
- self .sync_lists = self .config .get ("manual_playlists" )
64
+ self .sync_lists = []
65
+ manual_playlists = self .config .get ("manual_playlists" , "" )
66
+ if manual_playlists :
67
+ # If manual_playlists is a string of items separated by commas, split it into a list
68
+ manual_playlists_list = manual_playlists .split ("," )
69
+ # Then extend self.sync_lists with this list
70
+ self .sync_lists .extend (manual_playlists_list )
71
+ print (manual_playlists )
72
+ self .sync_my_user = False
67
73
currentuser = self .plex_service .plex .myPlexAccount ().username .lower ()
74
+
68
75
if currentuser in self .user_list :
69
76
self .user_list .remove (currentuser )
77
+ self .sync_my_user = True
70
78
71
79
def process_for_user (self , user ):
72
80
if user :
@@ -92,9 +100,24 @@ def process_for_user(self, user):
92
100
print (f"Thread resulted in an error: { e } " )
93
101
94
102
def is_running_in_docker ():
95
- return os .path .exists ("/.dockerenv" )
103
+ # Check for the .dockerenv file
104
+ if os .path .exists ("/.dockerenv" ):
105
+ return True
106
+
107
+ # Check for container-related entries in /proc/1/cgroup
108
+ try :
109
+ with open ("/proc/1/cgroup" , "rt" ) as f :
110
+ if any ("docker" in line or "containerd" in line for line in f ):
111
+ return True
112
+ except Exception :
113
+ pass
114
+
115
+ return False
96
116
97
117
def run (self ):
118
+ self .plex_service = PlexService ()
119
+ if self .sync_my_user :
120
+ self .process_for_user (None )
98
121
for user in self .user_list :
99
122
self .process_for_user (user )
100
123
if self .seconds_interval > 0 :
@@ -103,32 +126,32 @@ def run(self):
103
126
schedule .run_pending ()
104
127
time .sleep (1 )
105
128
106
- def extract_playlist_id (playlist_url ): # parse playlist ID from URL if applicable
129
+ def extract_playlist_id (playlist_url ):
130
+ # Check and extract the part after "?si="
107
131
if "?si=" in playlist_url :
108
132
playlist_url = playlist_url .split ("?si=" )[0 ]
109
133
110
- return (
111
- playlist_url . split ( "playlist/" )[ 1 ]
112
- if "playlist/" in playlist_url
113
- else playlist_url
114
- )
134
+ # Check and extract the part after "playlist/"
135
+ if "playlist/" in playlist_url :
136
+ playlist_url = playlist_url . split ( "playlist/" )[ 1 ]
137
+
138
+ return playlist_url
115
139
116
140
def process_playlist (
117
- self , playlists , plex_service , spotify_service , replace_existing
141
+ self , playlist , plex_service , spotify_service , replace_existing
118
142
):
119
- for playlist in playlists :
120
- try :
121
- playlist_id = Spotiplex .extract_playlist_id (playlist )
122
- print (playlist_id )
123
- playlist_name = spotify_service .get_playlist_name (playlist_id )
124
- spotify_tracks = spotify_service .get_playlist_tracks (playlist_id )
125
- plex_tracks = plex_service .check_tracks_in_plex (spotify_tracks )
126
- plex_service .create_or_update_playlist (
127
- playlist_name , playlist_id , plex_tracks
128
- )
129
- print (f"Processed playlist '{ playlist_name } '." )
130
- except Exception as e :
131
- print (f"Error processing playlist '{ playlist } ':" , e )
143
+ try :
144
+ playlist_id = Spotiplex .extract_playlist_id (playlist )
145
+ print (playlist_id )
146
+ playlist_name = spotify_service .get_playlist_name (playlist_id )
147
+ spotify_tracks = spotify_service .get_playlist_tracks (playlist_id )
148
+ plex_tracks = plex_service .check_tracks_in_plex (spotify_tracks )
149
+ plex_service .create_or_update_playlist (
150
+ playlist_name , playlist_id , plex_tracks
151
+ )
152
+ print (f"Processed playlist '{ playlist_name } '." )
153
+ except Exception as e :
154
+ print (f"Error processing playlist '{ playlist } ':" , e )
132
155
133
156
def configurator (self ):
134
157
# Config for Spotiplex
0 commit comments