Skip to content

ProjectItem

An item in the project panel: the root, a bin, or a clip.

Structural items are parser-built, not user-constructed.

Source code in src/py_premiere/models/project_item.py
 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
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
class ProjectItem:
    """An item in the project panel: the root, a bin, or a clip.

    Structural items are parser-built, not user-constructed.
    """

    def __init__(
        self,
        _element: ET.Element,
        project: Project,
        item_type: ProjectItemType,
    ) -> None:
        self._element = _element
        self.project = project
        self._type = item_type
        self._children: list[ProjectItem] = []
        self._markers: list[Marker] = []
        self._media_path: Path | None = None
        self._master_element: ET.Element | None = None
        self._parent: ProjectItem | None = None
        self._clip_elements: list[ET.Element] = []
        self._node_id_int: int | None = None
        self._default_out_ticks: int | None = None
        self._sequence_uid: str | None = None

    def _name_element(self) -> ET.Element | None:
        # A clip item's live name is its master clip's; the ProjectItem/Name
        # copy goes stale when Premiere renames (validated against
        # ExtendScript ground truth).
        if self._master_element is not None:
            element = self._master_element.find("Name")
            if element is not None:
                return element
        core = project_item_core(self._element)
        return None if core is None else core.find("Name")

    @property
    def name(self) -> str:
        """The item name. Read/write.

        Like ExtendScript, the root item reports the project file name and
        a clip item reports its master clip's name.
        """
        if self._type is ProjectItemType.ROOT:
            return self.project.name
        element = self._name_element()
        return (element.text or "") if element is not None else ""

    @name.setter
    def name(self, value: str) -> None:
        _validate_name(value)
        if self._type is ProjectItemType.ROOT:
            raise AttributeError("the root item's name mirrors the project file name")
        element = self._name_element()
        if element is None:
            raise ValueError("item has no name element")
        element.text = value

    @property
    def type(self) -> ProjectItemType:
        """The item type. Read-only."""
        return self._type

    @property
    def is_sequence(self) -> bool:
        """Whether this clip item is backed by a sequence. Read-only."""
        return self._sequence_uid is not None

    def add_bin(self, name: str) -> ProjectItem:
        """Create a child bin and return it.

        Works on the root and on any bin (nesting into an empty bin
        synthesizes its child-item list). The view-state properties Premiere
        writes for a new bin are elided (Premiere synthesizes them on open).
        """
        _validate_name(name)
        if self._type is ProjectItemType.CLIP:
            raise ValueError("cannot add a bin under a clip item")
        container = self._element.find("ProjectItemContainer")
        if container is None:
            raise ValueError("item has no ProjectItemContainer")
        items = _child_items(container)
        document = self.project._document
        uid = str(uuid.uuid4())
        bin_element = _new_bin_element(uid, name)
        document.attach_object(bin_element)
        _add_item_ref(items, uid)
        child = ProjectItem(bin_element, self.project, ProjectItemType.BIN)
        child._parent = self
        self._children.append(child)
        return child

    def remove_bin(self, child: ProjectItem) -> None:
        """Remove a child bin, deleting its contents recursively.

        Child bins are removed depth-first; child clip items go through
        `remove_item` (so a bin holding an in-use clip refuses removal
        before anything is touched).
        """
        if child not in self._children:
            raise ValueError("item is not a child of this bin")
        if child._type is not ProjectItemType.BIN:
            raise ValueError("only bins can be removed")
        for grandchild in list(child._children):
            if grandchild._type is ProjectItemType.BIN:
                child.remove_bin(grandchild)
            else:
                child.remove_item(grandchild)
        document = self.project._document
        uid = child._element.get("ObjectUID")
        container = self._element.find("ProjectItemContainer")
        if container is not None and uid is not None:
            _detach_item_ref(container, uid)
        document.remove_object(child._element)
        self._children.remove(child)

    def remove_item(self, child: ProjectItem) -> None:
        """Remove a child clip item, deleting its media objects.

        Deletes the exact graph Premiere deletes with a panel item (master
        clip, template clips, logging, markers, source, media, streams),
        keeping anything still referenced from outside it (e.g. media
        shared with another item). Refuses when the item is placed on a
        timeline (remove the clips first) or backed by a sequence.
        """
        if child not in self._children:
            raise ValueError("item is not a child of this bin")
        if child._type is not ProjectItemType.CLIP:
            raise ValueError("only clip items can be removed; use remove_bin")
        if child.is_sequence:
            raise ValueError("removing a sequence item is not supported")
        master = child._master_element
        if master is None:
            raise ValueError("item has no master clip")
        document = self.project._document
        # One pass answers both questions: who still points at the master
        # clip (a timeline placement, which blocks the removal), and what the
        # item exclusively owns (the graph that goes with it).
        index = ReferenceIndex(document)
        if index.referrers_outside(master, [child._element, master]):
            raise ValueError("item is in use on a timeline; remove its clips first")
        uid = child._element.get("ObjectUID")
        container = self._element.find("ProjectItemContainer")
        if container is not None and uid is not None:
            _detach_item_ref(container, uid)
        for element in document.owned_objects([child._element, master], index):
            document.remove_object(element)
        self._children.remove(child)
        # The lookup maps hold this item keyed by its master/sequence UID.
        self.project._items_by_master_uid = None
        self.project._items_by_sequence_uid = None

    def move_to(self, new_parent: ProjectItem) -> None:
        """Move this item into another bin (or the root).

        Only the parent-child wiring changes; the item's own object is
        untouched.
        """
        if self._type is ProjectItemType.ROOT:
            raise ValueError("cannot move the root item")
        if new_parent.project is not self.project:
            # Wiring a reference across documents leaves the destination with
            # a dangling ObjectURef and the source with an orphan object.
            raise ValueError("cannot move an item into another project")
        if new_parent._type is ProjectItemType.CLIP:
            raise ValueError("cannot move an item under a clip")
        if self._parent is None:
            raise ValueError("item has no parent to move from")
        if new_parent is self._parent:
            return
        ancestor: ProjectItem | None = new_parent
        while ancestor is not None:
            if ancestor is self:
                raise ValueError("cannot move an item into itself or a descendant")
            ancestor = ancestor._parent
        container = new_parent._element.find("ProjectItemContainer")
        if container is None:
            raise ValueError("destination has no ProjectItemContainer")
        destination = _child_items(container)
        uid = self._element.get("ObjectUID")
        if uid is None:
            raise ValueError("item has no ObjectUID")
        source = self._parent._element.find("ProjectItemContainer")
        if source is not None:
            _detach_item_ref(source, uid)
        _add_item_ref(destination, uid)
        self._parent._children.remove(self)
        new_parent._children.append(self)
        self._parent = new_parent

    @property
    def color_label(self) -> int:
        """The item's color label as an index (`0` when none is stored). Read/write.

        Stored in the item's property bag as `Column.PropertyText.Label` =
        `BE.Prefs.LabelColors.<index>`; the index matches ExtendScript's
        `getColorLabel` / UXP `getColorLabelIndex`. Items without the
        property (e.g. the root) report `0`, as ExtendScript does. Setting an
        index in `1..15` writes (or updates) the property; setting `0` clears
        the stored override, so the item reads back as `0`.
        """
        core = project_item_core(self._element)
        text = (
            None
            if core is None
            else core.findtext("Node/Properties/Column.PropertyText.Label")
        )
        prefix = "BE.Prefs.LabelColors."
        if text is None or not text.startswith(prefix):
            return 0
        suffix = text[len(prefix) :]
        return int(suffix) if suffix.isdigit() else 0

    @color_label.setter
    def color_label(self, index: int) -> None:
        validate_color_label(index)
        properties = self._element.find("ProjectItem/Node/Properties")
        if properties is None:
            raise ValueError("item has no property bag to store a color label")
        existing = properties.find("Column.PropertyText.Label")
        if index == 0:
            if existing is not None:
                remove_child(properties, existing)
            return
        text = "BE.Prefs.LabelColors." + str(index)
        if existing is not None:
            existing.text = text
        else:
            append_leaf(properties, "Column.PropertyText.Label", text)

    @property
    def node_id(self) -> str | None:
        """The item's identifier: the node ID in 8-digit hex. Read-only.

        Best-effort: Premiere assigns these per session at load, so they
        are reproducible only for freshly saved projects.
        """
        if self._node_id_int is None:
            return None
        return format(self._node_id_int, "08x")

    @property
    def tree_path(self) -> str:
        r"""The item's path in the project panel (`\project\bin\item`). Read-only."""
        if self._parent is None:
            return "\\" + self.project.name
        return self._parent.tree_path + "\\" + self.name

    @property
    def in_point(self) -> Time | None:
        """The item's in point in media time. Read-only.

        `None` for items without media (the root, bins), where ExtendScript
        reports the -400000 s unset sentinel.
        """
        ticks = self._point_ticks("InPoint")
        return None if ticks == UNSET_TICKS else Time(ticks)

    @property
    def out_point(self) -> Time | None:
        """The item's out point in media time. Read-only.

        `None` for items without media, like `in_point`.
        """
        ticks = self._point_ticks("OutPoint")
        return None if ticks == UNSET_TICKS else Time(ticks)

    def _point_ticks(self, tag: str) -> int:
        if not self._clip_elements:
            return UNSET_TICKS
        core = clip_core(self._clip_elements[0])
        stored = None if core is None else core.findtext(tag)
        if stored:
            return int(stored)
        if tag == "OutPoint":
            if self._sequence_uid is not None:
                # A sequence-backed item reports the LIVE sequence end, not
                # the stored (stale) source duration.
                for sequence in self.project.sequences:
                    if sequence.sequence_id == self._sequence_uid:
                        return sequence.end.ticks
            if self._default_out_ticks is not None:
                # Unset out point: ExtendScript reports the source duration.
                return self._default_out_ticks
        return 0

    @property
    def children(self) -> NamedList[ProjectItem]:
        """Child items of a bin, indexable by name. Read-only."""
        return NamedList(self._children)

    def __iter__(self) -> Iterator[ProjectItem]:
        return iter(self._children)

    def __len__(self) -> int:
        return len(self._children)

    def __getitem__(self, key: int | str) -> ProjectItem:
        return self.children[key]

    def __contains__(self, item: object) -> bool:
        return item in self.children

    def walk(self) -> Iterator[ProjectItem]:
        """Every descendant item, depth-first."""
        for child in self._children:
            yield child
            yield from child.walk()

    @property
    def footage_interpretation(self) -> FootageInterpretation | None:
        """The item's footage interpretation. Read-only.

        `None` for items without a video stream (bins, audio-only media).
        """
        media = self._media_element()
        if media is None:
            return None
        stream_ref = media.find("VideoStream")
        if stream_ref is None:
            return None
        document = self.project._document
        core = self._own_clip_core()
        source_ref = None if core is None else core.find("Source")
        source = None if source_ref is None else document.resolve(source_ref)
        return FootageInterpretation(document.resolve(stream_ref), source)

    @property
    def scale_to_frame_size(self) -> bool:
        """Whether placements scale the media to the sequence frame size.
        Read/write.

        Stored as `ScaleToFramePolicy` (1) on the master's template video
        clip and elided when off (70_scale_to_frame); mirrors
        ExtendScript's `setScaleToFrameSize`.
        """
        for clip in self._clip_elements:
            if clip.tag == "VideoClip":
                return clip.findtext("ScaleToFramePolicy") == "1"
        return False

    @scale_to_frame_size.setter
    def scale_to_frame_size(self, value: bool) -> None:
        validate_bool(value)
        for clip in self._clip_elements:
            if clip.tag == "VideoClip":
                set_elided_flag(clip, "ScaleToFramePolicy", value, text="1")
                return
        raise ValueError("item has no video clip to scale")

    def _media_element(self) -> ET.Element | None:
        # The `Media` object backing this clip item (master clip -> template
        # clip -> Source -> MediaSource/Media).
        core = self._own_clip_core()
        if core is None:
            return None
        source_ref = core.find("Source")
        if source_ref is None:
            return None
        document = self.project._document
        media_ref = document.resolve(source_ref).find("MediaSource/Media")
        if media_ref is None:
            return None
        return document.resolve(media_ref)

    @property
    def is_offline(self) -> bool:
        """Whether the item's media is offline. Read-only.

        Stored as `Media/OfflineReason`; elided when the media is online.
        """
        media = self._media_element()
        return media is not None and media.find("OfflineReason") is not None

    @property
    def generator_id(self) -> str | None:
        """The four-character code of the item's synthetic media, or `None`.

        Generated media (Black Video, a colour matte, bars and tone, ...) has
        no file: Premiere stores a big-endian fourcc where the path would go,
        which is why `media_path` is `None` for these items. `None` here means
        the item is backed by a real file (or by nothing at all).
        """
        media = self._media_element()
        if media is None:
            return None
        stored = media.findtext("FilePath") or ""
        if not stored.isdigit():
            return None
        return struct.pack(">I", int(stored)).decode("ascii", "replace")

    @property
    def generator_type(self) -> GeneratorType | None:
        """Which of Premiere's generators backs the item, or `None`.

        `None` both for real media and for a generator py has no code for -
        `generator_id` still reports the raw fourcc in that case. Note an
        adjustment layer is backed by Black Video, so it reports
        `BLACK_VIDEO` here and identifies itself through
        `is_adjustment_layer`.
        """
        media = self._media_element()
        if media is None:
            return None
        stored = media.findtext("FilePath") or ""
        if not stored.isdigit():
            return None
        try:
            return GeneratorType(int(stored))
        except ValueError:
            return None

    @property
    def is_adjustment_layer(self) -> bool:
        """Whether the item is an adjustment layer. Read-only.

        Stored as `MasterClip/IsAdjustmentLayer`. The media underneath is
        Premiere's synthetic Black Video generator, so the flag - not the
        media - is what identifies it.
        """
        if self._master_element is None:
            return False
        return self._master_element.findtext("IsAdjustmentLayer") == "true"

    @property
    def is_multicam_clip(self) -> bool:
        """Whether the item is a multi-camera source sequence. Read-only."""
        if self._master_element is None:
            return False
        enabled = self._master_element.findtext(
            "Node/Properties/Source.Monitor.Multicam.Enabled"
        )
        return enabled == "true"

    @property
    def is_mgt(self) -> bool:
        """Whether the item came from a Motion Graphics template. Read-only.

        An imported template's master hangs its Essential Graphics
        controls off a `BlueprintVideoComponentChain` - a slot no other
        kind of master clip uses - so the presence of that chain is what
        identifies one.
        """
        if self._master_element is None:
            return False
        return self._master_element.find("BlueprintVideoComponentChain") is not None

    @property
    def is_merged_clip(self) -> bool:
        """Whether the item is a merged clip. Read-only.

        Merged clips and multicam clips are both backed by a hidden
        `Sequence` combining the source files; the merged one flags itself in
        that sequence's property bag as `BE.Sequence.IsMergedClip`.
        """
        sequence = self._backing_sequence()
        if sequence is None:
            return False
        flag = sequence.findtext("Node/Properties/BE.Sequence.IsMergedClip")
        return flag == "true"

    def _backing_sequence(self) -> ET.Element | None:
        # The `Sequence` object an item's clips play from, for the item kinds
        # Premiere implements as a hidden sequence (merged and multicam
        # clips) as well as ordinary sequence items.
        core = self._own_clip_core()
        if core is None:
            return None
        source_ref = core.find("Source")
        if source_ref is None:
            return None
        document = self.project._document
        sequence_ref = document.resolve(source_ref).find("SequenceSource/Sequence")
        if sequence_ref is None:
            return None
        return document.resolve(sequence_ref)

    @property
    def start_time(self) -> Time:
        """The item's start time. Read/write.

        The start timecode embedded in the media, stored as
        `Media/AlternateStart` and honoured only while `UseAlternateStart`
        is set. Media with no timecode track - and items with no media -
        start at zero.

        The setter mirrors ExtendScript's `setStartTime` and is supported
        on media that already stores a start timecode: replaying Premiere's
        own edit touches `AlternateStart` alone (62_start_time vs
        19_timecode), so no reference exists yet for synthesizing the pair
        on timecode-less media.

        Persistence caveat, measured on the resave gate: for media with an
        EMBEDDED timecode, Premiere re-reads the media on open and restores
        `AlternateStart` to the embedded value, reverting this edit on its
        next resave - ExtendScript's own `setStartTime` suffers the same
        fate. The GUI's `Modify > Timecode` evidently writes something
        stickier; that representation is undecoded (see CAMPAIGN.md).
        """
        media = self._media_element()
        if media is None or media.findtext("UseAlternateStart") != "true":
            return Time(0)
        return Time(int(media.findtext("AlternateStart") or 0))

    @start_time.setter
    def start_time(self, value: Time) -> None:
        validate_time(value)
        if value.ticks < 0:
            raise ValueError("start time cannot be negative")
        media = self._media_element()
        alternate = None if media is None else media.find("AlternateStart")
        flag = None if media is None else media.find("UseAlternateStart")
        if alternate is None or flag is None:
            raise ValueError(
                "start time is only settable on media that stores a start "
                "timecode (Media/AlternateStart)"
            )
        alternate.text = str(value.ticks)
        flag.text = "true"

    @property
    def has_proxy(self) -> bool:
        """Whether the item has proxy media attached. Read-only."""
        return self._proxy_media() is not None

    @property
    def proxy_path(self) -> Path | None:
        """The path of the item's proxy media, if any. Read-only.

        `None` when no proxy is attached (ExtendScript's `getProxyPath`
        reports `0` in that case).
        """
        media = self._proxy_media()
        stored = None if media is None else media.findtext("FilePath")
        return Path(stored) if stored else None

    def attach_proxy(self, path: str | Path, is_hi_res: bool = False) -> None:
        """Attach proxy media to this item.

        ExtendScript's `attachProxy`. A proxy is a second `Media` object
        (flagged `IsProxy`) with its own stream, referenced from the media
        source's `Content` bag; the proxy's stream carries the HI-RES
        frame rect as an override so the item keeps reporting the original
        raster (18_proxy). The file must be readable and match the item's
        frame aspect ratio, as Premiere itself requires.

        `is_hi_res` swaps the roles, as the ExtendScript flag does: `path`
        becomes the media this item PLAYS and what it played until now is
        demoted to the proxy. The end state is the same graph either way -
        one `Media` flagged `IsProxy`, one not - and the MASTER CLIP takes
        the new file's name while the panel item's own `Name` is left
        behind, stale, which is what Premiere does too (verified against
        its calls in both directions, `samples/refs/gaps/proxy_*.prproj`).
        """
        _validate_proxy_path(path)
        validate_bool(is_hi_res)
        if self.has_proxy:
            raise ValueError("item already has proxy media attached")
        content = self._media_content()
        media = self._media_element()
        stream_ref = None if media is None else media.find("VideoStream")
        if content is None or media is None or stream_ref is None:
            raise ValueError("proxies attach to video media clip items")
        document = self.project._document
        own_rect = document.resolve(stream_ref).findtext("FrameRect")
        if not own_rect:
            raise ValueError("source video stream has no frame rect")
        if not is_hi_res:
            proxy_uid = self.project._make_proxy_media(Path(path), own_rect)
            append_child(content, ET.Element("ProxyMedia", {"ObjectURef": proxy_uid}))
            return
        self._attach_hi_res(document, content, media, own_rect, Path(path))

    def _attach_hi_res(
        self,
        document: PremiereDocument,
        content: ET.Element,
        media: ET.Element,
        own_rect: str,
        path: Path,
    ) -> None:
        # The newcomer becomes the media and the incumbent the proxy, so
        # the frame-rect override lands on what was already here - carrying
        # the NEW file's raster, since that is now the hi-res one.
        source = self._media_source()
        reference = None if source is None else source.find("MediaSource/Media")
        if reference is None:
            raise ValueError("media source has no Media reference")
        media_uid, hires_rect = self.project._make_primary_media(path, own_rect)
        reference.set("ObjectURef", media_uid)

        stream_ref = media.find("VideoStream")
        if stream_ref is None:
            raise ValueError("media has no video stream to override")
        _override_frame_rect(document.resolve(stream_ref), hires_rect)
        append_leaf(media, "IsProxy", "true")
        demoted = media.get("ObjectUID") or ""
        append_child(content, ET.Element("ProxyMedia", {"ObjectURef": demoted}))
        # The master follows the new media; Premiere leaves the panel
        # item's own copy of the name on the old file.
        master = self._master_element
        name = master.find("Name") if master is not None else None
        if name is not None:
            name.text = path.name
        # The item plays the newcomer now; without this the live object
        # keeps reporting the file it just demoted to proxy, and
        # `create_sub_clip` would re-import the proxy.
        self._media_path = path.resolve()

    def _proxy_media(self) -> ET.Element | None:
        # Proxy media is a SECOND `Media` object (flagged `IsProxy`), hung
        # off the media source's own Content bag rather than the master clip.
        content = self._media_content()
        if content is None:
            return None
        proxy_ref = content.find("ProxyMedia")
        if proxy_ref is None:
            return None
        return self.project._document.resolve(proxy_ref)

    def _media_source(self) -> ET.Element | None:
        # The `*MediaSource` object this item's template clip plays from.
        core = self._own_clip_core()
        source_ref = None if core is None else core.find("Source")
        if source_ref is None:
            return None
        return self.project._document.resolve(source_ref)

    def _media_content(self) -> ET.Element | None:
        # The media source's own `Content` bag, which carries the state that
        # belongs to this item's *view* of the media rather than to the media
        # itself (its proxy, and a subclip's boundaries).
        core = self._own_clip_core()
        if core is None:
            return None
        source_ref = core.find("Source")
        if source_ref is None:
            return None
        source = self.project._document.resolve(source_ref)
        return source.find("MediaSource/Content")

    @property
    def is_subclip(self) -> bool:
        """Whether the item is a subclip of another item. Read-only.

        A subclip is a second master clip over the same media, narrowed by
        boundaries on its own media source. Its `in_point` and `out_point`
        still describe the whole file - `subclip_in_point` and
        `subclip_out_point` are the narrowed range.
        """
        return self._boundary("StartBoundary") is not None

    @property
    def subclip_in_point(self) -> Time | None:
        """Where the subclip starts in media time, or `None`. Read-only."""
        return self._boundary("StartBoundary")

    @property
    def subclip_out_point(self) -> Time | None:
        """Where the subclip ends in media time, or `None`. Read-only."""
        return self._boundary("EndBoundary")

    @property
    def has_hard_boundaries(self) -> bool:
        """Whether the subclip's boundaries are hard. Read-only.

        ExtendScript's `createSubClip` calls this `hardBoundaries`: soft
        boundaries can be trimmed past on the timeline, hard ones cannot.
        `False` for items that are not subclips.
        """
        content = self._media_content()
        if content is None:
            return False
        return content.findtext("BoundariesAreHard") == "true"

    def _boundary(self, tag: str) -> Time | None:
        content = self._media_content()
        if content is None:
            return None
        stored = content.findtext(tag)
        return None if stored is None else Time(int(stored))

    def create_sub_clip(
        self,
        name: str,
        start: Time,
        end: Time,
        has_hard_boundaries: bool = False,
        take_video: bool = True,
        take_audio: bool = True,
    ) -> ProjectItem:
        """Create a subclip of this item in the project panel and return it.

        Mirrors ExtendScript's `createSubClip`. A subclip is a SECOND master
        clip over the same media file - Premiere duplicates the whole media
        graph rather than sharing objects (28_subclip) - narrowed by
        `StartBoundary`/`EndBoundary` on its media source. Soft boundaries
        can be trimmed past on the timeline, hard ones cannot.

        `take_video`/`take_audio` subclip only part of an A/V source, as
        ExtendScript's trailing flags do. NOTE the scripting guide lists
        them the other way round (`takeAudio, takeVideo`); driving the
        real call proved the fifth argument governs VIDEO and the sixth
        AUDIO, so py names them in their actual order. Dropping a half
        leaves the media's stream in place and omits that half's clip and
        source from the new master, which is what Premiere writes.

        The subclip's graph is synthesized the way an import is, so the
        media file must still be readable; it then takes over the source's
        file identity (one `FileKey`/content state per file, the
        modification blob carried once), and the source's footage
        interpretation overrides do NOT carry over.
        """
        _validate_name(name)
        validate_time(start)
        validate_time(end)
        validate_bool(has_hard_boundaries)
        validate_bool(take_video)
        validate_bool(take_audio)
        if not (take_video or take_audio):
            raise ValueError("a subclip must take the video, the audio, or both")
        if self._type is not ProjectItemType.CLIP or self.is_sequence:
            raise ValueError("subclips can only be created from media clip items")
        if self.media_path is None:
            raise ValueError("item has no media file to subclip")
        if not 0 <= start.ticks < end.ticks:
            raise ValueError("subclip boundaries must satisfy 0 <= start < end")
        if self._master_element is None:
            raise ValueError("item has no master clip")
        document = self.project._document
        item = self.project.import_files([self.media_path])[0]
        # The master carries the live subclip name; the ProjectItem copy
        # keeps the file name, exactly as Premiere writes it.
        master = item._master_element
        if master is None:
            raise ValueError("synthesized subclip has no master clip")
        name_element = master.find("Name")
        if name_element is not None:
            name_element.text = name
        logging_ref = master.find("LoggingInfo")
        if logging_ref is None:
            raise ValueError("synthesized subclip has no logging info")
        logging = document.resolve(logging_ref)
        for tag, text in (
            ("ClipName", name),
            ("MediaInPoint", str(start.ticks)),
            ("MediaOutPoint", str(end.ticks)),
        ):
            leaf = logging.find(tag)
            if leaf is not None:
                leaf.text = text
        if not (take_video and take_audio):
            item._drop_subclip_half(take_video)
        # A/V media narrows BOTH its sources: the identical boundary trio
        # lands in the video AND the audio source's Content bag
        # (71_av_subclip) - or in the surviving one alone when a half was
        # dropped.
        contents = []
        for clip_element in item._clip_elements:
            core = clip_core(clip_element)
            source_ref = None if core is None else core.find("Source")
            if source_ref is None:
                continue
            content = document.resolve(source_ref).find("MediaSource/Content")
            if content is not None:
                contents.append(content)
        if not contents:
            raise ValueError("synthesized subclip has no media content bag")
        for content in contents:
            append_leaf(content, "StartBoundary", str(start.ticks))
            append_leaf(content, "EndBoundary", str(end.ticks))
            append_leaf(
                content,
                "BoundariesAreHard",
                "true" if has_hard_boundaries else "false",
            )
        # The panel label stamp (`Column.PropertyText.Label`) is kept as the
        # import wrote it: Premiere itself is inconsistent - 28_subclip's
        # subclip carries none, 71_av_subclip's does - and a resave
        # re-stamps it either way.
        self._share_file_identity(item)
        return item

    def _drop_subclip_half(self, keep_video: bool) -> None:
        # Keep only the video or only the audio half of a freshly imported
        # A/V master, as Premiere's take flags do: the clip and everything
        # only it referenced go, the shared Media (and both its streams)
        # stay. An audio-only master keeps its component chains and channel
        # groups; a video-only one has neither to keep.
        document = self.project._document
        master = self._master_element
        if master is None:
            raise ValueError("item has no master clip")
        wanted = "VideoClip" if keep_video else "AudioClip"
        clips = master.find("Clips")
        if clips is None:
            raise ValueError("master clip has no Clips list")
        doomed = []
        for reference in list(clips.findall("Clip")):
            clip = document.resolve(reference)
            if clip.tag == wanted:
                continue
            doomed.append(clip)
            remove_child(clips, reference)
        if not doomed:
            return
        for index, reference in enumerate(clips.findall("Clip")):
            reference.set("Index", str(index))
        orphaned: list[ET.Element] = []
        if keep_video:
            # The audio plumbing belongs to the half being dropped - but NOT
            # `DefMappingID`, which Premiere keeps on a video-only subclip
            # (samples/refs/audit/sub_audio.prproj).
            chains = master.find("AudioComponentChains")
            if chains is not None:
                orphaned = [document.resolve(entry) for entry in chains]
                remove_child(master, chains)
        index_of = ReferenceIndex(document)
        # Unhooking that list leaves its chains referenced by nothing, and
        # `owned_objects` only reaches what the doomed CLIPS point at - so
        # they have to be seeded, or they survive as top-level orphans.
        doomed.extend(
            chain for chain in orphaned if not index_of.referrers.get(id(chain))
        )
        for element in document.owned_objects(doomed, index_of):
            document.remove_object(element)
        self._clip_elements = [
            document.resolve(reference) for reference in clips.findall("Clip")
        ]

    def _share_file_identity(self, other: ProjectItem) -> None:
        # Premiere keeps ONE file identity per media file: every Media
        # object describing it shares FileKey/content state, and only the
        # first carries the modification blob - the rest hash-reference it
        # (the multi-channel import rule, seen again on 28_subclip).
        source_media = self._media_element()
        target_media = other._media_element()
        if source_media is None or target_media is None:
            return
        for tag in ("FileKey", "ContentAndMetadataState"):
            stored = source_media.findtext(tag)
            leaf = target_media.find(tag)
            if stored and leaf is not None:
                leaf.text = stored
        source_state = source_media.find("ModificationState")
        target_state = target_media.find("ModificationState")
        if source_state is not None and target_state is not None:
            binary_hash = source_state.get("BinaryHash")
            if binary_hash:
                target_state.set("BinaryHash", binary_hash)
            target_state.text = None
        content_state = source_media.findtext("ContentAndMetadataState")
        core = other._own_clip_core()
        markers_ref = None if core is None else core.find("MarkerOwner/Markers")
        if content_state and markers_ref is not None:
            markers = self.project._document.resolve(markers_ref)
            last = markers.find("LastContentState")
            if last is not None:
                last.text = content_state

    @property
    def markers(self) -> NamedList[Marker]:
        """The item's clip markers, indexable by name. Read-only.

        Stored on the master clip's own template clip, shared with every
        timeline instance of the item. A sequence-backed item's own markers
        are separate from the sequence's markers (matching UXP). Bins and
        the root have none.
        """
        return NamedList(self._markers)

    def _own_clip_core(self) -> ET.Element | None:
        # The master clip's own template clip core (`Clips[0]` -> `Clip`),
        # where item markers live.
        if self._master_element is None:
            return None
        reference = self._master_element.find("Clips/Clip")
        if reference is None:
            return None
        return clip_core(self.project._document.resolve(reference))

    def add_marker(
        self,
        name: str,
        start: Time,
        comments: str = "",
        marker_type: str = "Comment",
        duration: Time | None = None,
    ) -> Marker:
        """Create a clip marker on this item and return it.

        `start` is in media time (a still's first frame sits at its 1-hour
        default timecode, not 0).
        """
        if self._type is not ProjectItemType.CLIP:
            raise ValueError("only clip items carry markers")
        core = self._own_clip_core()
        if core is None:
            raise ValueError("item has no master clip")
        document = self.project._document
        inner = _ensure_clip_marker_list(document, core)
        marker = Marker(name, start, comments, marker_type, duration)
        _attach_marker(document, inner, marker)
        self._markers.append(marker)
        return marker

    def remove_marker(self, marker: Marker) -> None:
        """Remove a clip marker from this item."""
        if marker not in self._markers:
            raise ValueError("marker does not belong to this item")
        core = self._own_clip_core()
        reference = core.find("MarkerOwner/Markers") if core is not None else None
        if reference is None:
            raise ValueError("master clip has no marker collection")
        document = self.project._document
        inner = document.resolve(reference).find("Markers")
        if inner is None:
            raise ValueError("marker collection has no inner list")
        _detach_marker(document, inner, marker)
        self._markers.remove(marker)

    @property
    def media_path(self) -> Path | None:
        """The path of the underlying media file, if any. Read-only.

        Premiere's internal generators (e.g. `Black Video`) store a numeric
        token instead of a filesystem path; they report `None` here (see
        `generator_type`).
        """
        return self._media_path

    def __repr__(self) -> str:
        return f"ProjectItem(name={self.name!r}, type={self._type.name})"

Attributes

children property

children

Child items of a bin, indexable by name. Read-only.

color_label property writable

color_label

The item's color label as an index (0 when none is stored). Read/write.

Stored in the item's property bag as Column.PropertyText.Label = BE.Prefs.LabelColors.<index>; the index matches ExtendScript's getColorLabel / UXP getColorLabelIndex. Items without the property (e.g. the root) report 0, as ExtendScript does. Setting an index in 1..15 writes (or updates) the property; setting 0 clears the stored override, so the item reads back as 0.

footage_interpretation property

footage_interpretation

The item's footage interpretation. Read-only.

None for items without a video stream (bins, audio-only media).

generator_id property

generator_id

The four-character code of the item's synthetic media, or None.

Generated media (Black Video, a colour matte, bars and tone, ...) has no file: Premiere stores a big-endian fourcc where the path would go, which is why media_path is None for these items. None here means the item is backed by a real file (or by nothing at all).

generator_type property

generator_type

Which of Premiere's generators backs the item, or None.

None both for real media and for a generator py has no code for - generator_id still reports the raw fourcc in that case. Note an adjustment layer is backed by Black Video, so it reports BLACK_VIDEO here and identifies itself through is_adjustment_layer.

has_hard_boundaries property

has_hard_boundaries

Whether the subclip's boundaries are hard. Read-only.

ExtendScript's createSubClip calls this hardBoundaries: soft boundaries can be trimmed past on the timeline, hard ones cannot. False for items that are not subclips.

has_proxy property

has_proxy

Whether the item has proxy media attached. Read-only.

in_point property

in_point

The item's in point in media time. Read-only.

None for items without media (the root, bins), where ExtendScript reports the -400000 s unset sentinel.

is_adjustment_layer property

is_adjustment_layer

Whether the item is an adjustment layer. Read-only.

Stored as MasterClip/IsAdjustmentLayer. The media underneath is Premiere's synthetic Black Video generator, so the flag - not the media - is what identifies it.

is_merged_clip property

is_merged_clip

Whether the item is a merged clip. Read-only.

Merged clips and multicam clips are both backed by a hidden Sequence combining the source files; the merged one flags itself in that sequence's property bag as BE.Sequence.IsMergedClip.

is_mgt property

is_mgt

Whether the item came from a Motion Graphics template. Read-only.

An imported template's master hangs its Essential Graphics controls off a BlueprintVideoComponentChain - a slot no other kind of master clip uses - so the presence of that chain is what identifies one.

is_multicam_clip property

is_multicam_clip

Whether the item is a multi-camera source sequence. Read-only.

is_offline property

is_offline

Whether the item's media is offline. Read-only.

Stored as Media/OfflineReason; elided when the media is online.

is_sequence property

is_sequence

Whether this clip item is backed by a sequence. Read-only.

is_subclip property

is_subclip

Whether the item is a subclip of another item. Read-only.

A subclip is a second master clip over the same media, narrowed by boundaries on its own media source. Its in_point and out_point still describe the whole file - subclip_in_point and subclip_out_point are the narrowed range.

markers property

markers

The item's clip markers, indexable by name. Read-only.

Stored on the master clip's own template clip, shared with every timeline instance of the item. A sequence-backed item's own markers are separate from the sequence's markers (matching UXP). Bins and the root have none.

media_path property

media_path

The path of the underlying media file, if any. Read-only.

Premiere's internal generators (e.g. Black Video) store a numeric token instead of a filesystem path; they report None here (see generator_type).

name property writable

name

The item name. Read/write.

Like ExtendScript, the root item reports the project file name and a clip item reports its master clip's name.

node_id property

node_id

The item's identifier: the node ID in 8-digit hex. Read-only.

Best-effort: Premiere assigns these per session at load, so they are reproducible only for freshly saved projects.

out_point property

out_point

The item's out point in media time. Read-only.

None for items without media, like in_point.

project instance-attribute

project = project

proxy_path property

proxy_path

The path of the item's proxy media, if any. Read-only.

None when no proxy is attached (ExtendScript's getProxyPath reports 0 in that case).

scale_to_frame_size property writable

scale_to_frame_size

Whether placements scale the media to the sequence frame size. Read/write.

Stored as ScaleToFramePolicy (1) on the master's template video clip and elided when off (70_scale_to_frame); mirrors ExtendScript's setScaleToFrameSize.

start_time property writable

start_time

The item's start time. Read/write.

The start timecode embedded in the media, stored as Media/AlternateStart and honoured only while UseAlternateStart is set. Media with no timecode track - and items with no media - start at zero.

The setter mirrors ExtendScript's setStartTime and is supported on media that already stores a start timecode: replaying Premiere's own edit touches AlternateStart alone (62_start_time vs 19_timecode), so no reference exists yet for synthesizing the pair on timecode-less media.

Persistence caveat, measured on the resave gate: for media with an EMBEDDED timecode, Premiere re-reads the media on open and restores AlternateStart to the embedded value, reverting this edit on its next resave - ExtendScript's own setStartTime suffers the same fate. The GUI's Modify > Timecode evidently writes something stickier; that representation is undecoded (see CAMPAIGN.md).

subclip_in_point property

subclip_in_point

Where the subclip starts in media time, or None. Read-only.

subclip_out_point property

subclip_out_point

Where the subclip ends in media time, or None. Read-only.

tree_path property

tree_path

The item's path in the project panel (\project\bin\item). Read-only.

type property

type

The item type. Read-only.

Methods:

__contains__

__contains__(item)
Source code in src/py_premiere/models/project_item.py
def __contains__(self, item: object) -> bool:
    return item in self.children

__getitem__

__getitem__(key)
Source code in src/py_premiere/models/project_item.py
def __getitem__(self, key: int | str) -> ProjectItem:
    return self.children[key]

__init__

__init__(_element, project, item_type)
Source code in src/py_premiere/models/project_item.py
def __init__(
    self,
    _element: ET.Element,
    project: Project,
    item_type: ProjectItemType,
) -> None:
    self._element = _element
    self.project = project
    self._type = item_type
    self._children: list[ProjectItem] = []
    self._markers: list[Marker] = []
    self._media_path: Path | None = None
    self._master_element: ET.Element | None = None
    self._parent: ProjectItem | None = None
    self._clip_elements: list[ET.Element] = []
    self._node_id_int: int | None = None
    self._default_out_ticks: int | None = None
    self._sequence_uid: str | None = None

__iter__

__iter__()
Source code in src/py_premiere/models/project_item.py
def __iter__(self) -> Iterator[ProjectItem]:
    return iter(self._children)

__len__

__len__()
Source code in src/py_premiere/models/project_item.py
def __len__(self) -> int:
    return len(self._children)

__repr__

__repr__()
Source code in src/py_premiere/models/project_item.py
def __repr__(self) -> str:
    return f"ProjectItem(name={self.name!r}, type={self._type.name})"

add_bin

add_bin(name)

Create a child bin and return it.

Works on the root and on any bin (nesting into an empty bin synthesizes its child-item list). The view-state properties Premiere writes for a new bin are elided (Premiere synthesizes them on open).

Source code in src/py_premiere/models/project_item.py
def add_bin(self, name: str) -> ProjectItem:
    """Create a child bin and return it.

    Works on the root and on any bin (nesting into an empty bin
    synthesizes its child-item list). The view-state properties Premiere
    writes for a new bin are elided (Premiere synthesizes them on open).
    """
    _validate_name(name)
    if self._type is ProjectItemType.CLIP:
        raise ValueError("cannot add a bin under a clip item")
    container = self._element.find("ProjectItemContainer")
    if container is None:
        raise ValueError("item has no ProjectItemContainer")
    items = _child_items(container)
    document = self.project._document
    uid = str(uuid.uuid4())
    bin_element = _new_bin_element(uid, name)
    document.attach_object(bin_element)
    _add_item_ref(items, uid)
    child = ProjectItem(bin_element, self.project, ProjectItemType.BIN)
    child._parent = self
    self._children.append(child)
    return child

add_marker

add_marker(
    name,
    start,
    comments="",
    marker_type="Comment",
    duration=None,
)

Create a clip marker on this item and return it.

start is in media time (a still's first frame sits at its 1-hour default timecode, not 0).

Source code in src/py_premiere/models/project_item.py
def add_marker(
    self,
    name: str,
    start: Time,
    comments: str = "",
    marker_type: str = "Comment",
    duration: Time | None = None,
) -> Marker:
    """Create a clip marker on this item and return it.

    `start` is in media time (a still's first frame sits at its 1-hour
    default timecode, not 0).
    """
    if self._type is not ProjectItemType.CLIP:
        raise ValueError("only clip items carry markers")
    core = self._own_clip_core()
    if core is None:
        raise ValueError("item has no master clip")
    document = self.project._document
    inner = _ensure_clip_marker_list(document, core)
    marker = Marker(name, start, comments, marker_type, duration)
    _attach_marker(document, inner, marker)
    self._markers.append(marker)
    return marker

attach_proxy

attach_proxy(path, is_hi_res=False)

Attach proxy media to this item.

ExtendScript's attachProxy. A proxy is a second Media object (flagged IsProxy) with its own stream, referenced from the media source's Content bag; the proxy's stream carries the HI-RES frame rect as an override so the item keeps reporting the original raster (18_proxy). The file must be readable and match the item's frame aspect ratio, as Premiere itself requires.

is_hi_res swaps the roles, as the ExtendScript flag does: path becomes the media this item PLAYS and what it played until now is demoted to the proxy. The end state is the same graph either way - one Media flagged IsProxy, one not - and the MASTER CLIP takes the new file's name while the panel item's own Name is left behind, stale, which is what Premiere does too (verified against its calls in both directions, samples/refs/gaps/proxy_*.prproj).

Source code in src/py_premiere/models/project_item.py
def attach_proxy(self, path: str | Path, is_hi_res: bool = False) -> None:
    """Attach proxy media to this item.

    ExtendScript's `attachProxy`. A proxy is a second `Media` object
    (flagged `IsProxy`) with its own stream, referenced from the media
    source's `Content` bag; the proxy's stream carries the HI-RES
    frame rect as an override so the item keeps reporting the original
    raster (18_proxy). The file must be readable and match the item's
    frame aspect ratio, as Premiere itself requires.

    `is_hi_res` swaps the roles, as the ExtendScript flag does: `path`
    becomes the media this item PLAYS and what it played until now is
    demoted to the proxy. The end state is the same graph either way -
    one `Media` flagged `IsProxy`, one not - and the MASTER CLIP takes
    the new file's name while the panel item's own `Name` is left
    behind, stale, which is what Premiere does too (verified against
    its calls in both directions, `samples/refs/gaps/proxy_*.prproj`).
    """
    _validate_proxy_path(path)
    validate_bool(is_hi_res)
    if self.has_proxy:
        raise ValueError("item already has proxy media attached")
    content = self._media_content()
    media = self._media_element()
    stream_ref = None if media is None else media.find("VideoStream")
    if content is None or media is None or stream_ref is None:
        raise ValueError("proxies attach to video media clip items")
    document = self.project._document
    own_rect = document.resolve(stream_ref).findtext("FrameRect")
    if not own_rect:
        raise ValueError("source video stream has no frame rect")
    if not is_hi_res:
        proxy_uid = self.project._make_proxy_media(Path(path), own_rect)
        append_child(content, ET.Element("ProxyMedia", {"ObjectURef": proxy_uid}))
        return
    self._attach_hi_res(document, content, media, own_rect, Path(path))

create_sub_clip

create_sub_clip(
    name,
    start,
    end,
    has_hard_boundaries=False,
    take_video=True,
    take_audio=True,
)

Create a subclip of this item in the project panel and return it.

Mirrors ExtendScript's createSubClip. A subclip is a SECOND master clip over the same media file - Premiere duplicates the whole media graph rather than sharing objects (28_subclip) - narrowed by StartBoundary/EndBoundary on its media source. Soft boundaries can be trimmed past on the timeline, hard ones cannot.

take_video/take_audio subclip only part of an A/V source, as ExtendScript's trailing flags do. NOTE the scripting guide lists them the other way round (takeAudio, takeVideo); driving the real call proved the fifth argument governs VIDEO and the sixth AUDIO, so py names them in their actual order. Dropping a half leaves the media's stream in place and omits that half's clip and source from the new master, which is what Premiere writes.

The subclip's graph is synthesized the way an import is, so the media file must still be readable; it then takes over the source's file identity (one FileKey/content state per file, the modification blob carried once), and the source's footage interpretation overrides do NOT carry over.

Source code in src/py_premiere/models/project_item.py
def create_sub_clip(
    self,
    name: str,
    start: Time,
    end: Time,
    has_hard_boundaries: bool = False,
    take_video: bool = True,
    take_audio: bool = True,
) -> ProjectItem:
    """Create a subclip of this item in the project panel and return it.

    Mirrors ExtendScript's `createSubClip`. A subclip is a SECOND master
    clip over the same media file - Premiere duplicates the whole media
    graph rather than sharing objects (28_subclip) - narrowed by
    `StartBoundary`/`EndBoundary` on its media source. Soft boundaries
    can be trimmed past on the timeline, hard ones cannot.

    `take_video`/`take_audio` subclip only part of an A/V source, as
    ExtendScript's trailing flags do. NOTE the scripting guide lists
    them the other way round (`takeAudio, takeVideo`); driving the
    real call proved the fifth argument governs VIDEO and the sixth
    AUDIO, so py names them in their actual order. Dropping a half
    leaves the media's stream in place and omits that half's clip and
    source from the new master, which is what Premiere writes.

    The subclip's graph is synthesized the way an import is, so the
    media file must still be readable; it then takes over the source's
    file identity (one `FileKey`/content state per file, the
    modification blob carried once), and the source's footage
    interpretation overrides do NOT carry over.
    """
    _validate_name(name)
    validate_time(start)
    validate_time(end)
    validate_bool(has_hard_boundaries)
    validate_bool(take_video)
    validate_bool(take_audio)
    if not (take_video or take_audio):
        raise ValueError("a subclip must take the video, the audio, or both")
    if self._type is not ProjectItemType.CLIP or self.is_sequence:
        raise ValueError("subclips can only be created from media clip items")
    if self.media_path is None:
        raise ValueError("item has no media file to subclip")
    if not 0 <= start.ticks < end.ticks:
        raise ValueError("subclip boundaries must satisfy 0 <= start < end")
    if self._master_element is None:
        raise ValueError("item has no master clip")
    document = self.project._document
    item = self.project.import_files([self.media_path])[0]
    # The master carries the live subclip name; the ProjectItem copy
    # keeps the file name, exactly as Premiere writes it.
    master = item._master_element
    if master is None:
        raise ValueError("synthesized subclip has no master clip")
    name_element = master.find("Name")
    if name_element is not None:
        name_element.text = name
    logging_ref = master.find("LoggingInfo")
    if logging_ref is None:
        raise ValueError("synthesized subclip has no logging info")
    logging = document.resolve(logging_ref)
    for tag, text in (
        ("ClipName", name),
        ("MediaInPoint", str(start.ticks)),
        ("MediaOutPoint", str(end.ticks)),
    ):
        leaf = logging.find(tag)
        if leaf is not None:
            leaf.text = text
    if not (take_video and take_audio):
        item._drop_subclip_half(take_video)
    # A/V media narrows BOTH its sources: the identical boundary trio
    # lands in the video AND the audio source's Content bag
    # (71_av_subclip) - or in the surviving one alone when a half was
    # dropped.
    contents = []
    for clip_element in item._clip_elements:
        core = clip_core(clip_element)
        source_ref = None if core is None else core.find("Source")
        if source_ref is None:
            continue
        content = document.resolve(source_ref).find("MediaSource/Content")
        if content is not None:
            contents.append(content)
    if not contents:
        raise ValueError("synthesized subclip has no media content bag")
    for content in contents:
        append_leaf(content, "StartBoundary", str(start.ticks))
        append_leaf(content, "EndBoundary", str(end.ticks))
        append_leaf(
            content,
            "BoundariesAreHard",
            "true" if has_hard_boundaries else "false",
        )
    # The panel label stamp (`Column.PropertyText.Label`) is kept as the
    # import wrote it: Premiere itself is inconsistent - 28_subclip's
    # subclip carries none, 71_av_subclip's does - and a resave
    # re-stamps it either way.
    self._share_file_identity(item)
    return item

move_to

move_to(new_parent)

Move this item into another bin (or the root).

Only the parent-child wiring changes; the item's own object is untouched.

Source code in src/py_premiere/models/project_item.py
def move_to(self, new_parent: ProjectItem) -> None:
    """Move this item into another bin (or the root).

    Only the parent-child wiring changes; the item's own object is
    untouched.
    """
    if self._type is ProjectItemType.ROOT:
        raise ValueError("cannot move the root item")
    if new_parent.project is not self.project:
        # Wiring a reference across documents leaves the destination with
        # a dangling ObjectURef and the source with an orphan object.
        raise ValueError("cannot move an item into another project")
    if new_parent._type is ProjectItemType.CLIP:
        raise ValueError("cannot move an item under a clip")
    if self._parent is None:
        raise ValueError("item has no parent to move from")
    if new_parent is self._parent:
        return
    ancestor: ProjectItem | None = new_parent
    while ancestor is not None:
        if ancestor is self:
            raise ValueError("cannot move an item into itself or a descendant")
        ancestor = ancestor._parent
    container = new_parent._element.find("ProjectItemContainer")
    if container is None:
        raise ValueError("destination has no ProjectItemContainer")
    destination = _child_items(container)
    uid = self._element.get("ObjectUID")
    if uid is None:
        raise ValueError("item has no ObjectUID")
    source = self._parent._element.find("ProjectItemContainer")
    if source is not None:
        _detach_item_ref(source, uid)
    _add_item_ref(destination, uid)
    self._parent._children.remove(self)
    new_parent._children.append(self)
    self._parent = new_parent

remove_bin

remove_bin(child)

Remove a child bin, deleting its contents recursively.

Child bins are removed depth-first; child clip items go through remove_item (so a bin holding an in-use clip refuses removal before anything is touched).

Source code in src/py_premiere/models/project_item.py
def remove_bin(self, child: ProjectItem) -> None:
    """Remove a child bin, deleting its contents recursively.

    Child bins are removed depth-first; child clip items go through
    `remove_item` (so a bin holding an in-use clip refuses removal
    before anything is touched).
    """
    if child not in self._children:
        raise ValueError("item is not a child of this bin")
    if child._type is not ProjectItemType.BIN:
        raise ValueError("only bins can be removed")
    for grandchild in list(child._children):
        if grandchild._type is ProjectItemType.BIN:
            child.remove_bin(grandchild)
        else:
            child.remove_item(grandchild)
    document = self.project._document
    uid = child._element.get("ObjectUID")
    container = self._element.find("ProjectItemContainer")
    if container is not None and uid is not None:
        _detach_item_ref(container, uid)
    document.remove_object(child._element)
    self._children.remove(child)

remove_item

remove_item(child)

Remove a child clip item, deleting its media objects.

Deletes the exact graph Premiere deletes with a panel item (master clip, template clips, logging, markers, source, media, streams), keeping anything still referenced from outside it (e.g. media shared with another item). Refuses when the item is placed on a timeline (remove the clips first) or backed by a sequence.

Source code in src/py_premiere/models/project_item.py
def remove_item(self, child: ProjectItem) -> None:
    """Remove a child clip item, deleting its media objects.

    Deletes the exact graph Premiere deletes with a panel item (master
    clip, template clips, logging, markers, source, media, streams),
    keeping anything still referenced from outside it (e.g. media
    shared with another item). Refuses when the item is placed on a
    timeline (remove the clips first) or backed by a sequence.
    """
    if child not in self._children:
        raise ValueError("item is not a child of this bin")
    if child._type is not ProjectItemType.CLIP:
        raise ValueError("only clip items can be removed; use remove_bin")
    if child.is_sequence:
        raise ValueError("removing a sequence item is not supported")
    master = child._master_element
    if master is None:
        raise ValueError("item has no master clip")
    document = self.project._document
    # One pass answers both questions: who still points at the master
    # clip (a timeline placement, which blocks the removal), and what the
    # item exclusively owns (the graph that goes with it).
    index = ReferenceIndex(document)
    if index.referrers_outside(master, [child._element, master]):
        raise ValueError("item is in use on a timeline; remove its clips first")
    uid = child._element.get("ObjectUID")
    container = self._element.find("ProjectItemContainer")
    if container is not None and uid is not None:
        _detach_item_ref(container, uid)
    for element in document.owned_objects([child._element, master], index):
        document.remove_object(element)
    self._children.remove(child)
    # The lookup maps hold this item keyed by its master/sequence UID.
    self.project._items_by_master_uid = None
    self.project._items_by_sequence_uid = None

remove_marker

remove_marker(marker)

Remove a clip marker from this item.

Source code in src/py_premiere/models/project_item.py
def remove_marker(self, marker: Marker) -> None:
    """Remove a clip marker from this item."""
    if marker not in self._markers:
        raise ValueError("marker does not belong to this item")
    core = self._own_clip_core()
    reference = core.find("MarkerOwner/Markers") if core is not None else None
    if reference is None:
        raise ValueError("master clip has no marker collection")
    document = self.project._document
    inner = document.resolve(reference).find("Markers")
    if inner is None:
        raise ValueError("marker collection has no inner list")
    _detach_marker(document, inner, marker)
    self._markers.remove(marker)

walk

walk()

Every descendant item, depth-first.

Source code in src/py_premiere/models/project_item.py
def walk(self) -> Iterator[ProjectItem]:
    """Every descendant item, depth-first."""
    for child in self._children:
        yield child
        yield from child.walk()