Skip to content

Commit 1149c7f

Browse files
authored
Merge pull request #659 from JonnyWong16/feature/edit_tags
Don't refresh metadata after editing tags
2 parents 724e669 + c675858 commit 1149c7f

File tree

5 files changed

+119
-74
lines changed

5 files changed

+119
-74
lines changed

plexapi/base.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,21 +458,20 @@ def edit(self, **kwargs):
458458
self._server.query(part, method=self._server._session.put)
459459

460460
def _edit_tags(self, tag, items, locked=True, remove=False):
461-
""" Helper to edit and refresh a tags.
461+
""" Helper to edit tags.
462462
463463
Parameters:
464-
tag (str): tag name
465-
items (list): list of tags to add
466-
locked (bool): lock this field.
467-
remove (bool): If this is active remove the tags in items.
464+
tag (str): Tag name.
465+
items (list): List of tags to add.
466+
locked (bool): True to lock the field.
467+
remove (bool): True to remove the tags in items.
468468
"""
469469
if not isinstance(items, list):
470470
items = [items]
471471
value = getattr(self, tag_plural(tag))
472-
existing_cols = [t.tag for t in value if t and remove is False]
473-
d = tag_helper(tag, existing_cols + items, locked, remove)
474-
self.edit(**d)
475-
self.refresh()
472+
existing_tags = [t.tag for t in value if t and remove is False]
473+
tag_edits = tag_helper(tag, existing_tags + items, locked, remove)
474+
self.edit(**tag_edits)
476475

477476
def refresh(self):
478477
""" Refreshing a Library or individual item causes the metadata for the item to be

plexapi/media.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,10 @@ class Collection(MediaTag):
708708

709709
@utils.registerPlexObject
710710
class Label(MediaTag):
711-
""" Represents a single label media tag.
711+
""" Represents a single Label media tag.
712712
713713
Attributes:
714-
TAG (str): 'label'
714+
TAG (str): 'Label'
715715
FILTER (str): 'label'
716716
"""
717717
TAG = 'Label'
@@ -720,10 +720,10 @@ class Label(MediaTag):
720720

721721
@utils.registerPlexObject
722722
class Tag(MediaTag):
723-
""" Represents a single tag media tag.
723+
""" Represents a single Tag media tag.
724724
725725
Attributes:
726-
TAG (str): 'tag'
726+
TAG (str): 'Tag'
727727
FILTER (str): 'tag'
728728
"""
729729
TAG = 'Tag'

plexapi/mixins.py

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -184,218 +184,240 @@ def fixMatch(self, searchResult=None, auto=False, agent=None):
184184
class CollectionMixin(object):
185185
""" Mixin for Plex objects that can have collections. """
186186

187-
def addCollection(self, collections):
187+
def addCollection(self, collections, locked=True):
188188
""" Add a collection tag(s).
189189
190190
Parameters:
191191
collections (list): List of strings.
192+
locked (bool): True (default) to lock the field, False to unlock the field.
192193
"""
193-
self._edit_tags('collection', collections)
194+
self._edit_tags('collection', collections, locked=locked)
194195

195-
def removeCollection(self, collections):
196+
def removeCollection(self, collections, locked=True):
196197
""" Remove a collection tag(s).
197198
198199
Parameters:
199200
collections (list): List of strings.
201+
locked (bool): True (default) to lock the field, False to unlock the field.
200202
"""
201-
self._edit_tags('collection', collections, remove=True)
203+
self._edit_tags('collection', collections, locked=locked, remove=True)
202204

203205

204206
class CountryMixin(object):
205207
""" Mixin for Plex objects that can have countries. """
206208

207-
def addCountry(self, countries):
209+
def addCountry(self, countries, locked=True):
208210
""" Add a country tag(s).
209211
210212
Parameters:
211213
countries (list): List of strings.
214+
locked (bool): True (default) to lock the field, False to unlock the field.
212215
"""
213-
self._edit_tags('country', countries)
216+
self._edit_tags('country', countries, locked=locked)
214217

215-
def removeCountry(self, countries):
218+
def removeCountry(self, countries, locked=True):
216219
""" Remove a country tag(s).
217220
218221
Parameters:
219222
countries (list): List of strings.
223+
locked (bool): True (default) to lock the field, False to unlock the field.
220224
"""
221-
self._edit_tags('country', countries, remove=True)
225+
self._edit_tags('country', countries, locked=locked, remove=True)
222226

223227

224228
class DirectorMixin(object):
225229
""" Mixin for Plex objects that can have directors. """
226230

227-
def addDirector(self, directors):
231+
def addDirector(self, directors, locked=True):
228232
""" Add a director tag(s).
229233
230234
Parameters:
231235
directors (list): List of strings.
236+
locked (bool): True (default) to lock the field, False to unlock the field.
232237
"""
233-
self._edit_tags('director', directors)
238+
self._edit_tags('director', directors, locked=locked)
234239

235-
def removeDirector(self, directors):
240+
def removeDirector(self, directors, locked=True):
236241
""" Remove a director tag(s).
237242
238243
Parameters:
239244
directors (list): List of strings.
245+
locked (bool): True (default) to lock the field, False to unlock the field.
240246
"""
241-
self._edit_tags('director', directors, remove=True)
247+
self._edit_tags('director', directors, locked=locked, remove=True)
242248

243249

244250
class GenreMixin(object):
245251
""" Mixin for Plex objects that can have genres. """
246252

247-
def addGenre(self, genres):
253+
def addGenre(self, genres, locked=True):
248254
""" Add a genre tag(s).
249255
250256
Parameters:
251257
genres (list): List of strings.
258+
locked (bool): True (default) to lock the field, False to unlock the field.
252259
"""
253-
self._edit_tags('genre', genres)
260+
self._edit_tags('genre', genres, locked=locked)
254261

255-
def removeGenre(self, genres):
262+
def removeGenre(self, genres, locked=True):
256263
""" Remove a genre tag(s).
257264
258265
Parameters:
259266
genres (list): List of strings.
267+
locked (bool): True (default) to lock the field, False to unlock the field.
260268
"""
261-
self._edit_tags('genre', genres, remove=True)
269+
self._edit_tags('genre', genres, locked=locked, remove=True)
262270

263271

264272
class LabelMixin(object):
265273
""" Mixin for Plex objects that can have labels. """
266274

267-
def addLabel(self, labels):
275+
def addLabel(self, labels, locked=True):
268276
""" Add a label tag(s).
269277
270278
Parameters:
271279
labels (list): List of strings.
280+
locked (bool): True (default) to lock the field, False to unlock the field.
272281
"""
273-
self._edit_tags('label', labels)
282+
self._edit_tags('label', labels, locked=locked)
274283

275-
def removeLabel(self, labels):
284+
def removeLabel(self, labels, locked=True):
276285
""" Remove a label tag(s).
277286
278287
Parameters:
279288
labels (list): List of strings.
289+
locked (bool): True (default) to lock the field, False to unlock the field.
280290
"""
281-
self._edit_tags('label', labels, remove=True)
291+
self._edit_tags('label', labels, locked=locked, remove=True)
282292

283293

284294
class MoodMixin(object):
285295
""" Mixin for Plex objects that can have moods. """
286296

287-
def addMood(self, moods):
297+
def addMood(self, moods, locked=True):
288298
""" Add a mood tag(s).
289299
290300
Parameters:
291301
moods (list): List of strings.
302+
locked (bool): True (default) to lock the field, False to unlock the field.
292303
"""
293-
self._edit_tags('mood', moods)
304+
self._edit_tags('mood', moods, locked=locked)
294305

295-
def removeMood(self, moods):
306+
def removeMood(self, moods, locked=True):
296307
""" Remove a mood tag(s).
297308
298309
Parameters:
299310
moods (list): List of strings.
311+
locked (bool): True (default) to lock the field, False to unlock the field.
300312
"""
301-
self._edit_tags('mood', moods, remove=True)
313+
self._edit_tags('mood', moods, locked=locked, remove=True)
302314

303315

304316
class ProducerMixin(object):
305317
""" Mixin for Plex objects that can have producers. """
306318

307-
def addProducer(self, producers):
319+
def addProducer(self, producers, locked=True):
308320
""" Add a producer tag(s).
309321
310322
Parameters:
311323
producers (list): List of strings.
324+
locked (bool): True (default) to lock the field, False to unlock the field.
312325
"""
313-
self._edit_tags('producer', producers)
326+
self._edit_tags('producer', producers, locked=locked)
314327

315-
def removeProducer(self, producers):
328+
def removeProducer(self, producers, locked=True):
316329
""" Remove a producer tag(s).
317330
318331
Parameters:
319332
producers (list): List of strings.
333+
locked (bool): True (default) to lock the field, False to unlock the field.
320334
"""
321-
self._edit_tags('producer', producers, remove=True)
335+
self._edit_tags('producer', producers, locked=locked, remove=True)
322336

323337

324338
class SimilarArtistMixin(object):
325339
""" Mixin for Plex objects that can have similar artists. """
326340

327-
def addSimilarArtist(self, artists):
341+
def addSimilarArtist(self, artists, locked=True):
328342
""" Add a similar artist tag(s).
329343
330344
Parameters:
331345
artists (list): List of strings.
346+
locked (bool): True (default) to lock the field, False to unlock the field.
332347
"""
333-
self._edit_tags('similar', artists)
348+
self._edit_tags('similar', artists, locked=locked)
334349

335-
def removeSimilarArtist(self, artists):
350+
def removeSimilarArtist(self, artists, locked=True):
336351
""" Remove a similar artist tag(s).
337352
338353
Parameters:
339354
artists (list): List of strings.
355+
locked (bool): True (default) to lock the field, False to unlock the field.
340356
"""
341-
self._edit_tags('similar', artists, remove=True)
357+
self._edit_tags('similar', artists, locked=locked, remove=True)
342358

343359

344360
class StyleMixin(object):
345361
""" Mixin for Plex objects that can have styles. """
346362

347-
def addStyle(self, styles):
363+
def addStyle(self, styles, locked=True):
348364
""" Add a style tag(s).
349365
350366
Parameters:
351367
styles (list): List of strings.
368+
locked (bool): True (default) to lock the field, False to unlock the field.
352369
"""
353-
self._edit_tags('style', styles)
370+
self._edit_tags('style', styles, locked=locked)
354371

355-
def removeStyle(self, styles):
372+
def removeStyle(self, styles, locked=True):
356373
""" Remove a style tag(s).
357374
358375
Parameters:
359376
styles (list): List of strings.
377+
locked (bool): True (default) to lock the field, False to unlock the field.
360378
"""
361-
self._edit_tags('style', styles, remove=True)
379+
self._edit_tags('style', styles, locked=locked, remove=True)
362380

363381

364382
class TagMixin(object):
365383
""" Mixin for Plex objects that can have tags. """
366384

367-
def addTag(self, tags):
385+
def addTag(self, tags, locked=True):
368386
""" Add a tag(s).
369387
370388
Parameters:
371389
tags (list): List of strings.
390+
locked (bool): True (default) to lock the field, False to unlock the field.
372391
"""
373-
self._edit_tags('tag', tags)
392+
self._edit_tags('tag', tags, locked=locked)
374393

375-
def removeTag(self, tags):
394+
def removeTag(self, tags, locked=True):
376395
""" Remove a tag(s).
377396
378397
Parameters:
379398
tags (list): List of strings.
399+
locked (bool): True (default) to lock the field, False to unlock the field.
380400
"""
381-
self._edit_tags('tag', tags, remove=True)
401+
self._edit_tags('tag', tags, locked=locked, remove=True)
382402

383403

384404
class WriterMixin(object):
385405
""" Mixin for Plex objects that can have writers. """
386406

387-
def addWriter(self, writers):
407+
def addWriter(self, writers, locked=True):
388408
""" Add a writer tag(s).
389409
390410
Parameters:
391411
writers (list): List of strings.
412+
locked (bool): True (default) to lock the field, False to unlock the field.
392413
"""
393-
self._edit_tags('writer', writers)
414+
self._edit_tags('writer', writers, locked=locked)
394415

395-
def removeWriter(self, writers):
416+
def removeWriter(self, writers, locked=True):
396417
""" Remove a writer tag(s).
397418
398419
Parameters:
399420
writers (list): List of strings.
421+
locked (bool): True (default) to lock the field, False to unlock the field.
400422
"""
401-
self._edit_tags('writer', writers, remove=True)
423+
self._edit_tags('writer', writers, locked=locked, remove=True)

plexapi/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ def download(url, token, filename=None, savepath=None, session=None, chunksize=4
335335
return fullpath
336336

337337

338+
def tag_singular(tag):
339+
if tag == 'countries':
340+
return 'country'
341+
elif tag == 'similar':
342+
return 'similar'
343+
else:
344+
return tag[:-1]
345+
346+
338347
def tag_plural(tag):
339348
if tag == 'country':
340349
return 'countries'

0 commit comments

Comments
 (0)