在下载前使用下载链接检查视频文件大小的代码? [编辑]

时间:2018-06-30 13:54:54

标签: python python-3.x sys python-webbrowser

我正在读《用python自动化无聊的东西》这本书,在那里我读到了有关webbrowser模块的信息。我试图制作一个程序,可以从网络上下载给定数量的视频。但是,由于Chrome浏览器同时启动了多个下载,因此我想知道是否有一些代码可以代替下面列出的代码中的注释。

# This is a program to download a list of episodes

import webbrowser, sys

start = int(sys.argv[1])  # denotes the starting episode number    
stop = int(sys.argv[2])  # denotes the final episode number

while start <= stop:
    link = #(first half of link) + str(start) + #(final half of link)
    #here goes the code that checks the size of the video to be downloaded
    webbrowser.open(link)
    while True:
        # here goes an if statement that keeps checking the size of the downloaded file
            start += 1
            break
        else:
            continue

编辑1:

我已经推断出原始问题的一部分,该问题反复检查了下载的大小。但是,实际上在我不知道的情况下仍然可以让我知道文件大小的代码

# This is a program to download a list of episodes

import webbrowser, sys, os

start = int(sys.argv[1])  # denotes the starting episode number    
stop = int(sys.argv[2])  # denotes the final episode number

while start <= stop:
    link = #(first half of link) + str(start) + #(final half of link)
    file = #name under which video will be downloaded
    os.chdir(r'C:\Users\OWNER\Downloads')
    #here goes the code that checks the size of the video to be downloaded
    webbrowser.open(link)
    while True:
        if os.path.getsize(file) >= # size of file to be downloaded:
            start += 1
            break
        else:
            continue    

0 个答案:

没有答案