Example #1
0
#!/usr/bin/env python3
"""
This script checks wether a poms playlist contains multiple translations of the same source. If so, it will delete remove all but one.
"""
from npoapi import MediaBackend
import time

api = MediaBackend().command_line_client()
api.add_argument('mid', type=str, nargs=1, help='The mid  of the object to handle')
args = api.parse_args()

group = args.mid[0]
members = api.members(group, batch=200, log_progress=True)

translations_for_mid = {}
for member in members:
    update = member.firstChild
    mid = update.attributes["mid"].value
    relations = member.getElementsByTagName("relation")
    for relation in relations:
        relation_type = relation.attributes["type"].value
        if relation_type == "TRANSLATION_SOURCE":
            translation_source = relation.firstChild.nodeValue
            if not translation_source in translations_for_mid:
                translations_for_mid[translation_source] = []
            translations_for_mid[translation_source].append(mid)

#print(pprint.pformat(map))
for mid in translations_for_mid:
    sorted_mids = sorted(translations_for_mid[mid])
    mids_to_delete = sorted_mids[1:]
Example #2
0
#!/usr/bin/env python3
""" """
"""Script to add a location """

from npoapi import MediaBackend, MediaBackendUtil as MU

api = MediaBackend().command_line_client()
api.add_argument('mid', type=str, nargs=1, help='The mid  of the object to handle')
api.add_argument('location', type=str, nargs=1, help='URL of the new "location"')

args = api.parse_args()

print(api.add_location(args.mid[0], MU.create_location(args.location[0])))

Example #3
0
#!/usr/bin/env python3
"""Script to add a image to all members of a group."""

from npoapi import MediaBackend, MediaBackendUtil as MU
import npoapi.xml.mediaupdate
from xml.dom import minidom

api = MediaBackend().command_line_client()
api.add_argument("mid", type=str, nargs=1, help="The mid  of the object to handle")
api.add_argument(
    "image", type=str, nargs="+", help="New image. If more than one is provided, they will be used alternately"
)
api.add_argument("title", type=str, nargs="?", help="title for new images")
api.add_argument("--only_if_none", action="store_true", default=False, help="Only if no images present yet")
api.add_argument("--dry_run", action="store_true", default=False, help="Dry run")
api.add_argument(
    "--filter",
    type=str,
    help="""
Filter. A piece of python code to filter. E.g. "memberType == npoapi.xml.mediaupdate.programUpdateType" or "member.type == 'PROMO'"
""",
)
api.add_argument("--to_object", action="store_true", default=False, help="Add to object itself too")
api.add_argument("--to_object_only", action="store_true", default=False, help="Add to object itself only")
api.add_argument("--max", type=int, nargs="?", help="Maximum number of objects to process")
api.add_argument("--max_query", type=int, nargs="?", help="Maximum number of objects to find")
api.add_argument("--segments", action="store_true", default=False, help="")

MU.logger = api.logger
args = api.parse_args()
Example #4
0
#!/usr/bin/env python3
"""Script to do something for all descendants of a poms group"""

import pickle
import os
from tempfile import gettempdir

# some imports handy for the exec call
import npoapi.xml.mediaupdate
from dateutil.parser import parse
from npoapi import MediaBackend, MediaBackendUtil as MU

api = MediaBackend().command_line_client()
api.add_argument('mid', type=str, nargs=1, help='The mid  of the object to handle')
api.add_argument('process', type=str, nargs=1, help="""
python code to postprocess. E.g.

member.genre.append('1.3.4')

member.publishStop=parse("2018-12-31")

""")
api.add_argument('-C', '--clean', action='store_true', default=False)
api.add_argument('--dryrun', action='store_true', default=False)

api.add_argument('--filter', type=str, help="""
Filter. A piece of python code to filter. E.g.
type(member) == npoapi.xml.mediaupdate.programUpdateType
member.type == 'CLIP'
'kort!' in short_title.lower()
""")
Example #5
0
#!/usr/bin/env python3
""" """
from npoapi import MediaBackend
from npoapi.xml import mediaupdate

poms = MediaBackend().command_line_client()
poms.add_argument('mid', type=str, nargs=1, help='The mid  of the object to get')
poms.add_argument('duration', type=str, nargs=1, help='The duration to set')

args = poms.parse_args()
bytes = poms.get(args.mid[0])
update = mediaupdate.CreateFromDocument(bytes)
duration = args.duration[0]
update.duration = duration
poms.post(update)
Example #6
0
#!/usr/bin/env python3
"""The generic tool  npo_mediabackend  will let you too must things. This is an example for how to make a more specific tool"""
from npoapi import MediaBackend
from npoapi.xml import mediaupdate, media
import sys

poms = MediaBackend().command_line_client()

poms.add_argument('id', type=str, nargs=1, help='The mid or crid of the object to handle')
poms.add_argument('type', type=str, nargs='?', help='The new type')
poms.add_argument('avType', type=str, nargs='?', help='The new avtype')

args = poms.parse_args()

id = args.id[0]

xml = poms.get(id, ignore_not_found=True)
if xml:
    object = mediaupdate.CreateFromDocument(xml)
    if args.type:
        if type(object) is mediaupdate.programUpdateType:
            object.type = getattr(media.programTypeEnum, args.type)
        elif type(object) is mediaupdate.groupUpdateType:
            object.type = getattr(media.groupTypeEnum, args.type)
    if args.avType:
        object.avType = getattr(media.avTypeEnum, args.avType)
    poms.post(object)
else:
    sys.stderr.write("The object %s is not found in poms")
Example #7
0
#!/usr/bin/env python3
"""Script to add a image to all members of a group."""

from npoapi import MediaBackend, MediaBackendUtil as MU
import npoapi.xml.mediaupdate
from xml.dom import minidom

api = MediaBackend().command_line_client()
api.add_argument('mid',   type=str, nargs=1, help='The mid  of the object to handle')
api.add_argument('image', type=str, nargs='+', help='New image. If more than one is provided, they will be used alternately')
api.add_argument('title', type=str, nargs='?', help='title for new images')
api.add_argument('--only_if_none', action='store_true', default=False, help='Only if no images present yet')
api.add_argument('--dry_run', action='store_true', default=False, help='Dry run')
api.add_argument('--filter', type=str,  help="""
Filter. A piece of python code to filter. E.g. "memberType == npoapi.xml.mediaupdate.programUpdateType" or "member.type == 'PROMO'"
""")
api.add_argument('--to_object', action='store_true', default=False, help='Add to object itself too')
api.add_argument('--to_object_only', action='store_true', default=False, help='Add to object itself only')
api.add_argument('--max', type=int, nargs='?', help='Maximum number of objects to process')
api.add_argument('--max_query', type=int, nargs='?', help='Maximum number of objects to find')
api.add_argument('--segments', action='store_true', default=False, help='')

MU.logger = api.logger
args = api.parse_args()

mid = args.mid[0]
images = args.image
title = args.title
mediaUpdate = api.get_object(mid, ignore_not_found=True)
only_if_none = args.only_if_none
filter = args.filter
Example #8
0
#!/usr/bin/env python3
"""Script to add a image to all members of a group."""

from npoapi import MediaBackend, MediaBackendUtil as MU
from npoapi.xml import mediaupdate
from npoapi.xml import poms

api = MediaBackend().command_line_client()
api.add_argument('mid', type=str, nargs=1, help='The mid  of the object to handle')
api.add_argument('group', type=str, nargs=1, help='Group')
api.add_argument('--use_get', action='store_true', default=False)
api.add_argument('--position', type=int, default=None)

args = api.parse_args()

mid   = args.mid[0]
group = args.group[0]

if args.use_get:
    media = poms.CreateFromDocument(api.get(mid))
    memberOf = mediaupdate.memberRef(group)
    memberOf.highlighted = False
    memberOf.position = args.position
    media.memberOf.append(memberOf)

    api.post(media)
else:
    api.add_member(mid, group, position=args.position)