In [1]:
from npoapi import Media
import json

Talking to the NPO Frontend API with PYTHON

You can instantiate a client like so


In [2]:
client = Media(env="test", debug=False).configured_login(create_config_file=True)

The credentials where read from a config file. If that file would not have existed, the user would have been requested to provide the api key, secret and origin, and the config file would have been created then for the next time.

The 'env' option influences to which api it will talk. It can be "test" (default), "dev" and "prod"


In [3]:
client.url


Out[3]:
'https://rs-test.poms.omroep.nl/v1'

Now you can do actual requests


In [ ]:


In [4]:
result = client.get("POMS_NTR_388772") 

print(json.dumps(json.loads(result), indent=1))


{
 "objectType": "program",
 "mid": "POMS_NTR_388772",
 "type": "BROADCAST",
 "avType": "AUDIO",
 "workflow": "PUBLISHED",
 "sortDate": 1376395200000,
 "creationDate": 1376435075424,
 "lastModified": 1376435112166,
 "urn": "urn:vpro:media:program:28506247",
 "embeddable": true,
 "episodeOf": [
  {
   "midRef": "AUTO_WINFRIEDDRAAITDOOR",
   "urnRef": "urn:vpro:media:group:13405810",
   "type": "SERIES",
   "index": 1,
   "highlighted": false,
   "added": 1376435078278
  }
 ],
 "crids": [
  "crid://broadcast.radiobox2/203820"
 ],
 "broadcasters": [
  {
   "id": "NTR",
   "value": "NTR"
  }
 ],
 "titles": [
  {
   "value": "Winfried Draait Door",
   "owner": "RADIOBOX",
   "type": "MAIN"
  }
 ],
 "descriptions": [
  {
   "value": "Elke werkdag draait Winfried Baijens door op Radio 6 met de beste soul en jazz, nieuwe releases, Nederlands talent en de mooiste prijzen. Geen dag gaat voorbij zonder een thema dat veelal iets te maken heeft met de actualiteit. Voorwaarde is; het thema moet allitereren. Daar houdt Winfried namelijk van, allitereren.\nVerder hoor je berichten van nationale en internationale sterren, luisteraars, betrokkenen bij het thema en muziekvrienden die Winfrieds voicemail inspreken. DJ Git Hyper is een vaste gast en Winfried maakt ook een muzikale kettingbrief. Vele grote namen uit de Nederlandse muziekwereld werkten al mee aan deze multitracks.",
   "owner": "RADIOBOX",
   "type": "MAIN"
  }
 ],
 "genres": [],
 "countries": [],
 "languages": [],
 "duration": 7200000,
 "descendantOf": [
  {
   "midRef": "AUTO_WINFRIEDDRAAITDOOR",
   "urnRef": "urn:vpro:media:group:13405810",
   "type": "SERIES"
  },
  {
   "midRef": "POMS_S_VPRO_171668",
   "urnRef": "urn:vpro:media:group:14683553",
   "type": "ARCHIVE"
  },
  {
   "midRef": "POMS_S_VPRO_218686",
   "urnRef": "urn:vpro:media:group:14921825",
   "type": "ARCHIVE"
  },
  {
   "midRef": "POMS_S_VPRO_117474",
   "urnRef": "urn:vpro:media:group:20347947",
   "type": "PLAYLIST"
  }
 ],
 "email": [
  "winfrieddraaitdoor@radio6.nl"
 ],
 "websites": [
  {
   "value": "http://www.radio6.nl/winfrieddraaitdoor"
  }
 ],
 "predictions": [
  {
   "state": "REALIZED",
   "platform": "INTERNETVOD"
  }
 ],
 "locations": [
  {
   "programUrl": "http://download.omroep.nl/audiologging/r6/2013/08/13/1400_1600_winfried_draait_door.mp3",
   "avAttributes": {
    "avFileFormat": "MP3"
   },
   "owner": "RADIOBOX",
   "creationDate": 1376435052113,
   "workflow": "PUBLISHED",
   "duration": 7200000,
   "lastModified": 1376435075571,
   "urn": "urn:vpro:media:location:28506251"
  }
 ],
 "scheduleEvents": [
  {
   "channel": "RAD6",
   "start": 1376395200000,
   "guideDay": 1376344800000,
   "duration": 7200000,
   "midRef": "POMS_NTR_388772",
   "poProgID": "POMS_NTR_388772",
   "urnRef": "urn:vpro:media:program:28506247"
  }
 ],
 "images": [
  {
   "title": "winfried_baijens.jpg",
   "description": "Winfried Draait Door",
   "imageUri": "urn:vpro:image:121034",
   "owner": "RADIOBOX",
   "type": "PICTURE",
   "highlighted": false,
   "creationDate": 1376435059364,
   "workflow": "PUBLISHED",
   "lastModified": 1376435075570,
   "urn": "urn:vpro:media:image:28506249"
  }
 ],
 "publishDate": 1496062156356
}

In [5]:
client.get("bla")


ERROR https://rs-test.poms.omroep.nl/v1/api/media/bla: 'GET' https://rs-test.poms.omroep.nl/v1/api/media/bla: 404 (<class 'urllib.error.HTTPError'>)
ERROR https://rs-test.poms.omroep.nl/v1/api/media/bla: {"status":404,"message":"No media for mid bla","cause":"javax.ws.rs.NotFoundException: No media for mid bla\n\tat nl.vpro.api.rs.v3.exception.Exceptions.notFound(Exceptions.java:22)\n\tat nl.vpro.api.rs.v3.media.MediaRestServiceImpl.getMediaHandleNotFound(MediaRestServiceImpl.java:686)\n\tat nl.vpro.api.rs.v3.media.MediaRestServiceImpl.load(MediaRestServiceImpl.java:169)\n\tat sun.reflect.GeneratedMethodAccessor233.invoke(Unknown Source)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)\n\tat org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:294)\n\tat org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:248)\n\tat org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:235)\n\tat org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:398)\n\tat org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:205)\n\tat org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)\n\tat org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)\n\tat org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:742)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)\n\tat org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)\n\tat org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat nl.vpro.api.security.ApiAuthenticationFilter.successfulAuthentication(ApiAuthenticationFilter.java:107)\n\tat org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:240)\n\tat nl.vpro.api.security.ApiAuthenticationFilter.doFilter(ApiAuthenticationFilter.java:57)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:97)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)\n\tat org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)\n\tat org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)\n\tat org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)\n\tat org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)\n\tat org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat nl.vpro.api.rs.v3.filter.MediaFilterThreadLocalFilter.doFilter(MediaFilterThreadLocalFilter.java:41)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)\n\tat org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)\n\tat org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:479)\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\n\tat java.lang.Thread.run(Thread.java:748)\n"}
Out[5]:
''

In [ ]:


In [ ]: