Page 1 of 1

Python - Import clips with .AddItemsToMediaPool

PostPosted: Tue Feb 02, 2021 11:59 am
by jensenni
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 clips (with the full path) for import into resolve. Like this:

clip_import.txt
Code: Select all
'/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)
Code: Select all
# 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:
Code: Select all
["'/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 code below:
Code: Select all
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 DVR 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.
Code: Select all
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 clips with .AddItemsToMediaPool

PostPosted: Tue Feb 02, 2021 3:11 pm
by pperquin
hi,

have you try something like :

for oneClip in clipListRead:
clips = resolve.GetMediaStorage().AddItemsToMediaPool(clipListRead)

Re: Python - Import clips with .AddItemsToMediaPool

PostPosted: Tue Feb 02, 2021 4:01 pm
by jensenni
Hi, Philippe. I just tried that. Unfortunately, it didn't work. But no error messages either :) Thank you for looking into this though! -- It might be possible that the new API (Davinci Resolve) has some limitations - but there is not enough documentation available to tell for sure. It's a real petty because all other parts of the script are working really well -- I just can't get over that last hurdle...

Re: Python - Import clips with .AddItemsToMediaPool

PostPosted: Tue Feb 02, 2021 4:44 pm
by pperquin
hi,

i make an error with the copy paste the good one is :

for oneClip in clipListRead:
clips = resolve.GetMediaStorage().AddItemsToMediaPool(oneClip)

Re: Python - Import clips with .AddItemsToMediaPool

PostPosted: Tue Feb 02, 2021 5:29 pm
by Shrinivas Ramani
Jens
In your code, printing this gives you a list with one line.
Code: Select all
str(clipListRead)

   ==> list with one str

["<--start of str     '/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',       end of str-->"]
You want to either format your file in a way that produces the proper list (e.g separate lines) - or split in python using comma.

Re: Python - Import clips with .AddItemsToMediaPool

PostPosted: Tue Feb 02, 2021 8:06 pm
by jensenni
Philippe, you did it!

I'll mark this as solved, even though it's still not reading in. But the path is now absolutely correct and this might be an issue with the API. I am not sure what Blackmagic needs to plug-in correctly (array, object, etc). Not sure.

Great job, Philippe!

Re: Python - Import clips with .AddItemsToMediaPool

PostPosted: Tue Feb 02, 2021 8:25 pm
by jensenni
Shrinivas Ramani wrote:Jens
In your code, printing this gives you a list with one line.
Code: Select all
str(clipListRead)

   ==> list with one str

["<--start of str     '/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',       end of str-->"]
You want to either format your file in a way that produces the proper list (e.g separate lines) - or split in python using comma.



Hi Shrinivas, the path is now correct. If I copy-paste the output path list directly into AddItemsToMediaPool(xxxx) it works. However, plugging in anything else does not work - please see below.
Is there a trick to this :)?

Code: Select all
# Import clips from searchPhrase result
# TODO: clipList var is not working yet. Seems a API issue in DVRv15? We'll try DVRv16.
for oneClip in clipListRead:
    clips = resolve.GetMediaStorage().AddItemsToMediaPool(oneClip)  # <-- clipList goes here
    print(end='\n')  # <-- command line spacer:)
    print("oneClip: " + str(oneClip))


best regards
Jens

macOS 10.13.2 | Python 3.6.8 | DVR 15.3.1

Re: Python - Import clips with .AddItemsToMediaPool

PostPosted: Tue Feb 02, 2021 9:49 pm
by pperquin
hi jensenni,

What are you trying to make when you say 'even though it's still not reading in' ?

Can you explain your scrip ?

regards,

Re: Python - Import clips with .AddItemsToMediaPool

PostPosted: Wed Feb 03, 2021 11:16 am
by jensenni
pperquin wrote:hi jensenni,

What are you trying to make when you say 'even though it's still not reading in' ?

Can you explain your scrip ?

regards,


What I meant is that I believe it has probably something to do with the API. Your ideas from yesterday worked but the function 'AddItemsToMediaPool(oneClip)' seems to be the issue -- it's just really hard to tell as there isn't any useful documentation about what we are supposed to plugin here. I checked the output again and it's now the correct path but for some reason, it's not working within that function... as for the idea itself, I am building a PhraseFind option for DavinciResolve for a film we are doing currently -- we have over 1200 film scenes and all of them are searchable for phrases spoken by actors -- super cool :) - once it's done I want to share that with the DavinciResolve community as a plugin -- well, that's the idea. I am happy to share the source code with you if you're interested...

Re: Python - Import clips with .AddItemsToMediaPool

PostPosted: Wed Feb 03, 2021 12:10 pm
by pperquin
hi,

you can also have a look to https://www.steakunderwater.com/wesuckl ... m.php?f=35 that is a good forum about programming.

regards,

Re: Python - Import clips with .AddItemsToMediaPool

PostPosted: Thu Feb 11, 2021 12:22 am
by jensenni
Thanks for the link. The site is great!