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'
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)
In [117]:
hits
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)
In [46]:
hits[2]
Out[46]:
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]:
In [55]:
import datetime
datetime.datetime.fromtimestamp(1534647929000/1000)
Out[55]:
In [62]:
hits[10]['hit'['usageRights']['availableTo']
Out[62]:
In [56]:
datetime.datetime.now()
Out[56]:
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)
In [ ]:
In [15]:
s = hits[0]
s.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']
In [ ]:
json['hits']
In [ ]:
json = r.json()
json['hits']
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]:
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]:
In [ ]:
'test: {}'.format(list(seasons.values()))
In [ ]:
seasons.values()
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]:
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]:
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]:
In [149]:
import re
re.sub(r'^https', 'http', None)
In [145]:
p.scheme = 'http'
p.geturl()
In [73]:
for m in json['mediaAssets']:
print(m.get('url', None))
In [76]:
import re
re.sub(r'\.net/z/', '.net/i/', 'test')
Out[76]:
url = "https://tv.nrk.no/serie/p3-sjekker-ut/MYNT12000317/sesong-1/episode-3" parsed_url = urlpar
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)
In [ ]:
r = session.get('https://tvapi.nrk.no/v1/categories')
r.raise_for_status()
r.json()
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()