Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Progress Finished Question
#1
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 call.run(None, 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'
else:
    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...')
sys.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.
Quote
#2
Think about what you're asking. How can you know % done if you have no communication from the program that is using the time?
Quote
#3
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.
Quote
#4
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."
https://freedns.afraid.org
Quote
#5
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.
Quote
#6
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."
https://freedns.afraid.org
Quote
#7
So, it won't be terribly accurate? Average file size is about 6GB.
Quote
#8
It will be fine.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#9
Great. I must confess, threading makes my brain hurt. It's a lot for a greenhorn noob. Oh well. Thanks again, @wavic.
Quote
#10
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."
https://freedns.afraid.org
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to stop Xmodem after bin file transfer was finished shaya2103 0 63 Nov-27-2019, 04:33 PM
Last Post: shaya2103
  Process finished with exit code -107374819 (0xC0000375) mrazko 2 550 Apr-05-2019, 12:46 PM
Last Post: mrazko
  Fabric - Run method is not being finished mglowinski93 3 586 Dec-29-2018, 10:45 AM
Last Post: mglowinski93

Forum Jump:


Users browsing this thread: 1 Guest(s)