Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Progress Finished Question
Hi all. First post, very new to Python and programming in general. K, now the question:
I have this script:
import sys, shutil, subprocess, ffmpy

def getDimensions(inputVideo):
    args = '-v error -select_streams v:0 -show_entries stream=width,height ' \
           '-of compact'
    call = ffmpy.FFprobe(r'E:\\App Back-Ups\FFprobe\ffprobe.exe', args, \
                         {inputVideo : None})
    return, subprocess.PIPE)

def getHeight(tupleIn):
    a = str(tupleIn[0])
    b = a.rfind('=')
    return a[b + 1:b + 4]

toMove = sys.argv[1]
output = getDimensions(toMove)
height = getHeight(output)
if height == '480':
    pathStr1 = 'E:\\My Movies\DVD Rips\\'
    pathStr2 = 'G:\\My Movies\DVD Rips'
    pathStr1 = 'E:\\My Movies\Blu-ray Rips\\'
    pathStr2 = 'G:\\My Movies\Blu-ray Rips'

lastSep = toMove.rfind('\\')
toCopy = pathStr1 + toMove[lastSep + 1:]
shutil.move(toMove, pathStr1)
shutil.copy(toCopy, pathStr2)
input('Press \'Enter\' to exit...')
It works fine, but sometimes the movie file sizes are quite large and they take a while to copy. I'm wondering how to add a progress bar or percent (preferable) to the runtime. I'm stuck figuring out how because shutil pauses while it's processing the move/copy and does not pick up the next line of script until after it has finished the copy. So, is it possible to add a simple percentage copied output to this script? Just so I know how much is done and how much more is left.
Think about what you're asking. How can you know % done if you have no communication from the program that is using the time?
I guess you can't? I know that shutil has no function that returns progress complete. I was thinking I could compare the size of the file with how much has been copied/moved as it happens. But, the script pauses at the copy/move functions until the file operation is done.
Well, you can run shutil.copy/move in a separate thread and compare the file size against the destination file and do some math to get the percentage or some other measure. You can use this and pass it to the tqdm module for example.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
Sweet! Thanks, @wavic. I'm about as noob as they come so know nothing about threads, but Google and the official docs do. I'll look into this further.
Consider that it will takes some time to check the size of copied file and compare it during to copying process. So the value will have a small difference.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
So, it won't be terribly accurate? Average file size is about 6GB.
It will be fine.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
Great. I must confess, threading makes my brain hurt. It's a lot for a greenhorn noob. Oh well. Thanks again, @wavic.
I am not very familiar with threading because I didn't use it.
The simplest approach:

import thread

source = '/path/big_file.BIG'
dest_path = '/path'
thread.start_new_thread(shutil.copy, (source, dest_path))
You provide the callable and the arguments to the start_new_thread method and that's all.
But this won't tell you if the copping is finished.

Better see this. It's basically almost the same. On top
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to stop Xmodem after bin file transfer was finished shaya2103 0 298 Nov-27-2019, 04:33 PM
Last Post: shaya2103
  Process finished with exit code -107374819 (0xC0000375) mrazko 2 5,013 Apr-05-2019, 12:46 PM
Last Post: mrazko
  Fabric - Run method is not being finished mglowinski93 3 983 Dec-29-2018, 10:45 AM
Last Post: mglowinski93
  how to progress with py jakegold98 1 980 Dec-05-2017, 02:58 AM
Last Post: micseydel

Forum Jump:

Users browsing this thread: 1 Guest(s)