In [1]:
import requests
import os.path

NRK_TV_API = 'https://tv.nrk.no'
NRK_TV_MOBIL_API = 'https://tvapi.nrk.no/v1'
NRK_PS_API = 'http://v8.psapi.nrk.no'

session = requests.Session()
session.headers['app-version-android'] = '999'

Searching

Search for a program that is not part of a series


In [2]:
string = "Sankthans-stemning fra Stavern"
string = "Herdlefjorden"
string = "DVFJ67000311"
try:
    r = session.get('https://tvapi.nrk.no/v1/search/' + string)
    r.raise_for_status()
    hits = r.json()['hits']
except Exception as e:
    print('No data received: {}'.format(e))
    
for i, hit in enumerate(hits):
    #if not hit['hit']['seriesId']:
    if hit['type'] not in ['episode', 'series']:
        print(i)


No data received: 412 Client Error: Precondition Failed for url: https://tvapi.nrk.no/v1/search/DVFJ67000311
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-a20928934679> in <module>()
      9     print('No data received: {}'.format(e))
     10 
---> 11 for i, hit in enumerate(hits):
     12     #if not hit['hit']['seriesId']:
     13     if hit['type'] not in ['episode', 'series']:

NameError: name 'hits' is not defined

In [117]:
hits

Search for a program that IS part of a series


In [41]:
string = "skam"
try:
    r = session.get('https://tvapi.nrk.no/v1/search/' + string)
    r.raise_for_status()
    hits = r.json()['hits']
except Exception as e:
    print('No data received: {}'.format(e))

In [45]:
for i, hit in enumerate(hits):
    if hit['type'] not in ['episode', 'serie']:
        print(i)


2

In [46]:
hits[2]


Out[46]:
{'type': 'program',
 'hit': {'objectId': 'KOIF23006716',
  'title': 'Skammerens datter',
  'description': 'Tronarvingen Nicodemus anklages for å ha myrdet families. Skammeren Melussina og datteren Dina kan se i øynene hans at han er uskyldig. Men det nekter den onde Drakan å godta. Med: Rebecca Emilie Sattrup, Jakob Oftebro, Maria Bonnevie. Regi: Kenneth Kainz.',
  'imageId': '9SXbxvTFO6W0Hm-FkMKUzg2QkK1IBLfTK-2Kd7HOccpg',
  'seasons': [],
  'duration': 92.23333,
  'expires': None,
  'seriesId': None,
  'seasonNumber': None,
  'seriesTitle': None,
  'episodeNumberOrDate': None,
  'episodeTitle': None,
  'aldersgrense': '12',
  'usageRights': {'availableFrom': 1533432719000,
   'availableTo': 1534647929000,
   'hasNoRights': False,
   'geoblocked': True},
  'programId': 'koif23006716',
  'category': {'id': 'film-tv', 'categoryId': 'film', 'title': 'Film'}},
 'highlights': None}

Search for a series


In [110]:
string = "skam"
string = "tidenes sommer"
try:
    r = session.get('https://tvapi.nrk.no/v1/search/' + string)
    r.raise_for_status()
    hits = r.json()['hits']
except Exception as e:
    print('No data received: {}'.format(e))

for i, hit in enumerate(hits):
    if hit['type'] == 'serie':
        print(i)

In [111]:
hits[0]


Out[111]:
{'type': 'program',
 'hit': {'objectId': 'DVYR20000017',
  'title': 'Væråret 2017',
  'description': 'Bli med på en reise gjennom ekstreme kontraster. TV-meteorolog Siri Wiberg pynter til rosa jul mens hun gjenopplever livsfarlige flommer, tidenes snøvinter i nord og nok en guffen sommer i sør. Noen ganger er været blodig alvor, andre ganger ren lykke.',
  'imageId': 'YwUYcFROsSu-Zxrqx8vWBwNpIw0dn3e--IQcLmxZndCw',
  'seasons': [],
  'duration': 44.283333,
  'expires': None,
  'seriesId': None,
  'seasonNumber': None,
  'seriesTitle': None,
  'episodeNumberOrDate': None,
  'episodeTitle': None,
  'aldersgrense': '0',
  'usageRights': {'availableFrom': 1514227535000,
   'availableTo': 253402210800000,
   'hasNoRights': False,
   'geoblocked': False},
  'programId': 'dvyr20000017',
  'category': {'id': 'nyheter-tv',
   'categoryId': 'nyheter',
   'title': 'Nyheter'}},
 'highlights': None}

In [55]:
import datetime
datetime.datetime.fromtimestamp(1534647929000/1000)


Out[55]:
datetime.datetime(2018, 8, 19, 5, 5, 29)

In [62]:
hits[10]['hit'['usageRights']['availableTo']


Out[62]:
253402210800000

In [56]:
datetime.datetime.now()


Out[56]:
datetime.datetime(2018, 8, 8, 11, 31, 23, 462711)

In [20]:
string = "Vestlandsrevyen"
try:
    r = session.get('https://tvapi.nrk.no/v1/search/' + string)
    r.raise_for_status()
    hits = r.json()['hits']
except Exception as e:
    print('No data received: {}'.format(e))

for i, hit in enumerate(hits):
    if hit['type'] == 'serie':
        print(i)


0

In [ ]:


In [15]:
s = hits[0]
s.get_seasons_and_episodes()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-c148d88b691c> in <module>()
      1 s = hits[0]
----> 2 s.get_seasons_and_episodes()

AttributeError: 'dict' object has no attribute 'get_seasons_and_episodes'

In [ ]:
[val['id'] for val in hits[0]['hit']['seasons']]

In [ ]:


In [ ]:
string = "skam"
r = session.get('https://tvapi.nrk.no/v1/search/' + string)
r.raise_for_status()
json = r.json()
json.keys()

In [ ]:
json['hi']

In [ ]:
json['metaData']

In [ ]:
string = "ikke gjør dette"
r = session.get('https://tv.nrk.no/autocomplete?query=' + string)
r.raise_for_status()
print(r.json().keys())
r.json()['result']

In [107]:
string = "ikke gjør dette"
r = session.get('https://radio.nrk.no/autocomplete?query=' + string)
r.raise_for_status()
print(r.json().keys())
r.json()['result']


---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-107-f3b2a5d1501a> in <module>()
      1 string = "ikke gjør dette"
      2 r = session.get('https://radio.nrk.no/autocomplete?query=' + string)
----> 3 r.raise_for_status()
      4 print(r.json().keys())
      5 r.json()['result']

~/miniconda3/envs/python3dev/lib/python3.6/site-packages/requests/models.py in raise_for_status(self)
    933 
    934         if http_error_msg:
--> 935             raise HTTPError(http_error_msg, response=self)
    936 
    937     def close(self):

HTTPError: 404 Client Error: Not Found for url: https://radio.nrk.no/autocomplete?query=ikke%20gj%C3%B8r%20dette

In [ ]:
json['hits']

In [ ]:
json = r.json()
json['hits']

Get episodes and seasons of a series


In [154]:
seriesId = 'hurtigruten-minutt-for-minutt' #ikke-gjoer-dette-hjemme'
seriesId = 'tidenes-sommer'
seriesId = 'skam'
r = session.get(NRK_TV_MOBIL_API + '/series/' + seriesId)
r.raise_for_status()
json = r.json()

In [155]:
json


Out[155]:
{'seriesId': 'skam',
 'title': 'SKAM',
 'description': 'SKAM er en nettdramaserie som følger en gjeng på Hartvig Nissen videregående skole i Oslo. Du kan følge serien hver dag på skam.p3.no. Hver fredag kan du se alle ukens filmer samlet i en episode her. Anbefalt målgruppe 15 år.',
 'seasonIds': [{'id': 91415, 'name': 'Sesong 4'},
  {'id': 85475, 'name': 'Sesong 3'},
  {'id': 76968, 'name': 'Sesong 2'},
  {'id': 70522, 'name': 'Sesong 1'}],
 'imageId': 'TEFdD69m0SjyvkknfPsMvgncdCcMW-aiJbQG-iSCHb3g',
 'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
 'categories': [{'categoryId': 'drama-serier',
   'displayValue': 'Drama/serier'}],
 'programs': [{'title': 'SKAM',
   'description': '– Denne talen er til deg.',
   'episodeNumberOrDate': '10:10',
   'programId': 'mynt15001017',
   'seriesId': 'skam',
   'imageId': 'zBtIJpNvPHQsxAdRUilchwZPVEwl1iLQN2AVmw5vnucg',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 91415,
   'usageRights': {'availableFrom': 1498339500000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 3567000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Når drar du?',
   'episodeNumberOrDate': '9:10',
   'programId': 'mynt15000917',
   'seriesId': 'skam',
   'imageId': 'rrsu20c_hC1ABM_Fq0DySwtHjbjAhL-dLK7zbjLtm8hA',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 91415,
   'usageRights': {'availableFrom': 1497637200000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 2901160,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Vær så snill, tilgi meg.',
   'episodeNumberOrDate': '8:10',
   'programId': 'mynt15000817',
   'seriesId': 'skam',
   'imageId': 'hDfi45GpMHznSS867So8FwvyDz-ZqlpVDSJOntmwpCZA',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 91415,
   'usageRights': {'availableFrom': 1497032400000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 2154760,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Det er noen som angriper oss.',
   'episodeNumberOrDate': '7:10',
   'programId': 'mynt15000717',
   'seriesId': 'skam',
   'imageId': 'YeHuEmaH0V2nfapHnUwBxArOyDiLWCGRkiFgjKLcJ9-A',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 91415,
   'usageRights': {'availableFrom': 1496427600000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 2202400,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Fake, fake, fake.',
   'episodeNumberOrDate': '6:10',
   'programId': 'mynt15000617',
   'seriesId': 'skam',
   'imageId': 'YO4twLLgD5uNtYoWQfCRlgj8TB38K1-2FqntJfH7uEqw',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 91415,
   'usageRights': {'availableFrom': 1495822800000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1850480,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Når du er trist, er jeg også trist.',
   'episodeNumberOrDate': '5:10',
   'programId': 'mynt15000517',
   'seriesId': 'skam',
   'imageId': 'c-kgWlFfm7GfVv2JdZnqoAe2LgnJCiJjTMYhDm-4eD8w',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 91415,
   'usageRights': {'availableFrom': 1494615300000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1649760,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Er ikke forelska par helt sjukt ekle?',
   'episodeNumberOrDate': '4:10',
   'programId': 'mynt15000417',
   'seriesId': 'skam',
   'imageId': '55Gwjoklfl7rVmQHE_wpTQHJvOVVUylffFS6qJygPV2g',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 91415,
   'usageRights': {'availableFrom': 1494008400000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1824000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Trenger du hjelp?',
   'episodeNumberOrDate': '3:10',
   'programId': 'mynt15000317',
   'seriesId': 'skam',
   'imageId': 'ZVLmJsMDq-RQjfm_dXjyDQ05UZS7Qt_sTc4sN5PYzJ_A',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 91415,
   'usageRights': {'availableFrom': 1493403600000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1696000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Vanlige, norske partyjenter.',
   'episodeNumberOrDate': '2:10',
   'programId': 'mynt15000217',
   'seriesId': 'skam',
   'imageId': 'vIuYRC8ItV4vqFxluMLIxQUvhGaB6ivtjIGYGP9wlclw',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 91415,
   'usageRights': {'availableFrom': 1492798800000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1093280,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Du hater å henge med oss.',
   'episodeNumberOrDate': '1:10',
   'programId': 'mynt15000117',
   'seriesId': 'skam',
   'imageId': 'TEFdD69m0SjyvkknfPsMvgncdCcMW-aiJbQG-iSCHb3g',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 91415,
   'usageRights': {'availableFrom': 1492194300000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1508720,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '- bare én ting vi alle vet helt sikkert. At livet er ... NÅ. ',
   'episodeNumberOrDate': '10:10',
   'programId': 'mynt15201016',
   'seriesId': 'skam',
   'imageId': 'WhEcAU_WtjkV7gavPEjPPQZuc2c4oY3EMW9nmWu0Fmfg',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 85475,
   'usageRights': {'availableFrom': 1481916000000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1983400,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Velkommen til mobilsvar.',
   'episodeNumberOrDate': '9:10',
   'programId': 'mynt15200916',
   'seriesId': 'skam',
   'imageId': 'mnLAOHNCEONr62cH86r3dgd9DmRsUwzxjzzJ5OC8lo0g',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 85475,
   'usageRights': {'availableFrom': 1481314800000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1098680,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Drit i å ringe Isak.',
   'episodeNumberOrDate': '8:10',
   'programId': 'mynt15200816',
   'seriesId': 'skam',
   'imageId': 'wPyRn8wRGUZxwB7soRegJgE43z8-G3mIS-N47lYJUPsA',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 85475,
   'usageRights': {'availableFrom': 1480710600000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1775160,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Er du homo?',
   'episodeNumberOrDate': '7:10',
   'programId': 'mynt15200716',
   'seriesId': 'skam',
   'imageId': '_KmgKlkVipOrxm_vuXgkXwaDpuyXKay06WkF7RfDdUWQ',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 85475,
   'usageRights': {'availableFrom': 1480101600000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1370000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Kan du ikke bare si det?',
   'episodeNumberOrDate': '6:10',
   'programId': 'mynt15200616',
   'seriesId': 'skam',
   'imageId': 'T9hTR6MNeoInG-aQmWWDEA9Iwnr3wtuBCU0TCvdnIN8w',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 85475,
   'usageRights': {'availableFrom': 1479496800000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1143000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Kan jeg bli her med deg for alltid?',
   'episodeNumberOrDate': '5:10',
   'programId': 'mynt15200516',
   'seriesId': 'skam',
   'imageId': 'L4yhYx2GUfZdMH4A-Lo6FwrdMSZSGRp3Kh48m2fSR9cg',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 85475,
   'usageRights': {'availableFrom': 1478292600000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1815560,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Da vorser vi sammen?',
   'episodeNumberOrDate': '4:10',
   'programId': 'mynt15200416',
   'seriesId': 'skam',
   'imageId': 'MUsyVUpq9MlWklcGLIi-ug-1myiruuSzpsFEeggtdLlw',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 85475,
   'usageRights': {'availableFrom': 1477682700000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1217920,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Hun er på.',
   'episodeNumberOrDate': '3:10',
   'programId': 'mynt15200316',
   'seriesId': 'skam',
   'imageId': 'KBGIs3S4uc8L5AdsqLS43Q3TiJLlJ5pmy_ju5lFgWY7A',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 85475,
   'usageRights': {'availableFrom': 1477074000000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1318280,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Du er over 18, sant?',
   'episodeNumberOrDate': '2:10',
   'programId': 'mynt15200216',
   'seriesId': 'skam',
   'imageId': 'P2hHJitxZ0rDNWcT3mGLVwUqKO8VsM278-4_aoYIsMZA',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 85475,
   'usageRights': {'availableFrom': 1476469200000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1529480,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Lykke til, Isak.',
   'episodeNumberOrDate': '1:10',
   'programId': 'mynt15200116',
   'seriesId': 'skam',
   'imageId': 'QRDw0LdSpNIbEgcPmF7E2gYkkSXyGoz2I1FB9qEnvQ1A',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 85475,
   'usageRights': {'availableFrom': 1475864400000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1629520,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Vil du flytte sammen med meg?',
   'episodeNumberOrDate': '12:12',
   'programId': 'mynt15001216',
   'seriesId': 'skam',
   'imageId': 'k_YLvfol8QKyOXcGrB1tewZbjUoYXJKypM18efvTbNwA',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1464978000000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 2967000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Husker du seriøst ingenting?',
   'episodeNumberOrDate': '11:12',
   'programId': 'mynt15001116',
   'seriesId': 'skam',
   'imageId': 'k6oYR7QleoTPhAkXbq8hcwtau1u3VN-TLwzoxSdXQKJQ',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1464373200000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1791800,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Jeg skal forklare alt.',
   'episodeNumberOrDate': '10:12',
   'programId': 'mynt15001016',
   'seriesId': 'skam',
   'imageId': 'dE9TWCap-cPlcystljhHTQOXN4FHZbb0ioVcgd3Ua_Jg',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1463768400000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 2890000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Jeg savner deg så jævlig.',
   'episodeNumberOrDate': '9:12',
   'programId': 'mynt15000916',
   'seriesId': 'skam',
   'imageId': 'SwnRFI0rFB4NJ-XzfT0m-AvGN3XaLltdfWvBMHXnSxpQ',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1463163600000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1270840,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Du bare tenker på William.',
   'episodeNumberOrDate': '8:12',
   'programId': 'mynt15000816',
   'seriesId': 'skam',
   'imageId': 'GuZznqldp2UsJdLxOJrHXQs1XaNiVO1GJDUzwCe8CVAA',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1462559400000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 2429120,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Noora, du trenger pikk.',
   'episodeNumberOrDate': '7:12',
   'programId': 'mynt15000716',
   'seriesId': 'skam',
   'imageId': 'Sakhx776IMeX1UqVgYwGwg17xRVTc0IV-KC0dtc2NtSQ',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1461958175000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1389760,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Jeg vil ikke bli beskytta.',
   'episodeNumberOrDate': '6:12',
   'programId': 'mynt15000616',
   'seriesId': 'skam',
   'imageId': 'RVU8SdaL1YfvqOJg2xYH7g4WIZNxVO8rcnuVvmAIfcrg',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1461349800000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1425000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Jeg er i hvert fall ikke sjalu.',
   'episodeNumberOrDate': '5:12',
   'programId': 'mynt15000516',
   'seriesId': 'skam',
   'imageId': 'fczKi1UyY2IUyv2UxQrZOwlFvzMKjTxB46FvkIwyD5Pg',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1459535400000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1867000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Jeg visste det var noe rart med henne.',
   'episodeNumberOrDate': '4:12',
   'programId': 'mynt15000416',
   'seriesId': 'skam',
   'imageId': 'c_njH8vuCMOjBkxJO0cMSgzIMjrjgTj8hRGBLXFelkjw',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1458934200000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1726160,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Er det noe du skjuler for oss?',
   'episodeNumberOrDate': '3:12',
   'programId': 'mynt15000316',
   'seriesId': 'skam',
   'imageId': 'erU5DI3TTrKGe4mBMHxpBQED0YAs8Me1KeVVAEP6i6Nw',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1458333000000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 2123120,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Du lyver til en venninne og skylder på meg.',
   'episodeNumberOrDate': '2:12',
   'programId': 'mynt15000216',
   'seriesId': 'skam',
   'imageId': '-Nr5QZgbz3X3dZU_uZQ1fw6aCgwDIKE0pQF2FP3FGV6Q',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1457724600000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1549320,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Om du bare hadde holdt det du lovet.',
   'episodeNumberOrDate': '1:12',
   'programId': 'mynt15000116',
   'seriesId': 'skam',
   'imageId': 'SSD39AvA5SnvxutvhdQl_AJwvOMhUgvDUF71NJQhItTQ',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 76968,
   'usageRights': {'availableFrom': 1457119800000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1545200,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Et jævlig dumt valg.',
   'episodeNumberOrDate': '11:11',
   'programId': 'msub19121116',
   'seriesId': 'skam',
   'imageId': 'eGn1DbGGZFhWo6Q3sALPygJcxZtpKYEUBpAo2KVYX8Ig',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1449862200000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 2095440,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Jeg tenker at du har blitt helt psyko.',
   'episodeNumberOrDate': '10:11',
   'programId': 'msub19121016',
   'seriesId': 'skam',
   'imageId': 'y_aMASKvsNc5AyFXv8qOUA19oBpa8S99QB8Cns59zClg',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1449257400000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1212400,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Man er det man gjør.',
   'episodeNumberOrDate': '9:11',
   'programId': 'msub19120916',
   'seriesId': 'skam',
   'imageId': 'FbdJ3zEUpyr3p0BOvRYuOg3mVOmlofI04qFP793L2wng',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1448652600000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1245560,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Hele skolen hater meg.',
   'episodeNumberOrDate': '8:11',
   'programId': 'msub19120816',
   'seriesId': 'skam',
   'imageId': 'fbhfG_qNbzmD_dG3utVIZgpPD_Y-gDCRckHkNOZ25qsw',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1448047800000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1411720,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Tenker alltid det er meg det er noe galt med.',
   'episodeNumberOrDate': '7:11',
   'programId': 'msub19120716',
   'seriesId': 'skam',
   'imageId': '1utoMjYRYeYyyNza23EwGQQulfG5X4uKFmae24I84vSw',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1447443000000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1186200,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Man vet når gutter lyver.',
   'episodeNumberOrDate': '6:11',
   'programId': 'msub19120616',
   'seriesId': 'skam',
   'imageId': 'j4Q7o6_6FrRQyzMjMgpyCwajMLLdi_SP2SMtr_prfDWg',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1446237720000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1360000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Hva er det som gjør deg kåt?',
   'episodeNumberOrDate': '5:11',
   'programId': 'msub19120516',
   'seriesId': 'skam',
   'imageId': 'Ktwr72o0LsW8m3ea0Dfw1AT7c2ibVtiaVml1oUgzq0Mw',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1445625000000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1138120,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Go for it din lille slut.',
   'episodeNumberOrDate': '4:11',
   'programId': 'msub19120416',
   'seriesId': 'skam',
   'imageId': '2eG9xTGwIpBrE1s-IyWLKw_5Cr6gZz95gsjZWbdCEidg',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1445020200000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 865960,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Vi er de største loserne på skolen.',
   'episodeNumberOrDate': '3:11',
   'programId': 'msub19120316',
   'seriesId': 'skam',
   'imageId': 'uJN6fQRML8WefsCPQsx4gQ7kpU-AjVuepJz6AklA5Zvg',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1444415400000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1003640,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Jonas, dette er helt dust.',
   'episodeNumberOrDate': '2:11',
   'programId': 'msub19120216',
   'seriesId': 'skam',
   'imageId': '6vVJ-pOjuhVhrnZ7fY29uQgGY87PH-dVSgIuvpkcHqnA',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1443810600000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 996800,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'},
  {'title': 'SKAM',
   'description': '– Du ser ut som en slut.',
   'episodeNumberOrDate': '1:11',
   'programId': 'msub19120116',
   'seriesId': 'skam',
   'imageId': 'snaBmCsfSGBEjLkTbzM4NgKO4pSiUDBSCQ7MxI0bpqUw',
   'category': {'categoryId': 'drama-serier', 'displayValue': 'Drama/serier'},
   'categories': [{'categoryId': 'drama-serier',
     'displayValue': 'Drama/serier'}],
   'seasonId': 70522,
   'usageRights': {'availableFrom': 1443205800000,
    'availableTo': 253402210800000,
    'hasNoRights': False,
    'geoblocked': True},
   'legalAge': '12',
   'parts': [],
   'duration': 1168000,
   'isAvailable': True,
   'legalAgeDisplayValue': 'Aldersgrense 12 år'}]}

In [ ]:
json['programs'][0]

In [ ]:
res = r.json()
[(prog['title'], prog['seasonId']) for prog in res['programs']]

In [ ]:
import nrkdownload.nrktv as nrktv
nrktv.parse_search_results(r.json(), "series")

In [ ]:
json['programs']

In [156]:
sum([0 , 0 ,2])


Out[156]:
2

In [ ]:
'test: {}'.format(list(seasons.values()))

In [ ]:
seasons.values()

Program details


In [4]:
string = 'DVFJ67000211'  # This one has several parts
string = 'MSPO46500113'  # This has two parts
# string = 'MYNT13000117'
# string = 'muhr57003018'  # This is a radio program
# string = 'KOID20001217'
string = 'MSUB19120216'
r = session.get(NRK_PS_API + '/mediaelement/' + string)
r.raise_for_status()
json = r.json()
json


Out[4]:
{'_links': {'self': {'href': '/mediaelement/MSUB19120216'},
  'parent': {'href': '/'},
  'next': {'href': '/mediaelement/MSUB19120316'}},
 'id': 'MSUB19120216',
 'title': 'SKAM',
 'description': '– Jonas, dette er helt dust.',
 'mediaElementType': 'Episode',
 'mediaType': 'Video',
 'image': {'id': '6vVJ-pOjuhVhrnZ7fY29uQ',
  'cropInfo': {'x': 0.0, 'y': 0.0, 'width': 1.0, 'height': 1.0}},
 'images': {'imageInfo': {'id': '6vVJ-pOjuhVhrnZ7fY29uQ',
   'cropInfo': {'x': 0.0, 'y': 0.0, 'width': 1.0, 'height': 1.0}},
  'imageWidthCropInfo': '6vVJ-pOjuhVhrnZ7fY29uQ?x=0.00000000000000000&y=0.00000000000000000&w=1.00000000000000000&h=1.00000000000000000',
  'webImages': [{'imageUrl': 'https://gfx.nrk.no/6vVJ-pOjuhVhrnZ7fY29uQMZsT4mvgpOagIuvpkcHqnA',
    'pixelWidth': 300},
   {'imageUrl': 'https://gfx.nrk.no/6vVJ-pOjuhVhrnZ7fY29uQ4WKm064xLeagIuvpkcHqnA',
    'pixelWidth': 600},
   {'imageUrl': 'https://gfx.nrk.no/6vVJ-pOjuhVhrnZ7fY29uQayDUqqwbydagIuvpkcHqnA',
    'pixelWidth': 960},
   {'imageUrl': 'https://gfx.nrk.no/6vVJ-pOjuhVhrnZ7fY29uQgGY87PH-dVSgIuvpkcHqnA',
    'pixelWidth': 1920}],
  'isDefaultImage': False},
 'mediaUrl': 'http://nordond5a-f.akamaihd.net/z/wo/open/b0/b0db32db0e735ffe227820f045cd1434df811ab2/8d153948-ab5d-4767-aaea-87186b80bcad_,141,316,563,1266,2250,.mp4.csmil/manifest.f4m',
 'mediaAssets': [{'url': 'http://nordond5a-f.akamaihd.net/z/wo/open/b0/b0db32db0e735ffe227820f045cd1434df811ab2/8d153948-ab5d-4767-aaea-87186b80bcad_,141,316,563,1266,2250,.mp4.csmil/manifest.f4m',
   'duration': 'PT16M36S',
   'carrierId': 'MSUB19120216AW',
   'webVttSubtitlesUrl': 'https%3a%2f%2fundertekst.nrk.no%2fprod%2fMSUB19%2f12%2fMSUB19120216AW%2fTMP%2fmaster.m3u8',
   'timedTextSubtitlesUrl': 'https%3a%2f%2fundertekst.nrk.no%2fprod%2fMSUB19%2f12%2fMSUB19120216AW%2fTMP%2fMSUB19120216AW.ttml',
   'bufferDuration': None}],
 'bitrateInfo': {'startIndex': 3, 'maxIndex': 4},
 'playerType': 'flash',
 'flashPlayerVersion': '1.13.000',
 'flashPluginVersion': '3.10',
 'isAvailable': True,
 'messageType': 'NoMessage',
 'mediaAnalytics': {'show': 'skam',
  'title': 'skam',
  'category': 'dramaserier',
  'contentLength': '15-20 min',
  'device': 'desktop',
  'playerId': 'flash',
  'deliveryType': 'O',
  'cdnName': 'Akamai',
  'playerInfo': 'desktop'},
 'scoresStatistics': {'springStreamSite': 'nrkstream',
  'springStreamStream': 'programspiller/odm/drama-serier/skam/s01e02.skam.MSUB19120216',
  'springStreamContentType': 'desktop',
  'springStreamProgramId': 'MSUB19120216'},
 'convivaStatistics': {'assetName': 'MSUB19120216-skam-2-11',
  'cdnName': 'AKAMAI',
  'deviceType': 'PC',
  'playerName': 'NRK FLASH',
  'isLive': False,
  'playerVersion': 'Pakke75',
  'contentType': 'N/A',
  'contentId': 'MSUB19120216',
  'episodeName': '2:11',
  'seriesName': 'SKAM',
  'contentLength': 996},
 'messageId': None,
 'isLive': False,
 'usageRights': {'isGeoBlocked': True,
  'availableFrom': '/Date(1443810600000+0200)/',
  'availableTo': '/Date(253402210800000+0100)/',
  'hasRightsNow': True},
 'akamaiBeacon': 'https://ma93-r.analytics.edgekey.net/config/beacon-9484.xml',
 'liveBufferStartTime': None,
 'fullTitle': 'SKAM 2:11',
 'mainTitle': 'SKAM',
 'legalAge': '12',
 'relativeOriginUrl': 'serie/skam/MSUB19120216/sesong-1/episode-2',
 'duration': 'PT16M36.8S',
 'shortIndexPoints': [],
 'hasSubtitles': True,
 'subtitlesDefaultOn': False,
 'subtitlesUrlPath': 'https://undertekst.nrk.no/prod/MSUB19/12/MSUB19120216AW/TMP/MSUB19120216AW.ttml',
 'seriesId': 'skam',
 'seriesTitle': 'SKAM',
 'episodeNumberOrDate': '2:11',
 'externalEmbeddingAllowed': True,
 'startNextEpisode': 10}

In [134]:
import nrkdownload
json['programId'] = string
json['imageId'] = json['image']['id']
program = nrkdownload.nrktv.new_program_from_search_result(json)
program.get_download_details(json)

In [136]:
program.subtitle_urls


Out[136]:
['https://undertekst.nrk.no/prod/KOID20/00/KOID20001217AA/TMP/master.m3u8']

In [91]:
from urllib.parse import unquote, urlparse

In [140]:
u = unquote('https%3a%2f%2fundertekst.nrk.no%2fprod%2fKOID20%2f00%2fKOID20001217AA%2fTMP%2fmaster.m3u8')
p = urlparse(u)

In [151]:
' '.join(['v', 'sdf'])


Out[151]:
'v sdf'

In [149]:
import re
re.sub(r'^https', 'http', None)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-149-a9ccbbb0241a> in <module>()
      1 import re
----> 2 re.sub(r'^https', 'http', None)

~/miniconda3/envs/python3dev/lib/python3.6/re.py in sub(pattern, repl, string, count, flags)
    189     a callable, it's passed the match object and must return
    190     a replacement string to be used."""
--> 191     return _compile(pattern, flags).sub(repl, string, count)
    192 
    193 def subn(pattern, repl, string, count=0, flags=0):

TypeError: expected string or bytes-like object

In [145]:
p.scheme = 'http'
p.geturl()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-145-dc99e28a2c9c> in <module>()
----> 1 p.scheme = 'http'
      2 p.geturl()

AttributeError: can't set attribute

In [73]:
for m in json['mediaAssets']:
    print(m.get('url', None))


http://nordond4b-f.akamaihd.net/z/wo/open/f4/f4dc5a04a7ca5c406f5cc313d4bed5d0d87004a0/a5084291-fb0c-4a48-ba2d-6ea4f834bab7_,141,316,563,1266,2250,.mp4.csmil/manifest.f4m
http://nordond10c-f.akamaihd.net/z/wo/open/fd/fd756ee8949ea417be4345697032973c6221206c/a5084291-fb0c-4a48-ba2d-6ea4f834bab7_,141,316,563,1266,2250,.mp4.csmil/manifest.f4m
http://nordond25a-f.akamaihd.net/z/wo/open/32/32752abdbe87b58125d3330acf4e8e9924d97c95/a5084291-fb0c-4a48-ba2d-6ea4f834bab7_,141,316,563,1266,2250,.mp4.csmil/manifest.f4m
http://nordond33c-f.akamaihd.net/z/wo/open/9d/9dd0247af7da58969085d27c515065e285e00700/9e760f0f-697a-435d-95d7-b1f5a731d14d_,141,316,563,1266,2250,.mp4.csmil/manifest.f4m

In [76]:
import re
re.sub(r'\.net/z/', '.net/i/', 'test')


Out[76]:
'test'

In [ ]:
import nrkdownload

In [ ]:
r = session.get(NRK_PS_API + '/mediaelement/' + 'MUHH48000516')
r.raise_for_status()
json = r.json()
json

In [ ]:
json['mediaAssets'][0]['url']

In [ ]:
# MUHH48000516
r = session.get(NRK_PS_API + '/mediaelement/' + 'mspo46500113')
r.raise_for_status()
json = r.json()
json

In [ ]:
r = session.get(NRK_PS_API + '/mediaelement/' + 'dvfj67000211')
r.raise_for_status()
json = r.json()
json

In [ ]:
json['mediaAssets'][0]['url']

In [ ]:
json['programId'] = 'KOID22008416'
json['imageId'] = json['image']['id']

In [ ]:


In [ ]:
programs = []
programs.append(nrkdownload.nrktv.Program(json))

In [ ]:
nrkdownload.nrktv.ask_for_program_download(programs)

Categories

Get name of all categories


In [ ]:
r = session.get('https://tvapi.nrk.no/v1/categories')
r.raise_for_status()
r.json()

List programs within a category


In [ ]:
r = session.get('https://tvapi.nrk.no/v1/categories/dokumentar')
r.raise_for_status()
r.json()

In [ ]:


In [ ]:
r = session.get('https://tvapi.nrk.no/v1/categories/vitenskap')
r.raise_for_status()
r.json()