Magdy
Magz

Magz

Python for a video editor. Working smarter :D

Python for a video editor. Working smarter :D

Magdy's photo
Magdy
·Mar 16, 2022·

3 min read

Subscribe to my newsletter and never miss my upcoming articles

It can get very tedious being organised when editing videos as a video editor. Every time I start a new video, I have to copy and paste an old file, rename it, then delete the contents in order to keep my folder structure consistent. Or, I create a new folder with the new name. I then create new folders one by one. Like, Documents, footage, interviews, pictures, exports, you got the point!

As a Python coder the first thing that came to mind was this doesn't make sense, this could definitely be automated. That's when I decided to code a simple program that does it all for me.

Here is the geeky bit, To make it super simple, I used the os library in Python. The concept is, I need to be prompted to type or copy and paste the name of the the new video I'm working on, then the code does the rest.

import os

folderName = input("Type folder name: \n")

output

Type folder name:

Once I type the new folder name, the following code runs. I call one function createProject(). It creates a folder then prints a success message to confirm. That's it. In this example, I create a folder named new new new and my presets are sub-folders including documents.

os.mkdir(f"{folderName}/{subfolder1}")
print( "++ " + folderName + "/" + subfolder1 + ' is created!')

output

++ new new new/Documents is created!

pic.png

This works fine but add and remove subfolders is such a faff. Every time I see repeated code I get the feeling that it could be shorter. A day later, I decided to make the code more concise by using a list and a "for loop". This way all I need to do to add, amend or remove folders is to change the name, add or remove items from the list. That's it, no more changes are required in the main function.

# change Subfolder names to the desired subfolders you want. 

myFolders = ["subfolder1", "subfolder2", "subfolder3", "subfolder4", "subfolder5", "subfolder6"]

The main function remains the same all the time, which is more efficient.

def createProject():
    os.mkdir(folderName)
    print( "++ " + folderName + ' is created!')

    for item in myFolders:
        os.mkdir(f"{folderName}/{item}")
        print( "++ " + folderName + "/" + item + ' is created!')

This makes the whole code for this simple program that saves me time and hassle tiny.

import os

folderName = input("Type folder name: \n")                                

myFolders = ["subfolder1", "subfolder2", "subfolder3", "subfolder4", "subfolder5", "subfolder6"]

def createProject():
    os.mkdir(folderName)
    print( "++ " + folderName + ' is created!')
    for item in myFolders:
        os.mkdir(f"{folderName}/{item}")
        print( "++ " + folderName + "/" + item + ' is created!')   

createProject()
print("Mission Accomplished")

It has been amazing to automate a boring task like this one using a couple of lines of Python.

What is also great is that his code is very customisable. I could add more sub-sub-folders. For example, new new new/Pictures/Raw and new new new/Pictures/compressed.

You can find the code and how to install it and run it on my github

 
Share this