Hi,

On 05/20/2011 07:27 PM, anbazhagan p wrote:
> Hi,
>    I can see a lot of difference between your script and mine,

That was intentional ;). Thought, I'd give you a reason to read up and learn 
some more python and some good programming practices :).

> a few things i
> can't understand ,
>
>     1) you have used reporthook=lambda and xferred in try part , i can't
> understand those.
>

Well, ok, so the third parameter for urlib.urlretrieve() is reporthook. This 
parameter is supposed to be a function, which should accept 3 arguments. This 
function is called once at the time the connection is made and then again for 
every block that gets downloaded. The arguments passed to the function are 
number of block transferred so far, the block size in bytes and the total size 
of the file. Now, this reporthook parameter is optional, but I added it anyways 
to provide an indication if progress of the download. Furthermore, the reason 
it 
is a lambda instead of regular function is so that you can read up on what a 
lambda is :).


>     2) you have used exception but i  think there is no possiblity of getting
> error ( i didn't get error
>        for few videos i downloaded using your script ), can you explain why
> you have used exception
>

Well, again it was not strictly necessary, but I added it just to demonstrate 
how one might handle conditions like loss of network or lack of disk-space 
(which are both possible error conditions). That said, yeah, strictly speaking 
for such a small script, exception handling isn't really necessary.


>     3) can we change the download option byte to kb
>

Sure we can. Now that you know what the reporthook argument is, do you want to 
give it a this task a try ?

>     4) whenever i cancel the script using ctrl+c and again start the script
> it overwrites the previous
>         file also starts from first video (so only i had to use wget to
> download videos and continue), can we continue
>          the download
>

Hmm, yep, that's just me being lazy. Sure, we could check for existence of the 
downloaded files and also check the Content-length header with a http HEAD 
request to determine which files have been completely downloaded. I'll add this 
and push.

I hope you are having fun with all of this, if your intention was just to get a 
working script, your initial script was just fine.

cheers,
- steve

PS: maybe we should take this off-list since this isn't exactly on-topic here.

-- 
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
_______________________________________________
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc

Reply via email to