如何根据实时在声音播放列表序列中注入声音时间项?

问题描述 投票:0回答:0

我觉得这有点复杂,但让我们开始吧!

输入:

  1. schedule_items:字典列表,每本字典都有这个键:
  • title:标题将是一个字符串
  • duration_milliseconds:duration_milliseconds 将是每个音轨的持续时间,以毫秒为单位
  • start_datetime:start_datetime 将是一个 datetime.datetime,它将显示音轨开始的具体时间。序列列表项将具有 start_datetime_i+1 = start_datetime_i+duration_milliseconds_i
  1. time_collection:包含标准两项的列表。

第一个是带键的字典:

  • collection_title:collection_title将是time_collection的标题:
  • collection_case:collection_case 将是 14 之间的数字(1 案例:01:00|13:00,02:00|14:00,03:00|15:00, ...12:00|24:00(12 项)2 案例:01:00,02:00,...,12:00,13:00,...24:00(24 项) 3 案例:01:00|13:00,01:30|13:30,02:00|14:00,02:30|14:30,03:00|15:00,...12 :00|24:00,12:30|24:30(24 项)和 4 案例:01:00,01:30,02:00,02:30,03:00,...12: 00,12:30,..24:00,24:30(48 项))。
  • append_duration_milliseconds:append_duration_milliseconds 将是连接 time_collection 的音轨的持续时间。例如,如果广播制作人希望每次播放 Time 时都会在其余音乐节目继续之前播放音轨,那么 append_duration_millisecond 将显示这个额外时间。

time_collection 列表的第二个项目将是一个列表,其中项目总数 = 所选 collection_case 的项目(case=1 12 项,case=2 24 项,case=3 24 项,case=4 48 项)。

每一项都将是一本带键的字典:

  • title:标题将是一个文本,例如:“时间是 1 点。”
  • duration_milliseconds:duration_milliseconds 将是表示时间的音轨的持续时间(例如一点钟 10*1000)
  • when_to_play:when_to_play会根据集合大小写为“01:00|13:00”或“01:00”或“01:30|13:30”或“24:30”等字符串。

输出:

标题为schedule_items_final的列表:其中将包含输入的所有schedule_items,根据开始日期时间输入的适当time_collection项目。

如果 schedule_items 的 duration 和 start_datetime 大于 1 小时(或 30 分钟),则音轨将被裁剪成多个部分(可能超过两个)并且这些部分的标题可能会说明这是一个部分。例如,如果我将标题为“bla bla bla”的 schedule_item 裁剪为三部分,则裁剪后的项目将具有标题“bla bla bla part 1”、“bla bla bla part 2”、“bla bla bla part 3”。


我相信问题已经得到很好的解释,但如果您对问题的任何部分感到困惑,请随时发表评论。

  • 我过去制作这个程序非常成功(但我已经失去了它),所以我很确定我们可以重新制作它(也许更好更快)。

一个小例子:

输入:

schedule_items=[{"title":"1","duration_milliseconds"1000*60*60*1.5,"start_datetime":datetime.now()},{"title":"2","duration_milliseconds":1000*60*10*2,"start_datetime":datetime.now()+timedelta(seconds=60*60*1.5)},{"title":"3","duration_milliseconds":1000*60*2,"start_datetime":datetime.now()+timedelta(seconds=60*60*1.5+60*10*2)},{"title":"4","duration_milliseconds":1000*60*60*2,"start_datetime":datetime.now()+timedelta(seconds=60*60*1.5+60*10*2+60*2)}]
time_collection=[{"collection_title":"Time collection 1","collection_case":1,"append_duration_milliseconds":1000*25},[{"title":"The time is 1","duration_milliseconds":1000*5,"when_to_play":"01:00|13:00"},{"title":"The time is 2","duration_milliseconds":1000*5,"when_to_play":"02:00|14:00"},{"title":"The time is 3","duration_milliseconds":1000*5,"when_to_play":"03:00|15:00"},{"title":"The time is 4","duration_milliseconds":1000*5,"when_to_play":"04:00|16:00"},{"title":"The time is 5","duration_milliseconds":1000*5,"when_to_play":"05:00|17:00"},{"title":"The time is 6","duration_milliseconds":1000*5,"when_to_play":"06:00|18:00"},{"title":"The time is 7","duration_milliseconds":1000*5,"when_to_play":"07:00|19:00"},{"title":"The time is 8","duration_milliseconds":1000*5,"when_to_play":"08:00|20:00"},{"title":"The time is 9","duration_milliseconds":1000*5,"when_to_play":"09:00|21:00"},{"title":"The time is 10","duration_milliseconds":1000*5,"when_to_play":"10:00|22:00"},{"title":"The time is 11","duration_milliseconds":1000*5,"when_to_play":"11:00|23:00"},{"title":"The time is 12","duration_milliseconds":1000*5,"when_to_play":"12:00|24:00"}]]

如果 datetime.now = 22/04/2023 23:58:00 那么预期输出将是:

一个。第一项:

{"title":"1 part 1","duration_milliseconds":1000*60*2,"start_datetime":22/04/2023 23:58:00}

b。第二项:

{"title":"The time is 12","duration_milliseconds":1000*30,"start_datetime":23/04/2023 00:00:00,"when_to_play":"12:00|24:00"}

c。第三项:

{"title":"1 part 2","duration_milliseconds"1000*59.5,"start_datetime":23/04/2023 00:00:30}

d。第四项:

{"title":"The time is 1","duration_milliseconds"1000*30,"start_datetime":23/04/2023 01:00:00,"when_to_play":"01:00|13:00"}

e。第五项:

{"title":"1 part 3","duration_milliseconds":1000*28.5,"start_datetime":23/04/2023 01:00:30}

f.项目编号 6:

{"title":"2","duration_milliseconds":1000*60*10*2,"start_datetime":23/04/2023 01:29:00}

克。商品编号 7:

{"title":"3","duration_milliseconds":1000*60*2,"start_datetime":23/04/2023 01:49:00}

h。项目编号 8:

{"title":"4 part 1","duration_milliseconds":1000*60*9,"start_datetime":23/04/2023 01:51:00}

我。项目编号 9:

{"title":"The time is 2","duration_milliseconds"1000*30,"start_datetime":23/04/2023 02:00:00,"when_to_play":"02:00|14:00"}

j。项目编号 10:

{"title":"4 part 2","duration_milliseconds":1000*59.5,"start_datetime":23/04/2023 02:00:30}

k。商品编号 11:

{"title":"The time is 3","duration_milliseconds"1000*30,"start_datetime":23/04/2023 03:00:00,"when_to_play":"03:00|15:00"}

l。项目编号 12:

{"title":"4 part 3","duration_milliseconds":1000*56.5,"start_datetime":23/04/2023 03:00:30}

在此示例中,程序从 22/04/2023 23:58:00 开始到 23/04/2023 03:57:00 结束。

编辑: 为了帮助初始化 time_collection 案例,此示例可用于在准备就绪时测试程序:

time_collection_1=
    [
        {
            "collection_title":"Time collection 1",
            "collection_case":1,
            "append_duration_milliseconds":1000*25
        },
        [
            {
                "title":"The time is 1",
                "duration_milliseconds":1000*5,
                "when_to_play":"01:00|13:00"
            },
            {
                "title":"The time is 2",
                "duration_milliseconds":1000*5,
                "when_to_play":"02:00|14:00"
            },
            {
                "title":"The time is 3",
                "duration_milliseconds":1000*5,
                "when_to_play":"03:00|15:00"
            },
            {
                "title":"The time is 4",
                "duration_milliseconds":1000*5,
                "when_to_play":"04:00|16:00"
            },
            {
                "title":"The time is 5",
                "duration_milliseconds":1000*5,
                "when_to_play":"05:00|17:00"
            },
            {
                "title":"The time is 6",
                "duration_milliseconds":1000*5,
                "when_to_play":"06:00|18:00"
            },
            {
                "title":"The time is 7",
                "duration_milliseconds":1000*5,
                "when_to_play":"07:00|19:00"
            },
            {
                "title":"The time is 8",
                "duration_milliseconds":1000*5,
                "when_to_play":"08:00|20:00"
            },
            {
                "title":"The time is 9",
                "duration_milliseconds":1000*5,
                "when_to_play":"09:00|21:00"
            },
            {
                "title":"The time is 10",
                "duration_milliseconds":1000*5,
                "when_to_play":"10:00|22:00"
            },
            {
                "title":"The time is 11",
                "duration_milliseconds":1000*5,
                "when_to_play":"11:00|23:00"
            },
            {
                "title":"The time is 12",
                "duration_milliseconds":1000*5,
                "when_to_play":"12:00|24:00"
            }
        ]
    ]
    
    
time_collection_2=
    [
        {
            "collection_title":"Time collection 2",
            "collection_case":2,
            "append_duration_milliseconds":1000*25
        },
        [
            {
                "title":"The time is 1",
                "duration_milliseconds":1000*5,
                "when_to_play":"01:00"
            },
            {
                "title":"The time is 2",
                "duration_milliseconds":1000*5,
                "when_to_play":"02:00"
            },
            {
                "title":"The time is 3",
                "duration_milliseconds":1000*5,
                "when_to_play":"03:00"
            },
            {
                "title":"The time is 4",
                "duration_milliseconds":1000*5,
                "when_to_play":"04:00"
            },
            {
                "title":"The time is 5",
                "duration_milliseconds":1000*5,
                "when_to_play":"05:00"
            },
            {
                "title":"The time is 6",
                "duration_milliseconds":1000*5,
                "when_to_play":"06:00"
            },
            {
                "title":"The time is 7",
                "duration_milliseconds":1000*5,
                "when_to_play":"07:00"
            },
            {
                "title":"The time is 8",
                "duration_milliseconds":1000*5,
                "when_to_play":"08:00"
            },
            {
                "title":"The time is 9",
                "duration_milliseconds":1000*5,
                "when_to_play":"09:00"
            },
            {
                "title":"The time is 10",
                "duration_milliseconds":1000*5,
                "when_to_play":"10:00"
            },
            {
                "title":"The time is 11",
                "duration_milliseconds":1000*5,
                "when_to_play":"11:00"
            },
            {
                "title":"The time is 12",
                "duration_milliseconds":1000*5,
                "when_to_play":"12:00"
            },
            {
                "title":"The time is 13",
                "duration_milliseconds":1000*5,
                "when_to_play":"13:00"
            },
            {
                "title":"The time is 14",
                "duration_milliseconds":1000*5,
                "when_to_play":"14:00"
            },
            {
                "title":"The time is 15",
                "duration_milliseconds":1000*5,
                "when_to_play":"15:00"
            },
            {
                "title":"The time is 16",
                "duration_milliseconds":1000*5,
                "when_to_play":"16:00"
            },
            {
                "title":"The time is 17",
                "duration_milliseconds":1000*5,
                "when_to_play":"17:00"
            },
            {
                "title":"The time is 18",
                "duration_milliseconds":1000*5,
                "when_to_play":"18:00"
            },
            {
                "title":"The time is 19",
                "duration_milliseconds":1000*5,
                "when_to_play":"19:00"
            },
            {
                "title":"The time is 20",
                "duration_milliseconds":1000*5,
                "when_to_play":"20:00"
            },
            {
                "title":"The time is 21",
                "duration_milliseconds":1000*5,
                "when_to_play":"21:00"
            },
            {
                "title":"The time is 22",
                "duration_milliseconds":1000*5,
                "when_to_play":"22:00"
            },
            {
                "title":"The time is 23",
                "duration_milliseconds":1000*5,
                "when_to_play":"23:00"
            },
            {
                "title":"The time is 24",
                "duration_milliseconds":1000*5,
                "when_to_play":"24:00"
            }
        ]
    ]
    
    
    

time_collection_3=
    [
        {
            "collection_title":"Time collection 3",
            "collection_case":3,
            "append_duration_milliseconds":1000*25
        },
        [
            {
                "title":"The time is 1",
                "duration_milliseconds":1000*5,
                "when_to_play":"01:00|13:00"
            },
            {
                "title":"The time is 1:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"01:30|13:30"
            },
            {
                "title":"The time is 2",
                "duration_milliseconds":1000*5,
                "when_to_play":"02:00|14:00"
            },
            {
                "title":"The time is 2:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"02:30|14:30"
            },
            {
                "title":"The time is 3",
                "duration_milliseconds":1000*5,
                "when_to_play":"03:00|15:00"
            },
            {
                "title":"The time is 3:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"03:30|15:30"
            },
            {
                "title":"The time is 4",
                "duration_milliseconds":1000*5,
                "when_to_play":"04:00|04:30"
            },
            {
                "title":"The time is 4:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"04:30|16:30"
            },
            {
                "title":"The time is 5",
                "duration_milliseconds":1000*5,
                "when_to_play":"05:00|17:00"
            },
            {
                "title":"The time is 5:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"05:30|17:30"
            },
            {
                "title":"The time is 6",
                "duration_milliseconds":1000*5,
                "when_to_play":"06:00|18:00"
            },
            {
                "title":"The time is 6:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"06:30|18:30"
            },
            {
                "title":"The time is 7",
                "duration_milliseconds":1000*5,
                "when_to_play":"07:00|19:00"
            },
            {
                "title":"The time is 7:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"07:30|19:30"
            },
            {
                "title":"The time is 8",
                "duration_milliseconds":1000*5,
                "when_to_play":"08:00|20:00"
            },
            {
                "title":"The time is 8:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"08:30|20:30"
            },
            {
                "title":"The time is 9",
                "duration_milliseconds":1000*5,
                "when_to_play":"09:00|21:00"
            },
            {
                "title":"The time is 9:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"09:30|21:30"
            },
            {
                "title":"The time is 10",
                "duration_milliseconds":1000*5,
                "when_to_play":"10:00|22:00"
            },
            {
                "title":"The time is 10:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"10:30|22:30"
            },
            {
                "title":"The time is 11",
                "duration_milliseconds":1000*5,
                "when_to_play":"11:00|23:00"
            },
            {
                "title":"The time is 11:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"11:30|23:30"
            },
            {
                "title":"The time is 12",
                "duration_milliseconds":1000*5,
                "when_to_play":"12:00|24:00"
            },
            {
                "title":"The time is 12:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"12:30|24:30"
            }
        ]
    ]
    
    

time_collection_4=
    [
        {
            "collection_title":"Time collection 4",
            "collection_case":4,
            "append_duration_milliseconds":1000*25
        },
        [
            {
                "title":"The time is 1",
                "duration_milliseconds":1000*5,
                "when_to_play":"01:00"
            },
            {
                "title":"The time is 1:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"01:30"
            },
            {
                "title":"The time is 2",
                "duration_milliseconds":1000*5,
                "when_to_play":"02:00"
            },
            {
                "title":"The time is 2:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"02:30"
            },
            {
                "title":"The time is 3",
                "duration_milliseconds":1000*5,
                "when_to_play":"03:00"
            },
            {
                "title":"The time is 3:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"03:30"
            },
            {
                "title":"The time is 4",
                "duration_milliseconds":1000*5,
                "when_to_play":"04:00"
            },
            {
                "title":"The time is 4:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"04:30"
            },
            {
                "title":"The time is 5",
                "duration_milliseconds":1000*5,
                "when_to_play":"05:00"
            },
            {
                "title":"The time is 5:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"05:30"
            },
            {
                "title":"The time is 6",
                "duration_milliseconds":1000*5,
                "when_to_play":"06:00"
            },
            {
                "title":"The time is 6:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"06:30"
            },
            {
                "title":"The time is 7",
                "duration_milliseconds":1000*5,
                "when_to_play":"07:00"
            },
            {
                "title":"The time is 7:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"07:30"
            },
            {
                "title":"The time is 8",
                "duration_milliseconds":1000*5,
                "when_to_play":"08:00"
            },
            {
                "title":"The time is 8:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"08:30"
            },
            {
                "title":"The time is 9",
                "duration_milliseconds":1000*5,
                "when_to_play":"09:00"
            },
            {
                "title":"The time is 9:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"09:30"
            },
            {
                "title":"The time is 10",
                "duration_milliseconds":1000*5,
                "when_to_play":"10:00"
            },
            {
                "title":"The time is 10:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"10:30"
            },
            {
                "title":"The time is 11",
                "duration_milliseconds":1000*5,
                "when_to_play":"11:00"
            },
            {
                "title":"The time is 11:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"11:30"
            },
            {
                "title":"The time is 12",
                "duration_milliseconds":1000*5,
                "when_to_play":"12:00"
            },
            {
                "title":"The time is 12:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"12:30"
            },
            {
                "title":"The time is 13",
                "duration_milliseconds":1000*5,
                "when_to_play":"13:00"
            },
            {
                "title":"The time is 13:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"13:30"
            },
            {
                "title":"The time is 14",
                "duration_milliseconds":1000*5,
                "when_to_play":"14:00"
            },
            {
                "title":"The time is 14:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"14:30"
            },
            {
                "title":"The time is 15",
                "duration_milliseconds":1000*5,
                "when_to_play":"15:00"
            },
            {
                "title":"The time is 15:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"15:30"
            },
            {
                "title":"The time is 16",
                "duration_milliseconds":1000*5,
                "when_to_play":"16:00"
            },
            {
                "title":"The time is 16:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"16:30"
            },
            {
                "title":"The time is 17",
                "duration_milliseconds":1000*5,
                "when_to_play":"17:00"
            },
            {
                "title":"The time is 17:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"17:30"
            },
            {
                "title":"The time is 18",
                "duration_milliseconds":1000*5,
                "when_to_play":"18:00"
            },
            {
                "title":"The time is 18:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"18:30"
            },
            {
                "title":"The time is 19",
                "duration_milliseconds":1000*5,
                "when_to_play":"19:00"
            },
            {
                "title":"The time is 19:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"19:30"
            },
            {
                "title":"The time is 20",
                "duration_milliseconds":1000*5,
                "when_to_play":"20:00"
            },
            {
                "title":"The time is 20:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"20:30"
            },
            {
                "title":"The time is 21",
                "duration_milliseconds":1000*5,
                "when_to_play":"21:00"
            },
            {
                "title":"The time is 21:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"21:30"
            },
            {
                "title":"The time is 22",
                "duration_milliseconds":1000*5,
                "when_to_play":"22:00"
            },
            {
                "title":"The time is 22:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"22:30"
            },
            {
                "title":"The time is 23",
                "duration_milliseconds":1000*5,
                "when_to_play":"23:00"
            },
            {
                "title":"The time is 23:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"23:30"
            },
            {
                "title":"The time is 24",
                "duration_milliseconds":1000*5,
                "when_to_play":"24:00"
            },
            {
                "title":"The time is 24:30",
                "duration_milliseconds":1000*5,
                "when_to_play":"24:30"
            }
        ]
    ]

这是一个小的启动代码:

import os, sys
from datetime import datetime, timedelta

def make_schedule(schedule_items,item_collection):
    collection_case = int(time_collection[0]["collection_case"])
    start_datetime = schedule_items[0]["start_datetime"]
    current_datetime = schedule_items[0]["start_datetime"]
    for schedule_item in schedule_items:
        if collection_case == 1:
            #code here
            pass
        elif collection_case == 2:
            #code here
            pass
        elif collection_case == 3:
            #code here
            pass
        elif collection_case == 4:
            #code here
            pass
            

def return_time_item_from_datetime(datetime_obj,time_collection):
    #supposed that datetime_obj is right datetime for example 23/12/2023 10:00:00 or 23/12/2023 10:30:00 not 23/12/2023 09:22:12
    collection_case = time_collection[0]["collection_case"]
    hours = datetime_obj.hour
    minutes = datetime_obj.minute
    seconds = datetime_obj.second
    if collection_case == 1:
        return time_collection[1][hours%12-1]
    elif collection_case == 2:
        return time_collection[1][hours-1]
    elif collection_case == 3:
        if minutes == 0:
            return time_collection[1][2*(hours%12-1)]
        elif minutes == 30:
            return time_collection[1][2*(hours%12-1)+1]
    elif collection_case == 4:
        if minutes == 0:
            return time_collection[1][2*(hours-1)]
        elif minutes == 30:
            return time_collection[1][2*(hours-1)+1]


def make_part_index(schedule_item,part_index):
    schedule_item["title"]+= " part "+str(index+1)
    return schedule_item


def add_schedule_item_duration_to_current_datetime(current_datetime,schedule_item):
    current_datetime += timedelta(seconds=schedule_item["duration_milliseconds"]/1000)
    return current_datetime

def add_time_item_check(datetime_obj,timedelta_obj,time_collection):
    collection_case = time_collection[0]["collection_case"]
    datetime_1 = datetime_obj
    datetime_2 = datetime_1 + timedelta_obj

    hour_1 = datetime_1.hour
    minute_1 = datetime_1.minute
    second_1 = datetime_1.second
    
    hour_2 = datetime_1.hour
    minute_2 = datetime_1.minute
    second_2 = datetime_1.second
    
    if hour_2<hour_1:
        hour_2 = 24
    
    if collection_case == 1:
        pass
    elif collection_case == 2:
        pass
    elif collection_case == 3:
        pass
    elif collection_case == 4:
        pass
python date datetime schedule
© www.soinside.com 2019 - 2024. All rights reserved.