News:

--

Main Menu

How_To_Deal_With_Nested_Folders ?

Started by pulsarstar, July 11, 2021, 10:29:37 AM

Previous topic - Next topic

pulsarstar

Hi Guys,
I could do with some help with my script please.
I am not very good with coding!
My script will accept a video file that is inside a container folder.
But if the container folder is nested, I get an Error returned.
Example: This works "G:/Folder1\video.mkv
This Does not work ":G/Folder1\Folder2\video.mkv
Oops
No mkv files found in "G:/Folder1"
As you would expect.
   Could someone please amend my script to show me how
I can deal with nested folders.
Thanks for your help.

*********************
** Start of Script **
*********************

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,out):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    adm.videoCodec("Copy")
    if adm.audioTracksCount() > 0:
        adm.audioClearTracks()
        adm.audioAddTrack(0)
        adm.audioCodec(0, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
        adm.audioSetDrc(0, 0)
        adm.audioSetShift(0, 0, 0)
        adm.audioSetNormalize2(0, 2, 120, -30)
    adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")

    filename = (splitext(filein))[0]
    filename += ".mkv"
    filename = basename(filename)
    return adm.save(out + sep + filename)
#
# Main
#
# -------- select extension --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mx = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mx):
    menuExt.addItem(extensions[entry])
dia = DialogFactory("Filter directory content")
dia.addControl(menuExt)
if not dia.show():
    return

idx = menuExt.index

if idx < 0 or idx >= mx:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idx]

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Oops", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Oops", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")



eumagga0x2a

Quote from: pulsarstar on July 11, 2021, 10:29:37 AMMy script

It is basically from https://avidemux.org/smif/index.php?msg=91175 with adjusted audoCodec() and audioSetNormalize2() arguments.

Quote from: pulsarstar on July 11, 2021, 10:29:37 AMBut if the container folder is nested, I get an Error returned.

If I am not mistaken, recursion is not possible with the internal tinyPy scripting. You would need to use a mix of Windows-specific cmd.exe or PowerShell scripting and the Avidemux-internal tinyPy one. Users dosdan and butterw could provide valuable help on this topic.

pulsarstar

Thank you for your help eumagga0x2a.
Sounds like I am getting out of my depths in the coding department !