Python Forum
Python - Import file sequence into Media Pool - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python - Import file sequence into Media Pool (/thread-32308.html)



Python - Import file sequence into Media Pool - jensenni - Feb-02-2021

MacOS 10.13.2 | Python 3.6.8 | External API Application: DaVinci Resolve v15.3.1

Hi. I am working on some automation for DVR and got the following issue. I have a .txt file that contains python created links to video clips (with full path) for import into DaVinci Resolve. Like this:

clip_import.txt
'/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2002_C0127/FW_A01_2021-12-12_2002_C0127_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0129/FW_A01_2021-12-12_2003_C0129_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0130/FW_A01_2021-12-12_2003_C0130_000000.dng',
I am loading the .txt file as follows: (python 3.6.8)
# Read the search result clipList
with open("/Volumes/audio/TRANSCRIBE/SearchPhrases/" + searchPhrase + ".txt") as f:
    clipListRead = f.readlines()
    print('cliplistRead: ' + str(clipListRead))
Here is the OUTPUT:
["'/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2002_C0127/FW_A01_2021-12-12_2002_C0127_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0129/FW_A01_2021-12-12_2003_C0129_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0130/FW_A01_2021-12-12_2003_C0130_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0131/FW_A01_2021-12-12_2003_C0131_000000.dng', "]
I created a variable called clipListRead (see above) and plugged that into the (API) code below:
clips = resolve.GetMediaStorage().AddItemsToMediaPool(clipListRead)
But that does not work for some reason. My question is: Do I need to create an object or an array to make this work? Or is this a Davinci Resolve API issue? Any other tricks to this? The focus seems to be on what can be plugged into that function provided by the DVR API. AddItemsToMediaPool(??????). I couldn't find anything in the docs so far.
As a note, the same code below (path filled in by hand) works fine and is the correct format to import the two clips into resolve.
clips = resolve.GetMediaStorage().AddItemsToMediaPool('/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A0_C0135/FW_A0_C0135_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A0_C0135/FW_A0_C0135_000000.dng',)
Thank you!
MacOS 10.13.2. | DVR v15.3.1 | Python 3.6.8


RE: Python - Import file sequence into Media Pool - buran - Feb-02-2021

you read all the file paths as one big string inside a list. It looks all paths are on one line in the text file
not tested but something like
with open(f"/Volumes/audio/TRANSCRIBE/SearchPhrases/{searchPhrase}.txt") as f:
    clipListRead = [item.strip() for item in f.readline().split(',') if item.strip()]
    print('cliplistRead:', clipListRead)
    clips = resolve.GetMediaStorage().AddItemsToMediaPool(clipListRead)