Skip to content
Snippets Groups Projects
operators_extra_actions.py 69.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • 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 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948
                        elif self.prop == 'proxy':
                            i.use_proxy = strip.use_proxy
                            i.use_proxy_custom_file = strip.use_proxy_custom_file
                            p = strip.use_proxy_custom_directory  # pep80
                            i.use_proxy_custom_directory = p
                            i.proxy.filepath = strip.proxy.filepath
                            i.proxy.directory = strip.proxy.directory
                            i.proxy.build_25 = strip.proxy.build_25
                            i.proxy.build_50 = strip.proxy.build_50
                            i.proxy.build_75 = strip.proxy.build_75
                            i.proxy.build_100 = strip.proxy.build_100
                            i.proxy.quality = strip.proxy.quality
                            i.proxy.timecode = strip.proxy.timecode
                        elif self.prop == 'strobe':
                            i.strobe = strip.strobe
                        elif self.prop == 'color_multiply':
                            i.color_multiply = strip.color_multiply
                        elif self.prop == 'color_saturation':
                            i.color_saturation = strip.color_saturation
                        elif self.prop == 'deinterlace':
                            i.use_deinterlace = strip.use_deinterlace
                        elif self.prop == 'flip':
                            i.use_flip_x = strip.use_flip_x
                            i.use_flip_y = strip.use_flip_y
                        elif self.prop == 'float':
                            i.use_float = strip.use_float
                        elif self.prop == 'alpha_mode':
                            i.alpha_mode = strip.alpha_mode
                        elif self.prop == 'reverse':
                            i.use_reverse_frames = strip.use_reverse_frames
                        elif self.prop == 'pan':
                            i.pan = strip.pan
                        elif self.prop == 'pitch':
                            i.pitch = strip.pitch
                        elif self.prop == 'volume':
                            i.volume = strip.volume
                        elif self.prop == 'cache':
                            i.use_memory_cache = strip.use_memory_cache
                        elif self.prop == 'directory':
                            i.directory = strip.directory
                        elif self.prop == 'mpeg_preseek':
                            i.mpeg_preseek = strip.mpeg_preseek
                        elif self.prop == 'stream_index':
                            i.stream_index = strip.stream_index
                        elif self.prop == 'wipe':
                            i.angle = strip.angle
                            i.blur_width = strip.blur_width
                            i.direction = strip.direction
                            i.transition_type = strip.transition_type
                        elif self.prop == 'transform':
                            i.interpolation = strip.interpolation
                            i.rotation_start = strip.rotation_start
                            i.use_uniform_scale = strip.use_uniform_scale
                            i.scale_start_x = strip.scale_start_x
                            i.scale_start_y = strip.scale_start_y
                            i.translation_unit = strip.translation_unit
                            i.translate_start_x = strip.translate_start_x
                            i.translate_start_y = strip.translate_start_y
                        elif self.prop == 'color':
                            i.color = strip.color
                        elif self.prop == 'speed':
                            i.use_default_fade = strip.use_default_fade
                            i.speed_factor = strip.speed_factor
                            i.use_as_speed = strip.use_as_speed
                            i.scale_to_length = strip.scale_to_length
                            i.multiply_speed = strip.multiply_speed
                            i.use_frame_blend = strip.use_frame_blend
                        elif self.prop == 'multicam_source':
                            i.multicam_source = strip.multicam_source
                        elif self.prop == 'effect_fader':
                            i.use_default_fade = strip.use_default_fade
                            i.effect_fader = strip.effect_fader
                    except:
                        pass
    
            bpy.ops.sequencer.reload()
            return {'FINISHED'}
    
    
    # FADE IN AND OUT
    class Sequencer_Extra_FadeInOut(bpy.types.Operator):
        bl_idname = 'sequencerextra.fadeinout'
        bl_label = 'Fade...'
        bl_description = 'Fade volume or opacity of active strip'
        mode = EnumProperty(
                name='Direction',
                items=(
                ('IN', 'Fade In...', ''),
                ('OUT', 'Fade Out...', ''),
                ('INOUT', 'Fade In and Out...', '')),
                default='IN',
                )
        bl_options = {'REGISTER', 'UNDO'}
        
        fade_duration = IntProperty(
            name='Duration',
            description='Number of frames to fade',
            min=1, max=250,
            default=25)
        fade_amount = FloatProperty(
            name='Amount',
            description='Maximum value of fade',
            min=0.0,
            max=100.0,
            default=1.0)
    
        @classmethod
        def poll(cls, context):
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return True
            else:
                return False
    
        def execute(self, context):
            seq = context.scene.sequence_editor
            scn = context.scene
            strip = seq.active_strip
            tmp_current_frame = context.scene.frame_current
    
            if strip.type == 'SOUND':
                if(self.mode) == 'OUT':
                    scn.frame_current = strip.frame_final_end - self.fade_duration
                    strip.volume = self.fade_amount
                    strip.keyframe_insert('volume')
                    scn.frame_current = strip.frame_final_end
                    strip.volume = 0
                    strip.keyframe_insert('volume')
                elif(self.mode) == 'INOUT':
                    scn.frame_current = strip.frame_final_start
                    strip.volume = 0
                    strip.keyframe_insert('volume')
                    scn.frame_current += self.fade_duration
                    strip.volume = self.fade_amount
                    strip.keyframe_insert('volume')
                    scn.frame_current = strip.frame_final_end - self.fade_duration
                    strip.volume = self.fade_amount
                    strip.keyframe_insert('volume')
                    scn.frame_current = strip.frame_final_end
                    strip.volume = 0
                    strip.keyframe_insert('volume')
                else:
                    scn.frame_current = strip.frame_final_start
                    strip.volume = 0
                    strip.keyframe_insert('volume')
                    scn.frame_current += self.fade_duration
                    strip.volume = self.fade_amount
                    strip.keyframe_insert('volume')
    
            else:
                if(self.mode) == 'OUT':
                    scn.frame_current = strip.frame_final_end - self.fade_duration
                    strip.blend_alpha = self.fade_amount
                    strip.keyframe_insert('blend_alpha')
                    scn.frame_current = strip.frame_final_end
                    strip.blend_alpha = 0
                    strip.keyframe_insert('blend_alpha')
                elif(self.mode) == 'INOUT':
                    scn.frame_current = strip.frame_final_start
                    strip.blend_alpha = 0
                    strip.keyframe_insert('blend_alpha')
                    scn.frame_current += self.fade_duration
                    strip.blend_alpha = self.fade_amount
                    strip.keyframe_insert('blend_alpha')
                    scn.frame_current = strip.frame_final_end - self.fade_duration
                    strip.blend_alpha = self.fade_amount
                    strip.keyframe_insert('blend_alpha')
                    scn.frame_current = strip.frame_final_end
                    strip.blend_alpha = 0
                    strip.keyframe_insert('blend_alpha')
                else:
                    scn.frame_current = strip.frame_final_start
                    strip.blend_alpha = 0
                    strip.keyframe_insert('blend_alpha')
                    scn.frame_current += self.fade_duration
                    strip.blend_alpha = self.fade_amount
                    strip.keyframe_insert('blend_alpha')
    
            scn.frame_current = tmp_current_frame
    
            scn.default_fade_duration = self.fade_duration
            scn.default_fade_amount = self.fade_amount
            return{'FINISHED'}
    
        def invoke(self, context, event):
            scn = context.scene
            initSceneProperties(context, scn)
            self.fade_duration = scn.default_fade_duration
            self.fade_amount = scn.default_fade_amount
            return context.window_manager.invoke_props_dialog(self)
    
    
    # EXTEND TO FILL
    class Sequencer_Extra_ExtendToFill(bpy.types.Operator):
        bl_idname = 'sequencerextra.extendtofill'
        bl_label = 'Extend to Fill'
        bl_description = 'Extend active strip forward to fill adjacent space'
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(cls, context):
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return True
            else:
                return False
    
        def execute(self, context):
            scn = context.scene
            seq = scn.sequence_editor
            meta_level = len(seq.meta_stack)
            if meta_level > 0:
                seq = seq.meta_stack[meta_level - 1]
            strip = functions.act_strip(context)
            chn = strip.channel
            stf = strip.frame_final_end
            enf = 300000
    
            for i in seq.sequences:
                ffs = i.frame_final_start
                if (i.channel == chn and ffs > stf):
                    if ffs < enf:
                        enf = ffs
            if enf == 300000 and stf < scn.frame_end:
                enf = scn.frame_end
    
            if enf == 300000 or enf == stf:
                self.report({'ERROR_INVALID_INPUT'}, 'Unable to extend')
                return {'CANCELLED'}
            else:
                strip.frame_final_end = enf
    
            bpy.ops.sequencer.reload()
            return {'FINISHED'}
    
    
    # DISTRIBUTE
    class Sequencer_Extra_Distribute(bpy.types.Operator):
        bl_idname = 'sequencerextra.distribute'
        bl_label = 'Distribute...'
        bl_description = 'Evenly distribute selected strips'
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(self, context):
            scn = context.scene
            if scn and scn.sequence_editor:
                return scn.sequence_editor.sequences
            else:
                return False
    
        def execute(self, context):
            scn = context.scene
            seq = scn.sequence_editor
            seq_all = scn.sequence_editor
            meta_level = len(seq.meta_stack)
            if meta_level > 0:
                seq = seq.meta_stack[meta_level - 1]
            seq_list = {}
            first_start = 300000
            item_num = 0
            for i in seq.sequences:
                if i.select == True:
                    seq_list[i.frame_start] = i.name
                    item_num += 1
                    if i.frame_start < first_start:
                        first_start = i.frame_start
            n = item_num - 1
            if(self.distribute_reverse):
                for key in sorted(seq_list.keys()):
                    dest = first_start + (n * self.distribute_offset)
                    seq_all.sequences_all[str(seq_list[key])].frame_start = dest
                    n -= 1
            else:
                for key in sorted(seq_list.keys(), reverse=True):
                    dest = first_start + (n * self.distribute_offset)
                    seq_all.sequences_all[str(seq_list[key])].frame_start = dest
                    n -= 1
    
            scn.default_distribute_offset = self.distribute_offset
            scn.default_distribute_reverse = self.distribute_reverse
            return{'FINISHED'}
    
        def invoke(self, context, event):
            scn = context.scene
            initSceneProperties(context, scn)
            self.distribute_offset = scn.default_distribute_offset
            self.distribute_reverse = scn.default_distribute_reverse
            return context.window_manager.invoke_props_dialog(self)
    
    
    # SKIP ONE SECOND
    class Sequencer_Extra_FrameSkip(bpy.types.Operator):
        bl_label = 'Skip One Second'
        bl_idname = 'screenextra.frame_skip'
        bl_description = 'Skip through the Timeline by one-second increments'
        bl_options = {'REGISTER', 'UNDO'}
        back = BoolProperty(
            name='Back',
            default=False)
    
        def execute(self, context):
            one_second = bpy.context.scene.render.fps
            if self.back == True:
                one_second *= -1
            bpy.ops.screen.frame_offset(delta=one_second)
            return {'FINISHED'}
    
    
    # JOG/SHUTTLE
    class Sequencer_Extra_JogShuttle(bpy.types.Operator):
        bl_label = 'Jog/Shuttle'
        bl_idname = 'sequencerextra.jogshuttle'
        bl_description = 'Jog through current sequence'
    
        def execute(self, context):
            scn = context.scene
            start_frame = scn.frame_start
            end_frame = scn.frame_end
            duration = end_frame - start_frame
            diff = self.x - self.init_x
            diff /= 5
            diff = int(diff)
            extended_frame = diff + (self.init_current_frame - start_frame)
            looped_frame = extended_frame % (duration + 1)
            target_frame = start_frame + looped_frame
            context.scene.frame_current = target_frame
    
        def modal(self, context, event):
            if event.type == 'MOUSEMOVE':
                self.x = event.mouse_x
                self.execute(context)
            elif event.type == 'LEFTMOUSE':
                return {'FINISHED'}
            elif event.type in ('RIGHTMOUSE', 'ESC'):
                return {'CANCELLED'}
    
            return {'RUNNING_MODAL'}
    
        def invoke(self, context, event):
            scn = context.scene
            self.x = event.mouse_x
            self.init_x = self.x
            self.init_current_frame = scn.frame_current
            self.execute(context)
            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
    
    
    # OPEN IN MOVIE CLIP EDITOR FROM FILE BROWSER
    class Clip_Extra_OpenFromFileBrowser(bpy.types.Operator):
        bl_label = 'Open from File Browser'
        bl_idname = 'clipextra.openfromfilebrowser'
        bl_description = 'Load a Movie or Image Sequence from File Browser'
        bl_options = {'REGISTER', 'UNDO'}
    
        def execute(self, context):
            for a in context.window.screen.areas:
                if a.type == 'FILE_BROWSER':
                    params = a.spaces[0].params
                    break
            try:
                params
            except:
                self.report({'ERROR_INVALID_INPUT'}, 'No visible File Browser')
                return {'CANCELLED'}
    
            if params.filename == '':
                self.report({'ERROR_INVALID_INPUT'}, 'No file selected')
                return {'CANCELLED'}
    
            strip = functions.act_strip(context)
            path = params.directory + params.filename
            strip_type = functions.detect_strip_type(params.filename)
            data_exists = False
    
            if strip_type in ('MOVIE', 'IMAGE'):
                for i in bpy.data.movieclips:
                    if i.filepath == path:
                        data_exists = True
                        data = i
    
                if data_exists == False:
                    try:
                        data = bpy.data.movieclips.load(filepath=path)
                    except:
                        self.report({'ERROR_INVALID_INPUT'}, 'Error loading file')
                        return {'CANCELLED'}
            else:
                self.report({'ERROR_INVALID_INPUT'}, 'Invalid file format')
                return {'CANCELLED'}
    
            for a in context.window.screen.areas:
                if a.type == 'CLIP_EDITOR':
                    a.spaces[0].clip = data
    
            return {'FINISHED'}
    
    
    # OPEN IN MOVIE CLIP EDITOR FROM SEQUENCER
    class Clip_Extra_OpenActiveStrip(bpy.types.Operator):
        bl_label = 'Open Active Strip'
        bl_idname = 'clipextra.openactivestrip'
        bl_description = 'Load a Movie or Image Sequence from Sequence Editor'
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(cls, context):
            scn = context.scene
            strip = functions.act_strip(context)
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return strip.type in ('MOVIE', 'IMAGE')
            else:
                return False
    
        def execute(self, context):
            strip = functions.act_strip(context)
            data_exists = False
    
            if strip.type == 'MOVIE':
                path = strip.filepath
            elif strip.type == 'IMAGE':
                base_dir = bpy.path.relpath(strip.directory)
                filename = strip.elements[0].filename
                path = base_dir + '/' + filename
            else:
                self.report({'ERROR_INVALID_INPUT'}, 'Invalid file format')
                return {'CANCELLED'}
    
            for i in bpy.data.movieclips:
                if i.filepath == path:
                    data_exists = True
                    data = i
            if data_exists == False:
                try:
                    data = bpy.data.movieclips.load(filepath=path)
                except:
                    self.report({'ERROR_INVALID_INPUT'}, 'Error loading file')
                    return {'CANCELLED'}
    
            for a in context.window.screen.areas:
                if a.type == 'CLIP_EDITOR':
                    a.spaces[0].clip = data
    
            return {'FINISHED'}
    
    
    # PLACE FROM FILE BROWSER WITH PROXY
    class Sequencer_Extra_PlaceFromFileBrowserProxy(bpy.types.Operator):
        bl_label = 'Place'
        bl_idname = 'sequencerextra.placefromfilebrowserproxy'
        bl_description = 'Place or insert active file from File Browser, '\
        'and add proxy file with according suffix and extension'
        insert = BoolProperty(name='Insert', default=False)
        build_25 = BoolProperty(name='default_build_25',
            description='default build_25',
            default=True)
        build_50 = BoolProperty(name='default_build_50',
            description='default build_50',
            default=True)
        build_75 = BoolProperty(name='default_build_75',
            description='default build_75',
            default=True)
        build_100 = BoolProperty(name='default_build_100',
            description='default build_100',
            default=True)
        proxy_suffix = StringProperty(
            name='default proxy suffix',
            description='default proxy filename suffix',
            default="-25")
        proxy_extension = StringProperty(
            name='default proxy extension',
            description='default proxy extension',
            default=".mkv")
        proxy_path = StringProperty(
            name='default proxy path',
            description='default proxy path',
            default="")
    
        bl_options = {'REGISTER', 'UNDO'}
    
        def invoke(self, context, event):
            scn = context.scene
            initSceneProperties(context, scn)
            self.build_25 = scn.default_build_25
            self.build_50 = scn.default_build_50
            self.build_75 = scn.default_build_75
            self.build_100 = scn.default_build_100
            self.proxy_suffix = scn.default_proxy_suffix
            self.proxy_extension = scn.default_proxy_extension
            self.proxy_path = scn.default_proxy_path
    
            return context.window_manager.invoke_props_dialog(self)
    
        def execute(self, context):
            scn = context.scene
            for a in context.window.screen.areas:
                if a.type == 'FILE_BROWSER':
                    params = a.spaces[0].params
                    break
            try:
                params
            except UnboundLocalError:
                self.report({'ERROR_INVALID_INPUT'}, 'No visible File Browser')
                return {'CANCELLED'}
    
            if params.filename == '':
                self.report({'ERROR_INVALID_INPUT'}, 'No file selected (proxy)')
                return {'CANCELLED'}
            path = os.path.join(params.directory, params.filename)
            frame = context.scene.frame_current
            strip_type = functions.detect_strip_type(params.filename)
    
            try:
                if strip_type == 'IMAGE':
                    image_file = []
                    filename = {"name": params.filename}
                    image_file.append(filename)
                    f_in = scn.frame_current
                    f_out = f_in + scn.render.fps - 1
                    bpy.ops.sequencer.image_strip_add(files=image_file,
                    directory=params.directory, frame_start=f_in,
                    frame_end=f_out, relative_path=False)
                elif strip_type == 'MOVIE':
                    bpy.ops.sequencer.movie_strip_add(filepath=path,
                    frame_start=frame, relative_path=False)
    
                    strip = functions.act_strip(context)
                    strip.use_proxy = True
    
                    # check if proxy exists, otherwise, uncheck proxy custom file
                    proxy_filepath = params.directory + self.proxy_path
                    proxy_filename = params.filename.rpartition(".")[0] + \
                    self.proxy_suffix + self.proxy_extension
                    proxypath = os.path.join(proxy_filepath, proxy_filename)
                    strip.proxy.build_25 = self.build_25
                    strip.proxy.build_50 = self.build_50
                    strip.proxy.build_75 = self.build_75
                    strip.proxy.build_100 = self.build_100
                    #print("----------------", proxypath)
                    if os.path.isfile(proxypath):
                        strip.use_proxy_custom_file = True
                        strip.proxy.filepath = proxypath
    
                elif strip_type == 'SOUND':
                    bpy.ops.sequencer.sound_strip_add(filepath=path,
                    frame_start=frame, relative_path=False)
                else:
                    self.report({'ERROR_INVALID_INPUT'}, 'Invalid file format')
                    return {'CANCELLED'}
    
            except:
                self.report({'ERROR_INVALID_INPUT'}, 'Error loading file (proxy)')
                return {'CANCELLED'}
    
            scn.default_proxy_suffix = self.proxy_suffix
            scn.default_proxy_extension = self.proxy_extension
            scn.default_proxy_path = self.proxy_path
            scn.default_build_25 = self.build_25
            scn.default_build_50 = self.build_50
            scn.default_build_75 = self.build_75
            scn.default_build_100 = self.build_100
    
            if self.insert == True:
                try:
                    bpy.ops.sequencerextra.insert()
                except:
                    self.report({'ERROR_INVALID_INPUT'}, 'Execution Error, '\
                    'check your Blender version')
                    return {'CANCELLED'}
            else:
                strip = functions.act_strip(context)
                scn.frame_current += strip.frame_final_duration
                bpy.ops.sequencer.reload()
    
            return {'FINISHED'}
    
    
    # OPEN IMAGE WITH EDITOR AND create movie clip strip
    class Sequencer_Extra_CreateMovieclip(bpy.types.Operator):
        bl_label = 'Create a Movieclip from selected strip'
        bl_idname = 'sequencerextra.createmovieclip'
        bl_description = 'Create a Movieclip strip from a MOVIE or IMAGE strip'
    
        """
        When a movie or image strip is selected, this operator creates a movieclip
        or find the correspondent movieclip that already exists for this footage,
        and add a VSE clip strip with same cuts the original strip has.
        It can convert movie strips and image sequences, both with hard cuts or
        soft cuts.
        """
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return strip.type in ('MOVIE', 'IMAGE')
            else:
                return False
    
        def execute(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
    
            if strip.type == 'MOVIE':
                #print("movie", strip.frame_start)
                path = strip.filepath
                #print(path)
                data_exists = False
                for i in bpy.data.movieclips:
                    if i.filepath == path:
                        data_exists = True
                        data = i
                newstrip = None
                if data_exists == False:
                    try:
                        data = bpy.data.movieclips.load(filepath=path)
                        newstrip = bpy.ops.sequencer.movieclip_strip_add(\
                            replace_sel=True, overlap=False, clip=data.name)
                        newstrip = functions.act_strip(context)
                        newstrip.frame_start = strip.frame_start\
                            - strip.animation_offset_start
                        tin = strip.frame_offset_start + strip.frame_start
                        tout = tin + strip.frame_final_duration
                        #print(newstrip.frame_start, strip.frame_start, tin, tout)
                        functions.triminout(newstrip, tin, tout)
                    except:
                        self.report({'ERROR_INVALID_INPUT'}, 'Error loading file')
                        return {'CANCELLED'}
    
                else:
                    try:
                        newstrip = bpy.ops.sequencer.movieclip_strip_add(\
                            replace_sel=True, overlap=False, clip=data.name)
                        newstrip = functions.act_strip(context)
                        newstrip.frame_start = strip.frame_start\
                            - strip.animation_offset_start
                        # i need to declare the strip this way in order
                        # to get triminout() working
                        clip = bpy.context.scene.sequence_editor.sequences[\
                            newstrip.name]
                        # i cannot change these movie clip attributes via scripts
                        # but it works in the python console...
                        #clip.animation_offset_start = strip.animation.offset_start
                        #clip.animation_offset_end = strip.animation.offset_end
                        #clip.frame_final_duration = strip.frame_final_duration
                        tin = strip.frame_offset_start + strip.frame_start
                        tout = tin + strip.frame_final_duration
                        #print(newstrip.frame_start, strip.frame_start, tin, tout)
                        functions.triminout(clip, tin, tout)
                    except:
                        self.report({'ERROR_INVALID_INPUT'}, 'Error loading file')
                        return {'CANCELLED'}
    
            elif strip.type == 'IMAGE':
                #print("image")
                base_dir = bpy.path.abspath(strip.directory)
                scn.frame_current = strip.frame_start -\
                    strip.animation_offset_start
                # searching for the first frame of the sequencer. This is mandatory
                # for hard cutted sequence strips to be correctly converted,
                # avoiding to create a new movie clip if not needed
                filename = sorted(os.listdir(base_dir))[0]
                path = os.path.join(base_dir, filename)
                #print(path)
                data_exists = False
                for i in bpy.data.movieclips:
                    #print(i.filepath, path)
                    if i.filepath == path:
                        data_exists = True
                        data = i
                #print(data_exists)
                if data_exists == False:
                    try:
                        data = bpy.data.movieclips.load(filepath=path)
                        newstrip = bpy.ops.sequencer.movieclip_strip_add(\
                            replace_sel=True, overlap=False,\
                            clip=data.name)
                        newstrip = functions.act_strip(context)
                        newstrip.frame_start = strip.frame_start\
                            - strip.animation_offset_start
                        clip = bpy.context.scene.sequence_editor.sequences[\
                        newstrip.name]
                        tin = strip.frame_offset_start + strip.frame_start
                        tout = tin + strip.frame_final_duration
                        #print(newstrip.frame_start, strip.frame_start, tin, tout)
                        functions.triminout(clip, tin, tout)
                    except:
                        self.report({'ERROR_INVALID_INPUT'}, 'Error loading file')
                        return {'CANCELLED'}
    
                else:
                    try:
                        newstrip = bpy.ops.sequencer.movieclip_strip_add(\
                            replace_sel=True, overlap=False, clip=data.name)
                        newstrip = functions.act_strip(context)
                        newstrip.frame_start = strip.frame_start\
                            - strip.animation_offset_start
                        # need to declare the strip this way in order
                        # to get triminout() working
                        clip = bpy.context.scene.sequence_editor.sequences[\
                        newstrip.name]
                        # cannot change this atributes via scripts...
                        # but it works in the python console...
                        #clip.animation_offset_start = strip.animation.offset_start
                        #clip.animation_offset_end = strip.animation.offset_end
                        #clip.frame_final_duration = strip.frame_final_duration
                        tin = strip.frame_offset_start + strip.frame_start
                        tout = tin + strip.frame_final_duration
                        #print(newstrip.frame_start, strip.frame_start, tin, tout)
                        functions.triminout(clip, tin, tout)
                    except:
                        self.report({'ERROR_INVALID_INPUT'}, 'Error loading file')
                        return {'CANCELLED'}
    
            # show the new clip in a movie clip editor, if available.
            if strip.type == 'MOVIE' or 'IMAGE':
                for a in context.window.screen.areas:
                    if a.type == 'CLIP_EDITOR':
                        a.spaces[0].clip = data
    
            return {'FINISHED'}
            
            
    # RECURSIVE LOADER
    
    class Sequencer_Extra_RecursiveLoader(bpy.types.Operator):
        bl_idname = "sequencerextra.recursiveload"
        bl_label = "recursive load"
        bl_options = {'REGISTER', 'UNDO'}
        
        recursive = BoolProperty(
            name='recursive',
            description='Load in recursive folders',
            default=False)
            
        recursive_select_by_extension = BoolProperty(
            name='select by extension',
            description='Load only clips with selected extension',
            default=False)
            
        ext = EnumProperty(
            items=functions.movieextdict,
            name="extension",
            default="3")
            
        recursive_proxies = BoolProperty(
            name='use proxies',
            description='Load in recursive folders',
            default=False)
        build_25 = BoolProperty(name='default_build_25',
            description='build_25',
            default=True)
        build_50 = BoolProperty(name='default_build_50',
            description='build_50',
            default=False)
        build_75 = BoolProperty(name='default_build_75',
            description='build_75',
            default=False)
        build_100 = BoolProperty(name='default_build_100',
            description='build_100',
            default=False)
        proxy_suffix = StringProperty(
            name='proxy suffix',
            description='proxy filename suffix',
            default="-25")
        proxy_extension = StringProperty(
            name='proxy extension',
            description='proxy extension',
            default=".mkv")
        proxy_path = StringProperty(
            name='proxy path',
            description='proxy path',
            default="")
        
           
        
        @classmethod
        def poll(self, context):
            scn = context.scene
            if scn and scn.sequence_editor:
                return (scn.sequence_editor)
            else:
                return False
            
        def invoke(self, context, event):
            scn = context.scene
            try:
                self.build_25 = scn.default_build_25
                self.build_50 = scn.default_build_50
                self.build_75 = scn.default_build_75
                self.build_100 = scn.default_build_100
                self.proxy_suffix = scn.default_proxy_suffix
                self.proxy_extension = scn.default_proxy_extension
                self.proxy_path = scn.default_proxy_path
                self.recursive = scn.default_recursive
                self.recursive_select_by_extension = scn.default_recursive_select_by_extension
                self.recursive_proxies = scn.default_recursive_proxies
                self.ext = scn.default_ext 
            except AttributeError:
                initSceneProperties(context, scn)
                self.build_25 = scn.default_build_25
                self.build_50 = scn.default_build_50
                self.build_75 = scn.default_build_75
                self.build_100 = scn.default_build_100
                self.proxy_suffix = scn.default_proxy_suffix
                self.proxy_extension = scn.default_proxy_extension
                self.proxy_path = scn.default_proxy_path
                self.recursive = scn.default_recursive
                self.recursive_select_by_extension = scn.default_recursive_select_by_extension
                self.recursive_proxies = scn.default_recursive_proxies
                self.ext = scn.default_ext 
                    
            return context.window_manager.invoke_props_dialog(self)  
            
        def loader(self, context, filelist):
            scn = context.scene
            if filelist:
                for i in filelist:
                    functions.setpathinbrowser(i[0], i[1])
                    try:
                        if self.recursive_proxies:
                            bpy.ops.sequencerextra.placefromfilebrowserproxy(
                                proxy_suffix=self.proxy_suffix,
                                proxy_extension=self.proxy_extension,
                                proxy_path=self.proxy_path,
                                build_25=self.build_25,
                                build_50=self.build_50,
                                build_75=self.build_75,
                                build_100=self.build_100)
                        else:
                            bpy.ops.sequencerextra.placefromfilebrowser()
                    except:
                        print("Error loading file (recursive loader error): ", i[1])
                        functions.add_marker(context, i[1])
                        self.report({'ERROR_INVALID_INPUT'}, 'Error loading file ')
                        pass
    
    
        def execute(self, context):
            scn = context.scene
            #initSceneProperties(context, scn)
            if self.recursive == True:
                #recursive
                #print(functions.sortlist(functions.recursive(\
                #context, self.recursive_select_by_extension, self.ext)))
                self.loader(context, functions.sortlist(\
                functions.recursive(context, self.recursive_select_by_extension,\
                self.ext)))
            else:
                #non recursive
                #print(functions.sortlist(functions.onefolder(\
                #context, self.recursive_select_by_extension, self.ext)))
                self.loader(context, functions.sortlist(functions.onefolder(\
                context, self.recursive_select_by_extension, self.ext)))
            try:   
                scn.default_build_25 = self.build_25
                scn.default_build_50 = self.build_50
                scn.default_build_75 = self.build_75
                scn.default_build_100 = self.build_100 
                scn.default_proxy_suffix = self.proxy_suffix 
                scn.default_proxy_extension = self.proxy_extension 
                scn.default_proxy_path = self.proxy_path 
                scn.default_recursive = self.recursive 
                scn.default_recursive_select_by_extension = self.recursive_select_by_extension 
                scn.default_recursive_proxies = self.recursive_proxies
                scn.default_ext = self.ext 
            except AttributeError:
                initSceneProperties(context, scn)
                self.build_25 = scn.default_build_25
                self.build_50 = scn.default_build_50
                self.build_75 = scn.default_build_75
                self.build_100 = scn.default_build_100
                self.proxy_suffix = scn.default_proxy_suffix
                self.proxy_extension = scn.default_proxy_extension
                self.proxy_path = scn.default_proxy_path
                self.recursive = scn.default_recursive
                self.recursive_select_by_extension = scn.default_recursive_select_by_extension
                self.recursive_proxies = scn.default_recursive_proxies
                self.ext = scn.default_ext
                
            return {'FINISHED'}
    
    
    # READ EXIF DATA
    class Sequencer_Extra_ReadExifData(bpy.types.Operator):
        # load exifdata from strip to scene['metadata'] property
        bl_label = 'Read EXIF Data'
        bl_idname = 'sequencerextra.read_exif'
        bl_description = 'Load exifdata from strip to metadata property in scene'
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(self, context):
            strip = functions.act_strip(context)
            scn = context.scene
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                return (strip.type == 'IMAGE' or 'MOVIE')
            else:
                return False
    
        def execute(self, context):
            try:
                exiftool.ExifTool().start()
            except:
                self.report({'ERROR_INVALID_INPUT'},
                'exiftool not found in PATH')
                return {'CANCELLED'}
    
            def getexifdata(strip):
                def getlist(lista):
                    for root, dirs, files in os.walk(path):
                        for f in files:
                            if "." + f.rpartition(".")[2].lower() \
                                in functions.imb_ext_image:
                                lista.append(f)
                            #if "."+f.rpartition(".")[2] in imb_ext_movie:
                            #    lista.append(f)
                    strip.elements
                    lista.sort()
                    return lista
    
                def getexifvalues(lista):
                    metadata = []
                    with exiftool.ExifTool() as et:
                        try:
                            metadata = et.get_metadata_batch(lista)
                        except UnicodeDecodeError as Err:
                            print(Err)
                    return metadata
                if strip.type == "IMAGE":
                    path = bpy.path.abspath(strip.directory)
                if strip.type == "MOVIE":
                    path = bpy.path.abspath(strip.filepath.rpartition("/")[0])
                os.chdir(path)
                #get a list of files
                lista = []
                for i in strip.elements:
                    lista.append(i.filename)
                return getexifvalues(lista)
    
            sce = bpy.context.scene
            frame = sce.frame_current
            text = bpy.context.active_object
            strip = context.scene.sequence_editor.active_strip
            sce['metadata'] = getexifdata(strip)
            return {'FINISHED'}