Python Forum
Python - Import file sequence into Media Pool
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python - Import file sequence into Media Pool
#1
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
Reply
#2
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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pool mysql error - not catch by try\except? korenron 1 512 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  Adding variable to Python code - media sentiment analysis Marietje 3 962 May-25-2021, 05:15 PM
Last Post: jefsummers
Smile Import error with local file colt 1 749 Nov-08-2020, 07:56 AM
Last Post: Gribouillis
  Open windows media player minimised TamP 1 866 Aug-02-2020, 08:40 PM
Last Post: Larz60+
  python multiprocessing import Pool, cpu_count: causes forever loop | help to remove Hassibayub 0 909 Jun-18-2020, 05:27 PM
Last Post: Hassibayub
  Code import .CSV file to MySQL table rtakle 4 1,284 Apr-30-2020, 03:16 PM
Last Post: anbu23
  Process (pool,map) strange behaviour maverick76 1 913 Feb-03-2020, 02:43 PM
Last Post: maverick76
  Regarding import library in two different program file Rohit 3 1,117 Jan-22-2020, 07:14 AM
Last Post: buran
  Please suggest python code to format DNA sequence FASTA file rajamdade 4 1,727 Oct-24-2019, 04:36 AM
Last Post: rajamdade
  How to use pool.map effectively? AlekseyPython 10 3,166 Oct-11-2019, 05:50 AM
Last Post: AlekseyPython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020