Ejemplo n.º 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:]
Ejemplo n.º 2
0
#!/usr/bin/env python3
"""Script to add a genre to all members of a group. Supported in poms >= 3.2 only"""

from npoapi import MediaBackend
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('genre', type=str, nargs=1, help='new Genre')
args = api.parse_args()

genre_id = args.genre[0]

bytes = api.get(args.mid[0], ignore_not_found=True)
if bytes:
    object = poms.CreateFromDocument(bytes)
    if type(object) == mediaupdate.programUpdateType:
        object.genre.append(genre_id)
        api.post(object)

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

    for member in map(lambda m: poms.CreateFromDOM(m.getElementsByTagName("mediaUpdate")[0], mediaupdate.Namespace), members):
        member_mid = member.mid
        print("Adding genre " + genre_id + " to " + member_mid)
        member.genre.append(genre_id)
        api.post(member)