コード例 #1
0
def download_fail_file():
    global download_fail_list
    global downloaded_clip
    if len(download_fail_list) > 0:
        start_download_in_pool(try_again_download, download_fail_list)
        if len(download_fail_list) == 0:
            share.log_content = {
                'time': share.get_time(),
                'link': link,
                'status': '下载成功'
            }
            t = threading.Thread(target=share.write,
                                 args=(share.log_content, ))
            # 设置守护线程,进程退出不用等待子线程完成
            t.setDaemon(True)
            t.start()
            if merge_file(video_path):
                if save_source_file is False:
                    # 删除文件夹
                    shutil.rmtree(video_path)
                share.m3.alert("下载完成")
                share.m3.show_info("下载完成")
                share.set_progress(0)
                share.m3.str.set('')
                share.m3.clear_alert()
                downloaded_clip = 0
                share.running = False
            else:
                share.m3.alert("视频文件合并失败,请查看消息列表")
        else:
            share.m3.alert("有部分文件没有下载完成,请点击重试!")
            share.m3.show_info("有部分文件没有下载完成,请点击重试!")
    else:
        share.m3.show_info("还没有下载失败的文件噢!")
コード例 #2
0
def download_fail_file1():
    global download_fail_list1
    global downloaded_clip
    if len(download_fail_list1) > 0:
        start_download_in_pool1(try_again_download, download_fail_list1)
        if len(download_fail_list1) == 0:
            share.log_content = {
                'time': share.get_time(),
                'link': url_path,
                'status': '下载成功'
            }
            t = threading.Thread(target=share.write,
                                 args=(share.log_content, ))
            # 设置守护线程,进程退出不用等待子线程完成
            t.setDaemon(True)
            t.start()
            merge_file1(video_path)
            # 删除下载的视频片段
            shutil.rmtree(video_path)
            share.m3.alert("下载完成")
            share.set_progress(0)
            share.m3.str.set('')
            share.m3.clear_alert()
            share.running = False
            downloaded_clip = 0
        else:
            share.m3.alert("有部分文件没有下载完成,请点击重试!")
            share.m3.show_info("有部分文件没有下载完成,请点击重试!")
    else:
        share.m3.show_info("还没有下载失败的文件噢!")
コード例 #3
0
def start_one(content_size, video_name, m3u8_href):
    global content_length
    global download_fail_list1
    global start
    global end
    global video_path
    global url_path
    global downloaded_clip
    content_length = content_size
    video_name = share.check_video_name(video_name)
    video_name = setting_gui.path + "/" + video_name
    video_path = video_name
    url_path = m3u8_href
    link = share.m3.button_url.get().rstrip()
    if not os.path.exists(video_name):
        os.makedirs(video_name)
    # 对文件进行划分
    file_divide(content_size)
    # 进行参数的拼接
    params = get_download_params1(video_name)
    share.m3.alert('[文件大小]:%0.2f MB' % (content_size / 1024 / 1024))
    # 启动线程池进行下载
    start_download_in_pool1(download_to_file1, params)
    # while len(download_fail_list1)!=0:
    #     download_fail_file1()
    # 用来检查文件片段是否都下载完成
    if downloaded_clip == len(start):
        share.log_content = {
            'time': share.get_time(),
            'link': url_path,
            'status': '下载成功'
        }
        t = threading.Thread(target=share.write, args=(share.log_content, ))
        # 设置守护线程,进程退出不用等待子线程完成
        t.setDaemon(True)
        t.start()
        # 合并视频
        merge_file1(video_name)
        # 删除下载的视频片段
        shutil.rmtree(video_name)

        share.m3.alert("下载完成")
        share.m3.show_info("下载完成")
        share.set_progress(0)
        share.m3.str.set('')
        share.m3.clear_alert()
        download_fail_list1 = []
        downloaded_clip = 0
        share.running = False
    else:
        share.m3.alert("有部分文件没有下载完成,请点击重试!")
        share.m3.show_info("有部分文件没有下载完成,请点击重试!")
    # 清空下载失败视频列表
    start = [
        0,
    ]
    end = []
コード例 #4
0
def download_to_file(url, file_name):
    global download_fail_list
    global url_list
    global downloaded_clip
    response = dm.easy_download(url=url,
                                stream=False,
                                header=requests_header.get_user_agent())
    if response is None:
        download_fail_list.append(([url, file_name], None))  # 将下载失败的视频连接加入列表
        return
    else:
        with open(file_name, 'wb') as file:
            file.write(response.content)
            downloaded_clip += 1
            m = (downloaded_clip / len(url_list)) * 100
            share.set_progress(m)  # 设置进度条
            share.m3.str.set('%.2f%%' % m)
コード例 #5
0
def try_again_download(url, file_name):
    global download_fail_list
    global downloaded_clip
    share.m3.alert("正在尝试重新下载%s" % file_name)
    response = dm.easy_download(url=url,
                                stream=False,
                                header=requests_header.get_user_agent(),
                                timeout=(18, 30))
    if response is None:
        # share.m3.alert("%s下载失败,请手动下载:\n%s" % (file_name, url))
        return
    else:
        download_fail_list.remove(([url, file_name], None))
        with open(file_name, 'wb') as file:
            file.write(response.content)
            downloaded_clip += 1
            m = (downloaded_clip / len(url_list)) * 100
            share.set_progress(m)
            share.m3.str.set('%.2f%%' % m)
コード例 #6
0
def download_to_file1(start1, end, file_name):
    global download_fail_list1
    global downloaded_clip
    response = dm.easy_download(
        url=url_path,
        stream=True,
        # proxies=proxy_ip_pool.get_proxy(),
        header=requests_header.get_user_agent2(start1, end))
    if response is None:
        download_fail_list1.append(([start1, end,
                                     file_name], None))  # 将下载失败的视频连接加入列表
        return
    else:

        with open(file_name, 'wb') as file:
            file.write(response.content)
            downloaded_clip += 1
            m = (downloaded_clip / len(start)) * 100
            share.set_progress(m)  # 设置进度条
            share.m3.str.set('%.2f%%' % m)
コード例 #7
0
def try_again_download(start, end, file_name):
    global download_fail_list1
    global downloaded_clip
    share.m3.alert("正在尝试重新下载%s" % file_name)
    response = dm.easy_download(
        url=url_path,
        stream=True,
        # proxies=proxy_ip_pool.get_proxy(),
        header=requests_header.get_user_agent2(start, end),
        timeout=(18, 30))
    if response is None:
        # share.m3.alert("%s下载失败,请手动下载:\n%s" % (file_name))
        return
    else:
        download_fail_list1.remove(([start, end, file_name], None))
        with open(file_name, 'wb') as file:
            file.write(response.content)
            downloaded_clip += 1
            m = (downloaded_clip / len(start)) * 100
            share.set_progress(m)  # 设置进度条
            share.m3.str.set('%.2f%%' % m)
コード例 #8
0
def start_list1(m3u8_href, video_name):
    global link
    global key
    global download_fail_list
    global url_list
    global url_path
    global url_host
    global video_path
    global downloaded_clip
    # 清空消息框中的消息
    share.m3.clear_alert()
    # 进度条归零
    share.set_progress(0)
    link = m3u8_href
    # 格式化文件名
    video_name = share.check_video_name(video_name)
    # 任务开始标志,防止重复开启下载任务
    # 获取所有ts视频下载地址
    url_list = get_ts_add(m3u8_href)
    if len(url_list) == 0:
        share.m3.alert("获取地址失败!")
        share.log_content = {
            'time': share.get_time(),
            'link': link,
            'status': '下载失败'
        }
        t = threading.Thread(target=share.write, args=(share.log_content, ))
        # 设置守护线程,进程退出不用等待子线程完成
        t.setDaemon(True)
        t.start()
        return False
    video_name = setting_gui.path + "/" + video_name
    video_path = video_name
    if not os.path.exists(video_name):
        os.makedirs(video_name)
    share.m3.alert("总计%s个视频" % str(len(url_list)))
    # 拼接正确的下载地址开始下载
    if test_download_url(url_host + url_list[0]):
        # 获取.ts文件的链接和命名
        params = get_download_params(head=url_host, dir_name=video_name)
        # 获得参数后线程池开启线程下载视频
        start_download_in_pool(download_to_file, params)
    elif test_download_url(url_path + url_list[0]):
        params = get_download_params(head=url_path, dir_name=video_name)
        # 线程池开启线程下载视频
        start_download_in_pool(download_to_file, params)
    elif test_download_url(url_list[0]):
        params = get_download_params('', dir_name=video_name)
        # 线程池开启线程下载视频
        start_download_in_pool(download_to_file, params)
    elif test_download_url(url_list[0]):
        params = get_download_params('', dir_name=video_name)
        # 线程池开启线程下载视频
        start_download_in_pool(download_to_file, params)
    elif test_download_url(url_list[0]):
        params = get_download_params(head='', dir_name=video_name)
        # 线程池开启线程下载视频
        start_download_in_pool(download_to_file, params)
    else:
        share.m3.alert("地址连接失败!")
        share.log_content = {
            'time': share.get_time(),
            'link': link,
            'status': '下载失败'
        }
        t = threading.Thread(target=share.write, args=(share.log_content, ))
        # 设置守护线程,进程退出不用等待子线程完成
        t.setDaemon(True)
        t.start()
        return False
    # 重新下载先前下载失败的.ts文件
    while len(download_fail_list) != 0:
        start_download_in_pool(try_again_download, download_fail_list)
    # 检查ts文件总数是否对应
    if downloaded_clip == len(url_list):
        share.log_content = {
            'time': share.get_time(),
            'link': link,
            'status': '下载成功'
        }
        t = threading.Thread(target=share.write, args=(share.log_content, ))
        # 设置守护线程,进程退出不用等待子线程完成
        t.setDaemon(True)
        t.start()
        # 合并视频
        if merge_file(video_name):
            if save_source_file is False:
                # 删除文件夹
                shutil.rmtree(video_name)
            share.m3.alert("下载完成!")
            share.set_progress(0)
            share.m3.str.set('')
            share.m3.clear_alert()
            share.running = False
            downloaded_clip = 0
            # 清空下载失败视频列表
            url_list = []
            download_fail_list = []
        else:
            share.m3.alert("视频文件合并失败,请查看消息列表")
    else:
        share.m3.alert("有部分文件没有下载完成,请点击重试!")
    # 重置任务开始标志
    return True