MCPcopy
hub / github.com/blacktwin/JBOPS / plex_deletion

Function plex_deletion

utility/media_manager.py:289–330  ·  view source on GitHub ↗

Parameters ---------- items (list): List of items to be deleted by Plex libraries {list): List of libraries used toggleDeletion (bool): Allow then disable Plex ability to delete media items Returns -------

(items, libraries, toggleDeletion)

Source from the content-addressed store, hash-verified

287
288
289def plex_deletion(items, libraries, toggleDeletion):
290 """
291 Parameters
292 ----------
293 items (list): List of items to be deleted by Plex
294 libraries {list): List of libraries used
295 toggleDeletion (bool): Allow then disable Plex ability to delete media items
296
297 Returns
298 -------
299
300 """
301 plex = PlexServer(PLEX_URL, PLEX_TOKEN)
302 if plex.allowMediaDeletion is None and toggleDeletion is None:
303 print("Allow Plex to delete media.")
304 exit()
305 elif plex.allowMediaDeletion is None and toggleDeletion:
306 print("Temporarily allowing Plex to delete media.")
307 plex._allowMediaDeletion(True)
308 time.sleep(1)
309 plex = PlexServer(PLEX_URL, PLEX_TOKEN)
310
311 print("The following items were added before {} and marked for deletion.".format(opts.date))
312 for item in items:
313 try:
314 if isinstance(item, int):
315 plex_item = plex.fetchItem(item)
316 elif isinstance(item, str):
317 plex_item = plex.fetchItem(int(item))
318 else:
319 plex_item = plex.fetchItem(int(item.rating_key))
320 plex_item.delete()
321 print("Item: {} was deleted".format(plex_item.title))
322 except NotFound:
323 print("Item: {} may already have been deleted.".format(item))
324 for _library in libraries:
325 section = plex.library.sectionByID(_library.key)
326 print("Emptying Trash from library {}".format(_library.title))
327 section.emptyTrash()
328 if toggleDeletion:
329 print("Disabling Plex to delete media.")
330 plex._allowMediaDeletion(False)
331
332
333def last_played_work(sectionID, date=None):

Callers 1

media_manager.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected