-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
709 lines (648 loc) · 34.1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
import os
import sys
import argparse
from pathlib import Path
from typing import Union
from dotenv import load_dotenv
import plexapi.exceptions
from plexapi.server import PlexServer
from plexapi.library import LibrarySection
from plexapi.collection import Collection
from plexapi.video import Movie, Show
from plexapi.media import Field, Guid
import requests
from tqdm import tqdm
import yaml
load_dotenv(override=True) # Take environment variables from .env
class PlexCollectionMaker:
"""Create collections in Plex libraries from a text file list of shows or movies."""
def __init__(self, edit_collections: bool):
"""
Create collections in Plex libraries from a text file list of shows or movies.
Args:
edit_collections (bool, optional): If true, load collection config files. If false, skip loading any
collection configs.
"""
self.load_config(edit_collections)
self.plex_setup()
def load_config(self, edit_collections: bool) -> None:
"""
Load environment variables from .env and library configuration from config.yml.
Args:
edit_collections (bool, optional): If true, load collection config files. If false, skip loading any
collection configs.
"""
self.using_public_ip = False
try:
self.plex_token = os.environ["PLEX_TOKEN"]
except KeyError:
sys.exit('Cannot find "PLEX_TOKEN" in .env file. Please consult the README.')
try:
self.plex_ip = os.environ["PLEX_SERVER_IP"]
except KeyError:
# Fallback to public ip
try:
self.plex_ip = os.environ["PLEX_SERVER_PUBLIC_IP"]
self.using_public_ip = True
except KeyError:
sys.exit("Cannot find IP address in .env file. Please consult the README.")
try:
if not self.using_public_ip:
self.plex_pub_ip = os.environ["PLEX_SERVER_PUBLIC_IP"]
else:
self.plex_pub_ip = None
except KeyError:
# Only local ip given
self.plex_pub_ip = None
# Ensure "http://" at start of ip address
for ip in [self.plex_ip, self.plex_pub_ip]:
if ip and (ip[:7] != "http://") and (ip[:8] != "https://"):
sys.exit(
'Invalid IP address. Ensure IP address begins "http://". '
'Please check the server IP addresses in .env, and consult the README.'
)
with open("./config.yml", encoding="utf-8") as config_file:
try:
config_yaml = yaml.safe_load(config_file)
except yaml.YAMLError as err:
print(err)
self.libraries = [*config_yaml["libraries"]]
self.collections_config = {}
if edit_collections:
for lib in config_yaml["libraries"]:
for coll_file in config_yaml["libraries"][lib]["collection_files"]:
with open(coll_file["file"], "r", encoding="utf-8") as collection_config_file:
try:
colls = yaml.safe_load(collection_config_file)
if self.collections_config.get(lib):
self.collections_config[lib].update(colls["collections"])
else:
self.collections_config[lib] = colls["collections"]
except yaml.YAMLError as err:
print(err)
def plex_setup(self) -> None:
"""
Load PlexAPI config and connect to server.
"""
try:
self.plex = PlexServer(self.plex_ip, self.plex_token)
except requests.exceptions.InvalidURL:
sys.exit("Invalid IP address. Please check the server IP addresses in .env, and consult the README.")
except requests.exceptions.RequestException:
if self.plex_pub_ip:
try:
self.plex = PlexServer(self.plex_pub_ip, self.plex_token)
except requests.exceptions.RequestException:
sys.exit(
"Unable to connect to Plex server. Please check the server "
"IP addresses in .env, and consult the README."
)
except plexapi.exceptions.Unauthorized:
sys.exit('Invalid Plex token. Please check the "PLEX_TOKEN" in .env, and consult the README.')
else:
sys.exit(
"Unable to connect to Plex server. Please check the "
f'{"PLEX_SERVER_PUBLIC_IP" if self.using_public_ip else "PLEX_SERVER_IP"} '
"in .env, and consult the README."
)
except plexapi.exceptions.Unauthorized:
sys.exit('Invalid Plex token. Please check the "PLEX_TOKEN" in .env, and consult the README.')
def get_libraries(self) -> "dict[str, LibrarySection]":
"""
Return accessible Plex libraries.
Returns:
dict[str, LibrarySection]: {library name: Plex library object}
"""
plex_libraries: "dict[str, LibrarySection]" = {}
for library in self.libraries:
try:
plex_libraries[library] = self.plex.library.section(library)
except plexapi.exceptions.NotFound:
sys.exit(f'Library named "{library}" not found. Please check the config.yml, and consult the README.')
return plex_libraries
def get_item_guid(
self, title: str, lib_type: str, full: bool = False
) -> str:
"""
Get available GUID from provided item string.
Args:
title (str): String that contains a GUID in the form {[source]-[id]}.
Plex guid is in the form plex://[type]/[id]
lib_type (str): either "movie" or "show" to determine available GUIDs
full (bool, optional): If false, return only id ([type]/[id] if Plex).
If true, return full GUID, [source]://[id] (including type if Plex).
Defaults to False.
Raises:
plexapi.exceptions.UnknownType: if provided lib_type is neither "movie" or "show"
Returns:
str: the available GUID of the title, returns "-1" if no GUID is available
"""
try:
lib_sources = {
"movie": ["tmdb", "imdb", "plex"],
"show": ["tvdb", "tmdb", "plex"]
}
for source in lib_sources[lib_type]:
if title.find(source) == -1:
# source not found in title
continue
if source == "plex":
guid = title.split(sep="plex://")[-1].split()[0]
else:
guid = title.split(sep=f"{{{source}-")[-1].split(sep="}")[0]
if full:
return f"{source}://{guid}"
return guid
return "-1"
except KeyError as exc:
raise plexapi.exceptions.UnknownType from exc
def make_collections(self, plex_libraries: "dict[str, LibrarySection]") -> "dict[str, list[Collection]]":
"""
Create new regular collections from config lists.
Args:
plex_libraries (dict[str, LibrarySection]): {library name: Plex library object}
Returns:
dict[str, list[Collection]]: {library name: list[Collection]} Preexisting collections to check for updates.
"""
collections_to_update: "dict[str, list[Collection]]" = {}
explained_guid = False
for library in plex_libraries.items():
collections_to_update[library[0]] = []
collection_title: str
for collection_title in [*self.collections_config[library[0]].keys()]:
try:
collection: Collection = library[1].collection(collection_title)
# If the collection was found, add to list to update/sync and continue to next in config
collections_to_update[library[0]].append(collection)
except plexapi.exceptions.NotFound:
# If the collection wasn't found in the library, add items according to config list
print(f'Creating "{collection_title}" collection in "{library[0]}" library...')
collection_items: "list[Movie | Show]" = []
if ("items" in self.collections_config[library[0]][collection_title]
and self.collections_config[library[0]][collection_title]["items"]
):
config_item: str
for config_item in self.collections_config[library[0]][collection_title]["items"]:
try:
# Find library item using plex guid, if provided
collection_items.append(
library[1].getGuid(self.get_item_guid(config_item, library[1].type, full=True))
)
except plexapi.exceptions.NotFound:
try:
# Fall back to item name, library.get(title) doesn't always return the
# actual item with exact title (eg Horror-of-Dracula for Drácula),
# so find match in full search
search = next(
(
lib_item for lib_item in plex_libraries[library[0]].search(
title=config_item.split(' plex://')[0].split(' {')[0]
) if lib_item.title == config_item.split(' plex://')[0].split(' {')[0]
),
None
)
if search is None:
raise plexapi.exceptions.NotFound from None
collection_items.append(search)
if not explained_guid:
print(
"\033[33mGUID not available, incorrect matches may occur.\033[0m "
"If incorrect items added to collection, consider dumping library "
"and using given title from output file."
)
explained_guid = True
except plexapi.exceptions.NotFound:
print(
f'\033[33mItem "{config_item.split(" plex://")[0]}" not found in '
f'"{library[0]}" library.\033[0m'
)
if len(collection_items) > 0:
# Create collection
collection: Collection = library[1].createCollection(
title=collection_title, items=collection_items
)
fields = [
("titleSort", collection.editSortTitle),
("contentRating", collection.editContentRating),
("summary", collection.editSummary),
("labels", collection.addLabel),
("poster", collection.uploadPoster),
("mode", collection.modeUpdate),
("sort", collection.sortUpdate)
]
for field, edit_func in fields:
if (field in self.collections_config[library[0]][collection_title]
and self.collections_config[library[0]][collection_title][field]
):
if field == "poster":
if (self.collections_config[
library[0]][collection_title][field][:7] == "http://"
or self.collections_config[
library[0]][collection_title][field][:8] == "https://"
):
edit_func(url=self.collections_config[library[0]][collection_title][field])
else:
edit_func(
filepath=self.collections_config[library[0]][collection_title][field]
)
else:
edit_func(self.collections_config[library[0]][collection_title][field])
else:
print(
"\033[31mUnable to create collection. "
f'Collection "{collection_title}" for '
f'"{library[0]}" library has no items in config.\033[0m'
)
else:
print(
"\033[31mUnable to create collection. "
f'Collection "{collection_title}" for '
f'"{library[0]}" library has no items in config.\033[0m'
)
return collections_to_update
def edit_collections(
self, plex_libraries: "dict[str, LibrarySection]", collections_to_update: "dict[str, list[Collection]]"
):
"""
Edit existing collections from config lists.
Args:
plex_libraries (dict[str, LibrarySection]): {library name: Plex library object}
collections_to_update (dict[str, list[Collection]]): Collections to update
"""
for lib in collections_to_update.items():
for collection_update in lib[1]:
if collection_update.smart:
print(
f'\033[31mUnable to create or update smart collections. '
f'Ignoring "{collection_update.title}" collection.\033[0m'
)
continue
print(f'Syncing "{collection_update.title}" in "{lib[0]}" library to config...')
if ("items" in self.collections_config[lib[0]][collection_update.title]
and self.collections_config[lib[0]][collection_update.title]["items"]
):
# Add new items to collection that are in config, but not collection
new_items = []
explained_guid = False
config_item: str
for config_item in self.collections_config[lib[0]][collection_update.title]["items"]:
if (config_item.split(" plex://")[0].split(" {")[0].encode("utf-8") not in
[lib_item.title.encode("utf-8") for lib_item in collection_update.items()]
):
print(
f'Adding "{config_item.split(" plex://")[0].split(" {")[0]}" '
f'to "{collection_update.title}" collection...'
)
try:
# Find library item using plex guid, if provided
new_items.append(
plex_libraries[lib[0]].getGuid(
self.get_item_guid(config_item, plex_libraries[lib[0]].type, full=True)
)
)
except plexapi.exceptions.NotFound:
try:
# Fall back to item name, library.get(title) doesn't always return the
# actual item with exact title (eg Horror-of-Dracula for Drácula),
# so find match in full search
search = next(
(
lib_item for lib_item in plex_libraries[lib[0]].search(
title=config_item.split(' plex://')[0].split(' {')[0]
) if lib_item.title == config_item.split(' plex://')[0].split(' {')[0]
),
None
)
if search is None:
raise plexapi.exceptions.NotFound from None
new_items.append(search)
if not explained_guid:
print(
"\033[33mGUID not available, incorrect matches may occur.\033[0m "
"If incorrect items added to collection, consider dumping library "
"and using given title from output file."
)
explained_guid = True
except plexapi.exceptions.NotFound:
print(
f'\033[33mItem "{config_item.split(" plex://")[0]}" '
f'not found in "{plex_libraries[lib[0]].title}" library\033[0m.'
)
if len(new_items) > 0:
collection_update.addItems(items=new_items)
# Remove items from collection that are not in config list
remove_items = []
lib_item: Union[Movie, Show]
for lib_item in collection_update.items():
remove_item_from_coll = True
config_guids = []
config_item: str
for config_item in self.collections_config[lib[0]][collection_update.title]["items"]:
# Get any guids provided for items in config
config_guids.append(self.get_item_guid(config_item, plex_libraries[lib[0]].type))
# If item in collection matches an item in the config, don't remove
sg: Guid
for sg in lib_item.guids:
if (config_item.find(sg.id.split("://")[-1]) != -1
or sg.id.split("://")[-1] in config_guids
):
remove_item_from_coll = False
if config_item.find(lib_item.guid) != -1:
remove_item_from_coll = False
# This is back-up, if name in config doesn't match
# the exact title used in Plex, this check will fail
remove_item_from_coll = (
remove_item_from_coll
and lib_item.title.encode("utf-8") not in [
config_item.split(" plex://")[0].split(" {")[0].encode("utf-8")
for config_item in self.collections_config[lib[0]][collection_update.title]["items"]
]
)
if remove_item_from_coll:
print(f'Removing "{lib_item.title}" from "{collection_update.title}" collection...')
remove_items.append(plex_libraries[lib[0]].getGuid(lib_item.guid))
if len(remove_items) > 0:
collection_update.removeItems(items=remove_items)
fields = [
("titleSort", collection_update.editSortTitle),
("contentRating", collection_update.editContentRating),
("summary", collection_update.editSummary),
("poster", collection_update.uploadPoster),
("mode", collection_update.modeUpdate),
("sort", collection_update.sortUpdate)
]
for field, edit_func in fields:
if (field in self.collections_config[lib[0]][collection_update.title]
and self.collections_config[lib[0]][collection_update.title][field]
):
if field == "poster":
if (self.collections_config[
lib[0]][collection_update.title][field][:7] == "http://"
or self.collections_config[
lib[0]][collection_update.title][field][:8] == "https://"
):
edit_func(url=self.collections_config[lib[0]][collection_update.title][field])
else:
edit_func(
filepath=self.collections_config[lib[0]][collection_update.title][field]
)
else:
edit_func(self.collections_config[lib[0]][collection_update.title][field])
#TODO if not in config, check locked?, confirm with user to unlock, and revert/rescan?
# Add/remove labels according to config list
if "labels" in self.collections_config[lib[0]][collection_update.title]:
if self.collections_config[lib[0]][collection_update.title]["labels"]:
new_labels = []
for config_label in self.collections_config[lib[0]][collection_update.title]["labels"]:
if config_label not in [x.tag for x in collection_update.labels]:
print(f'Adding "{config_label}" label to "{collection_update.title}" collection...')
new_labels.append(config_label)
if len(new_labels) > 0:
collection_update.addLabel(labels=new_labels)
remove_labels = []
for lib_label in [x.tag for x in collection_update.labels]:
if lib_label not in self.collections_config[lib[0]][collection_update.title]["labels"]:
print(
f'Removing "{lib_label}" label from "{collection_update.title}" collection...'
)
remove_labels.append(lib_label)
if len(remove_labels) > 0:
collection_update.removeLabel(labels=remove_labels)
else:
# Labels section in config, but no tags listed, remove all from library collection
collection_update.removeLabel(
labels=[x.tag for x in collection_update.labels],
locked=False
)
else:
print(
f'\033[31mNo items found in config. Removing collection "{collection_update.title}" '
f'from "{plex_libraries[lib[0]]}" library.\033[0m'
)
collection_update.delete()
def dump_collections(self, plex_libraries: "dict[str, LibrarySection]") -> Path:
"""
Dump existing collections to YAML files.
Args:
plex_libraries (dict[str, LibrarySection]): {library name: Plex library object}
Returns:
Path: Output directory where YAML files are saved.
"""
for library in plex_libraries.items():
library_collections: "list[Collection]" = library[1].collections()
lib_dicts: "dict[str, dict[str, dict[str, Union[str, list[str]]]]]" = {}
# # lib_dicts = {
# # 'collections': {
# # 'collection1': {
# # 'items': [
# # 'item1',
# # 'item2',
# # ],
# # 'labels': [
# # 'label1',
# # 'label2',
# # 'label3'
# # ],
# # 'poster': 'poster',
# # 'mode': 'mode',
# # 'sort': 'sort',
# # 'titleSort': 'titleSort',
# # },
# # 'collection2': {}
# # }
# # }
mode_dict = {
-1: "default",
0: "hide",
1: "hideItems",
2: "showItems"
}
sort_dict = {
0: "release",
1: "alpha",
2: "custom"
}
lib_dicts["collections"] = {}
for c in tqdm(
library_collections,
total=len(library_collections),
ascii=" ░▒█",
ncols=100,
desc=library[0],
unit="collection"
):
lib_dicts["collections"][c.title] = {}
fields = [x.name for x in c.fields]
lib_dicts["collections"][c.title]["smart"] = c.smart
if "titleSort" in fields:
lib_dicts["collections"][c.title]["titleSort"] = c.titleSort
if "label" in fields:
lib_dicts["collections"][c.title]["labels"] = [x.tag for x in c.labels]
if "contentRating" in fields:
lib_dicts["collections"][c.title]["contentRating"] = c.contentRating
if "summary" in fields:
lib_dicts["collections"][c.title]["summary"] = c.summary
# lib_dicts['collections'][c.title]['poster'] = c.posterUrl
lib_dicts["collections"][c.title]["mode"] = mode_dict[c.collectionMode]
lib_dicts["collections"][c.title]["sort"] = sort_dict[c.collectionSort]
lib_dicts["collections"][c.title]["items"] = [f"{x.title} {x.guid}" for x in c.items()]
os.makedirs("./config_dump", exist_ok=True)
config_file = Path(f'./config_dump/{library[0].replace(" ", "_")}_collections.yml')
with open(config_file.as_posix(), "w", encoding="utf-8") as f:
yaml.dump(lib_dicts, f)
return config_file.parent.resolve()
def dump_libraries(self, plex_libraries: "dict[str, LibrarySection]", all_fields: bool = False) -> Path:
"""
Dump all library items to YAML files.
Args:
plex_libraries (dict[str, LibrarySection]): {library name: Plex library object}
all_fields (bool, optional): Include all locked fields for each library item.
Returns:
Path: Output directory where YAML files are saved.
"""
for library in plex_libraries.items():
if all_fields:
lib_dict: "dict[str, dict[Union[str, list[str]]]]" = {}
# # lib_dicts = {
# # 'library': {
# # 'title1 guid1': {
# # 'titleSort': 'titleSort',
# # 'originalTitle': 'originalTitle',
# # 'contentRating': 'contentRating',
# # 'year': 'year',
# # 'studio': 'studio',
# # 'originallyAvailableAt': 'originallyAvailableAt',
# # 'summary': 'summary',
# # 'genre': [
# # 'genre1',
# # 'genre2',
# # 'genre3'
# # ],
# # 'label': [
# # 'label1',
# # 'label2'
# # ],
# # 'collection': [
# # 'collection1',
# # 'collection2',
# # ]
# # },
# # 'title2 guid2': {}
# # }
# # }
lib_dict[library[0]] = {}
item: Union[Movie, Show]
for item in tqdm(
library[1].all(),
total=library[1].totalSize,
ascii=" ░▒█",
ncols=100,
desc=library[0],
unit=library[1].type
):
title = f"{item.title} {item.guid}"
lib_dict[library[0]][title] = {}
used_fields = [
"titleSort",
"originalTitle",
"contentRating",
"year",
"studio",
"originallyAvailableAt",
"summary"
]
used_multi_fields = ["genre", "label", "collection"]
field: Field
for field in item.fields:
if field.name in used_fields:
lib_dict[library[0]][title][field.name] = getattr(item, field.name)
if field.name in used_multi_fields:
lib_dict[library[0]][title][field.name] = [x.tag for x in getattr(item, field.name+"s")]
else: # Just a list of movie/show titles and guids
lib_dict: "dict[str, list[str]]" = {}
lib_dict[library[0]] = [
f"{x.title} {x.guid}" for x in tqdm(
library[1].all(),
total=library[1].totalSize,
ascii=" ░▒█",
ncols=100,
desc=library[0],
unit=library[1].type
)
]
os.makedirs("./library_dump", exist_ok=True)
library_dump_file = Path(
f'./library_dump/{library[0].replace(" ", "_")}{"_(all_fields)" if all_fields else ""}.yml'
)
with open(library_dump_file.as_posix(), "w", encoding="utf-8") as f:
yaml.dump(lib_dict, f)
return library_dump_file.parent.resolve()
def lock_posters(self, plex_libraries: "dict[str, LibrarySection]") -> None:
"""
Lock all posters and background art.
Args:
plex_libraries (dict[str, LibrarySection]): {library name: Plex library object}
"""
for library in plex_libraries.items():
item: Union[Movie, Show]
for item in tqdm(
library[1].all(),
total=library[1].totalSize,
ascii=" ░▒█",
ncols=100,
desc=library[0],
unit=library[1].type
):
item.lockPoster()
item.lockArt()
def main(
edit_collections: bool = False,
dump_collections: bool = False,
dump_libraries: bool = False,
all_fields: bool = False,
lock_posters: bool = False,
) -> None:
"""
Function to run script logic.
"""
pcm = PlexCollectionMaker(edit_collections=edit_collections)
plex_libraries = pcm.get_libraries()
print("Found Plex libraries: ", end="")
print(*plex_libraries.keys(), sep=", ")
if edit_collections:
print("Found collection configs:")
for lib in plex_libraries.items():
print(f" {lib[0]}: ", end="")
print(*pcm.collections_config[lib[0]].keys(), sep=", ")
print()
if edit_collections:
collections_to_update = pcm.make_collections(plex_libraries=plex_libraries)
pcm.edit_collections(plex_libraries=plex_libraries, collections_to_update=collections_to_update)
print("Collections updated.")
if dump_collections:
print("Dumping existing collections to file...")
stem = pcm.dump_collections(plex_libraries=plex_libraries)
print(f'Complete. YAML files at "{stem}".')
if dump_libraries:
print("Dumping existing library items to file...")
stem = pcm.dump_libraries(plex_libraries=plex_libraries, all_fields=all_fields)
print(f'Complete. YAML files at "{stem}".')
if lock_posters:
print("Locking posters and background art...")
pcm.lock_posters(plex_libraries=plex_libraries)
print("Art locked.")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-e", "--exclude-edit", action="store_false", help="don't create or edit collections")
parser.add_argument("-c", "--dump-collections", action="store_true", help="dump collections to file")
parser.add_argument("-l", "--dump-libraries", action="store_true", help="dump libraries to file")
parser.add_argument("-a", "--all-fields", action="store_true", help="include all fields when dumping libraries")
parser.add_argument("-p", "--lock-posters", action="store_true", help="lock all poster and background art fields")
args = parser.parse_args()
main(
edit_collections=args.exclude_edit,
dump_collections=args.dump_collections,
dump_libraries=args.dump_libraries,
all_fields=args.all_fields,
lock_posters=args.lock_posters,
)