qmasingarbe / pymiere

Python for Premiere pro
GNU General Public License v3.0
353 stars 46 forks source link

Trouble bringing imported footage into sequence #31

Closed crydrk closed 3 years ago

crydrk commented 3 years ago

I'm trying to move imported images into a sequence, and am having problem with this path:

C:/Users/Corey/Desktop/testFolder/download21/0.jpg

When replacing the path in the example code with this new path, I get the error below. This same error happens whether I use the example code or my full code even further below. Any thoughts?

Traceback (most recent call last): File "C:/Users/Corey/Documents/OrganizedDocs/python/PremiereScripts/downloadFilesAndCreateSequence.py", line 17, in <module> project.activeSequence.videoTracks[0].insertClip(items[0], time_from_seconds(0)) File "C:\Python27\lib\site-packages\pymiere\objects\premiere_objects.py", line 3764, in insertClip self._check_type(clipProjectItem, ProjectItem, 'arg "clipProjectItem" of function "Track.insertClip"') File "C:\Python27\lib\site-packages\pymiere\core.py", line 209, in _check_type raise ValueError("{} shoud be of type {} but got '{}' (type {})".format(name, cls, obj, type(obj))) ValueError: arg "clipProjectItem" of function "Track.insertClip" shoud be of type <class 'pymiere.objects.premiere_objects.ProjectItem'> but got 'undefined' (type <type 'str'>)

My code below if it helps, but as I said the path itself is the problem, since I tried it manually with the example code. [edit] Apologies, a quote somewhere is messing up the code formatting here in github.

import pymiere
import requests
import os
from pymiere.wrappers import get_system_sequence_presets
from pymiere.wrappers import time_from_seconds

downloadListURLs = ["https://rarest.org/wp-content/uploads/2018/10/shadowless-first-edition-charizard.jpg", "https://i.pinimg.com/originals/b9/bc/64/b9bc643730761af9692ab9cf7a7af03a.jpg"]
downloadedFiles = []
downloadLocation = "C:/Users/Corey/Desktop/testFolder/"

isPremiereOpen = False

project = None

try:
    isOpen = pymiere.objects.app.isDocumentOpen()
    print "Connected successfully: %s" % isOpen
    isPremiereOpen = True
    project = pymiere.objects.app.project
except:
    print "Premiere, or the pymiere panel is not open."

if isPremiereOpen:
    folderCount = 1
    newFolderName = ""
    while True:
        if os.path.exists(downloadLocation + "download" + str(folderCount)):
            folderCount += 1
            continue
        else:
            newFolderName = downloadLocation + "download" + str(folderCount) + "/"
            os.makedirs(newFolderName)
            break
    count = 0
    for url in downloadListURLs:
        print "Downloading: %s" % url
        r = requests.get(url, allow_redirects=True)
        extension = url.split('.')[-1]
        print "extension: %s" % extension
        downloadedFilename = newFolderName + str(count) + "." + extension
        open(downloadedFilename, "wb").write(r.content)
        count += 1
        downloadedFiles.append(downloadedFilename)

    projPath = newFolderName + "compiledImages.pproj"
    pymiere.objects.app.newProject(projPath)

    sequence_preset_path = get_system_sequence_presets(category="HDV", resolution=None, preset_name="HDV 1080p25")
    sequence_name = "Image Sequence"
    pymiere.objects.qe.project.newSequence(sequence_name, sequence_preset_path)
    sequence = [s for s in pymiere.objects.app.project.sequences if s.name == sequence_name][0]
    pymiere.objects.app.project.openSequence(sequenceID=sequence.sequenceID)

    for image in downloadedFiles:
        success = project.importFiles([image], suppressUI = True, targetBin = project.getInsertionBin(), importAsNumberedStills=False)
        print image
        items = project.rootItem.findItemsMatchingMediaPath(image, ignoreSubclips=False)
        print items
        for i in items:
            print i
        sequence.videoTracks[0].insertClip(items[0], time_from_seconds(0))
qmasingarbe commented 3 years ago

Hi!

Your problem is coming from the formating of the path. On windows paths should be written using backslashes (\) instead of the usual slashes (/). If you use simple slashes in python some APIs won't properly work and it is the case for pymiere.

You can see an indepth explanation with some solutions here : https://medium.com/@ageitgey/python-3-quick-tip-the-easy-way-to-deal-with-file-paths-on-windows-mac-and-linux-11a072b58d5f I would personnaly use the "Old solution" from the above article

If you want a quick and (really) dirty fix, you can add this line after line 61 (after for image in downloadedFiles:) : image = os.path.normpath(image) It will convert your simpleslash path in a backslash windows compliant path.

Let me know if you have any other issues!

crydrk commented 3 years ago

Ah, thank you very much. Hoping this response doesn't reopen the ticket, but want to give thanks. ~Corey On Tuesday, March 23, 2021, 02:05:03 PM PDT, Quentin Masingarbe @.***> wrote:

Closed #31.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.