10
10
from modules .EmbyInterface import EmbyInterface
11
11
from modules .EpisodeInfo import EpisodeInfo
12
12
from modules .ImageMaker import ImageMaker
13
+ from modules .JellyfinInterface import JellyfinInterface
13
14
from modules .PlexInterface import PlexInterface
14
15
from modules .PreferenceParser import PreferenceParser
15
16
from modules .global_objects import set_preference_parser
65
66
default = SUPPRESS ,
66
67
help = 'Print the last log file' )
67
68
68
- # Argument group for Plex
69
+ # Argument group for the media server
69
70
media_server_group = parser .add_argument_group ('Media Server' )
70
71
media_server_group .add_argument (
71
72
'--import-cards' , '--import-archive' , '--load-archive' ,
72
73
type = str ,
73
74
nargs = 2 ,
74
75
default = SUPPRESS ,
75
76
metavar = ('ARCHIVE_DIRECTORY' , 'LIBRARY' ),
76
- help = 'Import an archive of Title Cards into Emby/Plex' )
77
+ help = 'Import an archive of Title Cards into Emby/Jellyfin/ Plex' )
77
78
media_server_group .add_argument (
78
79
'--import-series' , '--load-series' ,
79
80
type = str ,
101
102
nargs = 3 ,
102
103
default = SUPPRESS ,
103
104
metavar = ('LIBRARY' , 'NAME' , 'YEAR' ),
104
- help = 'Remove the cards for the given series within Emby/Plex' )
105
+ help = 'Remove the cards for the given series within Emby/Jellyfin/Plex' )
106
+ media_server_group .add_argument (
107
+ '--id' , '--series-id' ,
108
+ type = str ,
109
+ nargs = 2 ,
110
+ default = [],
111
+ action = 'append' ,
112
+ metavar = ('ID_TYPE' , 'ID' ),
113
+ help = 'Specify database IDs of a series for importing/reloading cards' )
105
114
106
115
# Argument group for Sonarr
107
116
sonarr_group = parser .add_argument_group ('Sonarr' )
183
192
print (file_handle .read ())
184
193
185
194
186
- # Execute Emby/Plex options
187
- if (hasattr (args , 'import_cards' )
188
- or hasattr ( args , 'revert_series' )) and ( pp .use_plex or pp .use_emby ):
195
+ # Execute Media Server options
196
+ if (( hasattr (args , 'import_cards' ) or hasattr ( args , 'revert_series' ) )
197
+ and any (( pp . use_emby , pp .use_jellyfin , pp .use_plex )) ):
189
198
# Temporary classes
190
199
@dataclass
191
200
class Episode :
192
201
destination : Path
193
202
episode_info : EpisodeInfo
194
203
spoil_type : str
195
204
196
- # Create Emby/PlexInterface
197
- if args .media_server == 'plex' :
198
- media_interface = PlexInterface (** pp .plex_interface_kwargs )
199
- else :
205
+ # Create MediaServer Interface
206
+ if args .media_server == 'emby' :
200
207
media_interface = EmbyInterface (** pp .emby_interface_kwargs )
208
+ elif args .media_server == 'jellyfin' :
209
+ media_interface = JellyfinInterface (** pp .jellyfin_interface_kwargs )
210
+ else :
211
+ media_interface = PlexInterface (** pp .plex_interface_kwargs )
201
212
202
213
# Get series/name + year from archive directory if unspecified
203
214
if hasattr (args , 'import_cards' ):
@@ -217,6 +228,14 @@ class Episode:
217
228
archive = pp .source_directory / series_info .full_clean_name
218
229
library = args .revert_series [0 ]
219
230
231
+ # Get series ID's if provided
232
+ if args .id :
233
+ for id_type , id_ in args .id :
234
+ try :
235
+ getattr (series_info , f'set_{ id_type } _id' )(id_ )
236
+ except Exception as e :
237
+ log .error (f'Unrecognized ID type "{ id_type } " - { e } ' )
238
+
220
239
# Forget cards associated with this series
221
240
media_interface .remove_records (library , series_info )
222
241
@@ -226,7 +245,7 @@ class Episode:
226
245
log .warning (f'No images to import' )
227
246
exit (1 )
228
247
229
- # For each image, fill out episode map to load into Emby/Plex
248
+ # For each image, fill out episode map to load into server
230
249
episode_map = {}
231
250
for image in all_images :
232
251
if (groups := match (r'.*s(\d+).*e(\d+)' , image .name , IGNORECASE )):
@@ -239,18 +258,21 @@ class Episode:
239
258
ep = Episode (image , EpisodeInfo ('' , season , episode ), 'spoiled' )
240
259
episode_map [f'{ season } -{ episode } ' ] = ep
241
260
242
- # Load images into Emby/Plex
243
- media_interface .set_title_cards (library , series_info ,episode_map )
261
+ # Load images into server
262
+ media_interface .set_title_cards (library , series_info , episode_map )
244
263
245
- if hasattr (args , 'forget_cards' ) and (pp .use_plex or pp .use_emby ):
246
- # Create interface and remove records for indicated series+library
264
+ # Create interface and remove records for indicated series+library
265
+ if (hasattr (args , 'forget_cards' )
266
+ and any ((pp .use_emby , pp .use_jellyfin , pp .use_plex ))):
247
267
series_info = SeriesInfo (args .forget_cards [1 ], args .forget_cards [2 ])
248
-
249
- # Create Emby/PlexInterface
250
268
if args .media_server == 'emby' :
251
269
EmbyInterface (** pp .emby_interface_kwargs ).remove_records (
252
270
args .forget_cards [0 ], series_info ,
253
271
)
272
+ elif args .media_server == 'jellyfin' :
273
+ JellyfinInterface (** pp .jellyfin_interface_kwargs ).remove_records (
274
+ args .forget_cards [0 ], series_info ,
275
+ )
254
276
else :
255
277
PlexInterface (** pp .plex_interface_kwargs ).remove_records (
256
278
args .forget_cards [0 ], series_info ,
0 commit comments