def update_youtube()

in gnm_deliverables/launch_detector.py [0:0]


def update_youtube(msg: LaunchDetectorUpdate, asset: DeliverableAsset):
    """
    either create or update a Youtube information object from the given message
    :param msg:  LaunchDetectorUpdate instance giving the content to update
    :param asset: DeliverableAsset that needs to be updated
    :return:
    """
    if asset.youtube_master is None:
        rec: Youtube = Youtube()
    else:
        rec: Youtube = asset.youtube_master

    # FIXME: should update our data model to handle multiple assets on a given item, then we can remove this.
    youtube_assets = [a for a in msg.assets if a.platform.lower() == "youtube"]
    # sort is lowest-number first, we want the highest so take last of the list
    youtube_assets_sorted: List[MediaAsset] = sorted(youtube_assets, key=lambda a: a.version)

    if len(youtube_assets_sorted) > 0:
        rec.youtube_id = youtube_assets_sorted[-1].asset_id

    if msg.yt_meta:
        rec.youtube_category = msg.yt_meta.category_id
        rec.youtube_channel = msg.yt_meta.channel_id
        rec.youtube_tags = msg.yt_meta.keywords
        if msg.yt_meta.title != "":
            rec.youtube_title = msg.yt_meta.title
        if msg.yt_meta.description != "":
            rec.youtube_description = msg.yt_meta.description
    if msg.published is not None:
        rec.publication_date = msg.published.at
    # set the etag in case something else is editing it at the moment
    rec.etag = zoned_datetime().isoformat('T')
    asset.youtube_master = rec
    rec.save()
    asset.save()