def get_duration(segment_time_str, time_range):
    """
    计算当前时间到给定结束时间的时差
    如果计算的时差大于segment_time，则返回segment_time。
    """
    if not time_range or '-' not in time_range:
        return segment_time_str
    end_time_str = time_range.split('-')[1]

    now = datetime.now()
    end_time_today_str = now.strftime("%Y-%m-%d") + " " + end_time_str
    end_time_today = datetime.strptime(end_time_today_str, "%Y-%m-%d %H:%M:%S")
    # 判断结束时间是否是第二天的时间
    if now > end_time_today:
        end_time_today += timedelta(days=1)

    time_diff = end_time_today - now
    if segment_time_str:
        segment_time_parts = list(map(int, segment_time_str.split(":")))
        segment_time = timedelta(hours=segment_time_parts[0],
                                 minutes=segment_time_parts[1], seconds=segment_time_parts[2])

        if time_diff > segment_time:
            return segment_time_str

    # 增加10s，防止time_diff过小多次执行下载
    if time_diff.total_seconds() <= 60:
        time_diff = time_diff + timedelta(seconds=10)

    hours, remainder = divmod(time_diff.total_seconds(), 3600)
    minutes, seconds = divmod(remainder, 60)

    to_parameter = f"{int(hours):02}:{int(minutes):02}:{int(seconds):02}"

    return to_parameter
计算当前时间到给定结束时间的时差
如果计算的时差大于segment_time，则返回segment_time。
biliup/engine/download.py