VideoHelp Forum
+ Reply to Thread
Results 1 to 6 of 6
Thread
  1. Member
    Join Date
    Aug 2017
    Location
    Costa Rica
    Search Comp PM
    So there's this Python script in AvsPmod to batch create avs scripts from all the files inside a directory

    Code:
    import os
    
    # Get the directory containing source files
    dirname = avsp.GetDirectory()
    
    if dirname:
     # Generate each of the avisynth scripts
     for filename in os.listdir(dirname):
     fullname = os.path.join(dirname, filename)
     if os.path.isfile(fullname):
     # Get the extension-based template string
     srctxt = avsp.GetSourceString(fullname)
     # Create the script string
     scripttxt = srctxt + '\n' + 'Sharpen(1.0)\nInfo()'
     # Write the script text to a file
     f = open(fullname + '.avs', 'w')
     f.write(scripttxt)
     f.close()
    It works great but the issue is that it names the avs with the extension of the file e.g myvideo.mkv.avs so when you encode it and mux it the resulting file will be named myvideo.mkv.mkv. I want the script to omit the extension, I know it's doable and probably simple but I don't know anything about Python since I'm not a programmer.

    I encode hundreds of videos so removing the double extension is an annoying step that I want to remove from my workflow.
    Quote Quote  
  2. actually,after the line (which pulls script by video name):
    Code:
    srctxt = avsp.GetSourceString(fullname)
    you change that string to:
    Code:
    fullname = os.path.join(dirname, os.path.splitext(fullname)[0])
    Last edited by _Al_; 23rd Oct 2020 at 01:05.
    Quote Quote  
  3. Member
    Join Date
    Aug 2017
    Location
    Costa Rica
    Search Comp PM
    Originally Posted by _Al_ View Post
    actually,after the line (which pulls script by video name):
    Code:
    srctxt = avsp.GetSourceString(fullname)
    you change that string to:
    Code:
    fullname = os.path.join(dirname, os.path.splitext(fullname)[0])
    Nope doesn't work, I tried this one and the first example befere your edit and neither worked.

    Code:
    fullname = os.path.join(dirname, filename)
    fullname = os.path.join(dirname, os.path.splitext(fullname)[0])
    or
    Code:
    fullname = os.path.join(dirname, os.path.splitext(filename)[0])

    srctxt = avsp.GetSourceString(fullname) is to get source filter e.g DirectShowSource or LWLibavVideoSource that you configured in AvsPmod so it needs to be included as far as I know.
    Last edited by pandachinoman; 23rd Oct 2020 at 01:25.
    Quote Quote  
  4. this should work, maybe there is a problem with indentation in your example, this below should be alright :
    Code:
    import os
    # Get the directory containing source files
    dirname = avsp.GetDirectory()
    
    if dirname:
        # Generate each of the avisynth scripts
        for filename in os.listdir(dirname):
        fullname = os.path.join(dirname, filename)
        if os.path.isfile(fullname):
            # Get the extension-based template string
            srctxt = avsp.GetSourceString(fullname)
            # Create the script string
            scripttxt = srctxt + '\n' + 'Sharpen(1.0)\nInfo()'
            # Write the script text to a file
            f = open(os.path.splitext(fullname)[0] + '.avs', 'w')
            f.write(scripttxt)
            f.close()
    Quote Quote  
  5. Member
    Join Date
    Aug 2017
    Location
    Costa Rica
    Search Comp PM
    Originally Posted by _Al_ View Post
    this should work
    Yeah that one worked, though AvsPmod was still giving me an indentation error with your example so I fixed it:
    Code:
    import os
    # Get the directory containing source files
    dirname = avsp.GetDirectory()
    
    if dirname:
        # Generate each of the avisynth scripts
        for filename in os.listdir(dirname):
            fullname = os.path.join(dirname, filename)
            if os.path.isfile(fullname):
                # Get the extension-based template string
                srctxt = avsp.GetSourceString(fullname)
                # Create the script string
                scripttxt = srctxt + '\n' + 'Sharpen(1.0)\nInfo()'
                # Write the script text to a file
                f = open(os.path.join(dirname, os.path.splitext(fullname)[0]) + '.avs', 'w')
                f.write(scripttxt)
                f.close()
    Seems it's AvsPmod that one that is picky with the indentation. Thanks!
    Quote Quote  
  6. oh yes sorry for-in loop content should be indented as well.
    It's Python, how it works, not AvsPmod problem, Python uses indentation instead of parentheses for loops , if, for ... in ... blocks etc.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!