# EDL export script, help needed!

**URL:** <https://blenderartists.org/t/edl-export-script-help-needed/686526>\
**Category:** Python Support\
**Created:** [March 22, 2017, 4:28am UTC](https://blenderartists.org/t/edl-export-script-help-needed/686526 "2017-03-22T04:28:06Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![tin2tin](https://blenderartists.org/user_avatar/blenderartists.org/tin2tin/32/1084923_2.png) [@tin2tin](https://blenderartists.org/u/tin2tin)\
**Post date:** [March 24, 2017, 6:54am UTC](https://blenderartists.org/t/edl-export-script-help-needed/686526/5 "2017-03-24T06:54:28Z")

</div>

Here’s how far I am atm. Correct the export path in the last line of the script to test it. I haven’t found out how to pull information on crossfades and fades. Any help much appreciated.

```auto
import bpy
import os

"""
export_edl.py -- Export of Edit Description List ("EDL") files.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
"""

# TimeCode class by Campbell Barton
class TimeCode:
    """
    Simple timecode class
    also supports conversion from other time strings used by EDL
    """
    __slots__ = (
        "fps",
        "hours",
        "minutes",
        "seconds",
        "frame",
    )

    def __init__ (self, data, fps):
        self.fps = fps
        if type(data) == str:
            self.from_string(data)
            frame = self.as_frame()
            self.from_frame(frame)
        else:
            self.from_frame(data)

    def from_string(self, text):
        # hh:mm:ss:ff
        # No dropframe support yet

        if text.lower().endswith("mps"): # 5.2mps
            return self.from_frame(int(float(text[:-3]) * self.fps))
        elif text.lower().endswith("s"): # 5.2s
            return self.from_frame(int(float(text[:-1]) * self.fps))
        elif text.isdigit(): # 1234
            return self.from_frame(int(text))
        elif ":" in text: # hh:mm:ss:ff
            text = text.replace(";", ":").replace(",", ":").replace(".", ":")
            text = text.split(":")

            self.hours = int(text[0])
            self.minutes = int(text[1])
            self.seconds = int(text[2])
            self.frame = int(text[3])
            return self
        else:
            print("ERROR: could not convert this into timecode %r" % text)
            return self

    def from_frame(self, frame):

        if frame &lt; 0:
            frame = -frame
            neg = True
        else:
            neg = False

        fpm = 60 * self.fps
        fph = 60 * fpm

        if frame &lt; fph:
            self.hours = 0
        else:
            self.hours = int(frame / fph)
            frame = frame % fph

        if frame &lt; fpm:
            self.minutes = 0
        else:
            self.minutes = int(frame / fpm)
            frame = frame % fpm

        if frame &lt; self.fps:
            self.seconds = 0
        else:
            self.seconds = int(frame / self.fps)
            frame = frame % self.fps

        self.frame = frame

        if neg:
            self.frame = -self.frame
            self.seconds = -self.seconds
            self.minutes = -self.minutes
            self.hours = -self.hours

        return self

    def as_frame(self):
        abs_frame = self.frame
        abs_frame += self.seconds * self.fps
        abs_frame += self.minutes * 60 * self.fps
        abs_frame += self.hours * 60 * 60 * self.fps

        return abs_frame

    def as_string(self):
        self.from_frame(int(self))
        return "%.2d:%.2d:%.2d:%.2d" % (self.hours, self.minutes, self.seconds, self.frame)

    def __repr__ (self):
        return self.as_string()

    # Numeric stuff, may as well have this
    def __neg__ (self):
        return TimeCode(-int(self), self.fps)

    def __int__ (self):
        return self.as_frame()

    def __sub__ (self, other):
        return TimeCode(int(self) - int(other), self.fps)

    def __add__ (self, other):
        return TimeCode(int(self) + int(other), self.fps)

    def __mul__ (self, other):
        return TimeCode(int(self) * int(other), self.fps)

    def __div__ (self, other):
        return TimeCode(int(self) // int(other), self.fps)

    def __abs__ (self):
        return TimeCode(abs(int(self)), self.fps)

    def __iadd__ (self, other):
        return self.from_frame(int(self) + int(other))

    def __imul__ (self, other):
        return self.from_frame(int(self) * int(other))

    def __idiv__ (self, other):
        return self.from_frame(int(self) // int(other))
# end timecode

#EDLBlock Copyright (C) 2015 William R. Zwicky &lt;wrzwicky@pobox.com&gt;
class EDLBlock:
    def __init__ (self):
        self.id = 0
        """Num, 3 digits, officially 001-999. Non-num makes row a comment."""
        self.reel = None
        """Reference to media file or tape.
           Officially: 4-digit num, optional B; or BL for black,
           or AX for aux source.
           Unofficially: any string."""
        self.channels = None
        """A=audio1,V=video1,B=A+V,A2=audio2,A2/V=A2+V,AA=A1+A2,AA/V=A1+A2+V"""
        self.transition = None
        """C=cut,
           D=dissolve,
           Wxxx=wipe type xxx,
           KB=key background,
           K=key foreground,
           KO=key foreground mask"""
        self.transDur = None
        """3-digit duration, in frames, or lone F"""
        self.srcIn = None
        """timecode (hh:mm:ss:ff)"""
        self.srcOut = None
        """timecode (hh:mm:ss:ff)"""
        self.recIn = None
        """timecode (hh:mm:ss:ff)"""
        self.recOut = None
        """timecode (hh:mm:ss:ff). Either out-time or duration.
           Ignored on read; clip length is srcOut-srcIn."""
        self.file = None
        """filename and extention, but no path"""          

class EDL(list):
    def __init__ (self):
        self.title = None
        self.dropframe = False
        self.reels = {}
        #self.edits = []

    def load(filename):
        pass

    def savePremiere(self):
        # CMX 3600:
        # 111^^222^^3333^^4444^555^666666666666^777777777777^888888888888^999999999999^
        # Old Lightworks converter:
        # 003 E00706EU V D 030 00:00:26:29 00:00:32:10 00:00:01:02 00:00:07:13
        # 111^^22222222^3333^4444^555^^66666666666^77777777777^88888888888^99999999999
        # Export from Premiere:
        # 003 AX AA C 00:00:00:10 00:02:03:24 00:00:53:25 00:02:57:09
        # * FROM CLIP NAME: Ep6_Sc2 - Elliot tries again with Tiff.mp4
        s=""
        if not not self.title:
            s="TITLE: " + self.title+"
"
        if self.dropframe:
            s += "FCM: DROP FRAME"+"
"
        else:
            s += "FCM: NON DROP FRAME"+"

"

        for block in self:
            s += "%03d %-8s %-4s %-4s %03s %-11s %-11s %-11s %-11s" \
                % (block.id, block.reel, block.channels,
                   block.transition, block.transDur,
                   block.srcIn, block.srcOut, block.recIn, block.recOut)+"
* FROM CLIP NAME: " + block.file + "
"
        print(s)
        return(s)

context = bpy.context
scene = context.scene
vse = scene.sequence_editor

edl_fps=scene.render.fps
id_count=1

e = EDL()
e.title = "Test script"
e.dropframe=False

for strip in vse.sequences_all:
# # Edit Strip Panel
# #print("-" * 72)
# print(strip.name)
# print(strip.type)
# # extend for other strip types.
# if strip.type in ['MOVIE']:
# print(strip.filepath)
# elif strip.type in ['SOUND']:
# print(strip.sound.filepath)
# print(strip.channel)
# print(strip.frame_start)
# print(strip.frame_final_duration)
# # Trim Duration (soft)
# print(strip.frame_offset_start)
# print(strip.frame_offset_end)
    
    b = EDLBlock()
    b.id = id_count
    id_count=id_count+1
    if strip.type in ['MOVIE']:
        reelname = bpy.path.basename(strip.filepath)
        b.file=reelname
        reelname = os.path.splitext(reelname)[0]        
        b.reel = ((reelname+" ")[0:8])                
        b.channels = "V "
    elif strip.type in ['SOUND']:
        reelname = bpy.path.basename(strip.sound.filepath)
        b.file=reelname
        reelname = os.path.splitext(reelname)[0]        
        b.reel = ((reelname+" ")[0:8])        
        b.channels = "A " 
    #elif strip.type in ['CROSS']:            
        
    b.transition = "C "
    b.transDur = " "
    b.srcIn = TimeCode(strip.frame_offset_start,edl_fps)
    b.srcOut = TimeCode(strip.frame_offset_start+strip.frame_final_duration,edl_fps)
    b.recIn = TimeCode(strip.frame_final_start,edl_fps)
    b.recOut = TimeCode(strip.frame_final_end,edl_fps)                
    e.append(b)

#write to a file
file_handle = open("C:/Users/User/Desktop/mytest.edl","w")
file_handle.write(e.savePremiere())
file_handle.close()

```

---

_[View the full topic](https://blenderartists.org/t/edl-export-script-help-needed/686526)._
