#!/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)
#!/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)
class MediaBackendTest(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.client = MediaBackend().configured_login(config_dir=os.path.dirname(__file__)).env(ENV).debug() def test_xml_to_bytes_string(self): self.assertEquals("<a xmlns='urn:vpro:media:update:2009' />", self.client.xml_to_bytes("<a xmlns='urn:vpro:media:update:2009' />").decode("utf-8")) def test_xml_to_bytes_minidom(self): self.assertEquals('<a xmlns="urn:vpro:media:update:2009"/>', self.client.xml_to_bytes( minidom.parseString("<a xmlns='urn:vpro:media:update:2009' />").documentElement).decode( "utf-8")) def test_append_params(self): self.assertEquals("http://vpro.nl?a=a&x=y", self.client.append_params("http://vpro.nl", include_errors=False, a="a", x="y")) def test_set_duration(self): existing = poms.CreateFromDocument(self.client.get("WO_VPRO_1422026")) existing.duration = "PT30M" self.client.post(existing) def test_get_locations(self): bytes=self.client.get_locations("POMS_VPRO_1421796") locations=poms.CreateFromDocument(bytes) print(str(locations)) def test_get_segments(self): bytes = self.client.get("RBX_AT_2145721") existing = mediaupdate.CreateFromDocument(bytes) self.assertTrue(type(existing) == mediaupdate.segmentUpdateType) def test_get_images(self): mid="POMS_VPRO_1421796" media=poms.CreateFromDocument(self.client.get(mid)) print(len(media.images.image)) image=media.images.image[0] bytes = self.client.get_images("POMS_VPRO_1421796") images= poms.CreateFromDocument(bytes) image2=images.wildcardElements()[0] self.assertEquals(image.title, image2.title) self.assertEquals(image2.title, "sdf") print(image2.toxml()) def test_set_location(self): mid = "POMS_VPRO_1421796" self.client.set_location(mid, "http://www.vpro.nl/123", publishStop="2012-01-11T17:16:01.287Z") def test_set_location_by_id(self): mid = "POMS_VPRO_1421796" self.client.set_location(mid, 58758190, publishStop="2012-01-11T17:16:01.287Z") def test_set_location_by_id_as_string(self): mid = "POMS_VPRO_1421796" self.client.set_location(mid, "58758190", publishStop="2013-01-11T17:16:01.287Z") def test_set_location_by_urn(self): mid = "POMS_VPRO_1421796" self.client.set_location(mid, "urn:vpro:media:location:58758190", publishStop="2014-01-11T17:16:01.287Z") def test_create_location(self): mid = "POMS_VPRO_1421796" self.client.set_location(mid, "http://www.vpro.nl/" + str(round(time.time())) + ".mp3", publishStop="2012-01-11T17:16:01.287Z")
#!/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")
#!/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') args = api.parse_args() mid = args.mid[0] group = args.group[0] media = poms.CreateFromDocument(api.get(mid)) memberOf = mediaupdate.memberRefUpdateType(group) memberOf.highlighted = False media.memberOf.append(memberOf) api.post(media)
#!/usr/bin/env python3 from npoapi import MediaBackend from mediaupdate import MediaUpdate import pprint 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() mid = args.mid[0] print(pprint.pformat(MediaUpdate.CreateFromDOM(api.get(mid))))