Skip to content

Commit

Permalink
Weer wat fixxes gemaakt.
Browse files Browse the repository at this point in the history
  • Loading branch information
Opvolger committed Dec 16, 2023
1 parent 01b6e1f commit 94701f7
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 64 deletions.
5 changes: 3 additions & 2 deletions addon.py
Expand Up @@ -14,6 +14,7 @@

from resources.lib.uzg import Uzg
from resources.lib.npoapiclasses import AddonItems
from typing import List

from urllib.parse import urlencode
from urllib.parse import parse_qsl
Expand Down Expand Up @@ -54,7 +55,7 @@ def homeMenu():
xbmcplugin.addDirectoryItem(_handle, url, list_item, is_folder)
xbmcplugin.endOfDirectory(_handle)

def addItems(addonitems: list[AddonItems], action):
def addItems(addonitems: List[AddonItems], action):
xbmcplugin.setPluginCategory(_handle, action)
if addonitems:
if addonitems[0].kodiInfo.isPlayable:
Expand Down Expand Up @@ -102,7 +103,7 @@ def router(paramstring):
playVideo(params['productId'])
else:
# action will give list of items from api
items = Uzg.getItems(params['action'], params['guid'], params['productId'], params['slug'], text)
items = uzg.getItems(params['action'], params['guid'], params['productId'], params['slug'], text)
if items:
addItems(items, params['action'])
else:
Expand Down
2 changes: 1 addition & 1 deletion addon.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.uzg" name="NPO Start" provider-name="Bas Magré (Opvolger)" version="4.0.1">
<addon id="plugin.video.uzg" name="NPO Start" provider-name="Bas Magré (Opvolger)" version="4.0.2">
<requires>
<import addon="script.module.inputstreamhelper" version="0.5.2" />
</requires>
Expand Down
7 changes: 6 additions & 1 deletion changelog.txt
@@ -1,4 +1,9 @@
Version 4.0.1
Version 4.0.2
* Alleen zien wat "Free" is maar nu beter
* Fix wat overzichten
* Fix website update

Version 4.0.1
* Alleen zien wat "Free" is

Version 4.0.0
Expand Down
71 changes: 36 additions & 35 deletions resources/lib/npoapiclasses.py
@@ -1,5 +1,6 @@
from resources.lib.npoapihelpers import NpoHelpers
from datetime import datetime
from typing import List

class KodiInfo(object):
def __init__(self, item, art = None) -> None:
Expand Down Expand Up @@ -42,22 +43,29 @@ class JsonToItems(object):
@staticmethod
def getItems(json):
# TODO paging
uzgitemlist = list()
uzgitemlist: List[AddonItems] = []
items = json # nome times items are direct, sometimes in item
if 'items' in json:
items = json['items'] # nome times items are direct, sometimes in item
for item in items:
addItem = True
restrictionPremium = False
restrictionFree = False
if 'restrictions' in item:
for restriction in item['restrictions']:
for restriction in item['restrictions']:
if restriction['subscriptionType'] == "premium":
restrictionPremium = True
if restriction['subscriptionType'] == "free":
restrictionFree = True
if restriction['available']['from']:
if restriction['available']['from'] <= int(datetime.now().timestamp()) <= restriction['available']['till']:
now = int(datetime.now().timestamp())
if restriction['available']['from'] <= now <= restriction['available']['till']:
addItem = True
else:
addItem = False
else:
addItem = True
if restrictionPremium and restrictionFree == False:
# only Premium members
addItem = False
if (addItem):
productId = None
slug = None
Expand All @@ -75,18 +83,23 @@ def getItems(json):
return uzgitemlist

class EpisodesOfSerieItems(object):
def __init__(self, guid):
self.guid = guid

def getItems(self) -> list[AddonItems]:
url = 'https://npo.nl/start/api/domain/programs-by-series?seriesGuid={}&sort=-firstBroadcastDate'.format(self.guid)
def getItems(self, guid) -> List[AddonItems]:
url = 'https://npo.nl/start/api/domain/programs-by-series?seriesGuid={}&sort=-firstBroadcastDate'.format(guid)
return JsonToItems.getItems(NpoHelpers.getJsonData(url))

class AllItems(object):
def getItems(self) -> list[AddonItems]:
url = 'https://npo.nl/start/_next/data/9gPO_EpYVoXUgPbn57qRY/categorie/programmas.json?slug=programmas'
def __init__(self):
self.buildId = None

def getBuildId(self):
if (self.buildId == None):
url = 'https://npo.nl/start/categorie/programmas'
self.buildId = NpoHelpers.getBuildId(url)
return self.buildId

def getItems(self, url) -> List[AddonItems]:
result = NpoHelpers.getJsonData(url)
uzgitemlist = list()
uzgitemlist: List[AddonItems] = []
for collection in result['pageProps']['dehydratedState']['queries'][0]['state']['data']['collections']:
url = 'https://npo.nl/start/api/domain/page-collection?guid={}'.format(collection['guid'])
result = NpoHelpers.getJsonData(url)
Expand All @@ -98,38 +111,26 @@ def getItems(self) -> list[AddonItems]:
return uzgitemlist

class CollectionItems(object):
def __init__(self, guid):
self.guid = guid

def getItems(self) -> list[AddonItems]:
url = 'https://npo.nl/start/api/domain/page-collection?guid={}'.format(self.guid)
def getItems(self, guid) -> List[AddonItems]:
url = 'https://npo.nl/start/api/domain/page-collection?guid={}'.format(guid)
return JsonToItems.getItems(NpoHelpers.getJsonData(url))

class EpisodesOfSeasonItems(object):
def __init__(self, guid):
self.guid = guid

def getItems(self) -> list[AddonItems]:
url = 'https://npo.nl/start/api/domain/programs-by-season?guid={}&sort=-firstBroadcastDate'.format(self.guid)
def getItems(self, guid) -> List[AddonItems]:
url = 'https://npo.nl/start/api/domain/programs-by-season?guid={}&sort=-firstBroadcastDate'.format(guid)
return JsonToItems.getItems(NpoHelpers.getJsonData(url))

class SeasonItems(object):
def __init__(self, slug):
self.slug = slug

def getItems(self) -> list[AddonItems]:
url = 'https://npo.nl/start/api/domain/series-seasons?slug={}'.format(self.slug)
def getItems(self, slug) -> List[AddonItems]:
url = 'https://npo.nl/start/api/domain/series-seasons?slug={}'.format(slug)
return JsonToItems.getItems(NpoHelpers.getJsonData(url))

class QueryItems(object):
def __init__(self, text):
self.url = 'https://npo.nl/start/api/domain/search-results?query={}&searchType=series&subscriptionType=anonymous'.format(text.replace(' ', '%20'))


def getItems(self) -> list[AddonItems]:
return JsonToItems.getItems(NpoHelpers.getJsonData(self.url))
def getItems(self, text) -> List[AddonItems]:
url = 'https://npo.nl/start/api/domain/search-results?query={}&searchType=series&subscriptionType=anonymous'.format(text.replace(' ', '%20'))
return JsonToItems.getItems(NpoHelpers.getJsonData(url))

class Channels(object):
def getItems(self) -> list[AddonItems]:
def getItems(self) -> List[AddonItems]:
url = 'https://npo.nl/start/api/domain/guide-channels'
return JsonToItems.getItems(NpoHelpers.getJsonData(url))
29 changes: 26 additions & 3 deletions resources/lib/npoapihelpers.py
@@ -1,8 +1,9 @@
import json
import json, re

from datetime import datetime
from resources.lib.jsonhelper import ToJsonObject
from urllib.request import urlopen, Request
from typing import List

class NpoHelpers():

Expand All @@ -15,6 +16,23 @@ def getPlayInfo(externalId):
licenseKey = NpoHelpers.getLicenseKey(info["stream"]["drmToken"])
return info, licenseKey

@staticmethod
def getBuildId(url):
req = Request(url)
req.add_header(
'User-Agent',
'Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36')
req.add_header('Content-Type', 'application/json; charset=utf-8')
response = urlopen(req)
website = response.read()
response.close()

regex = r"buildId\":\"([A-z0-9]*)"

match = re.findall(regex, str(website))
if match:
return match[0]

@staticmethod
def getJsonData(url):
req = Request(url)
Expand Down Expand Up @@ -135,6 +153,11 @@ def getAction(item):
return 'episodesSerie'
if item['type'] == "timebound_series":
return 'seasons'
if item['type'] == "umbrella_series":
return 'collection'
print(item['type'])
if 'slug' in item:
return 'webcollectie'
return 'unknown'

@staticmethod
Expand Down Expand Up @@ -190,7 +213,7 @@ def getPremiered(item):

@staticmethod
def getStudio(item):
broadcasters = list()
broadcasters: List[str] = []
if 'broadcasters' in item:
if item['broadcasters']:
for broadcaster in item['broadcasters']:
Expand All @@ -200,7 +223,7 @@ def getStudio(item):

@staticmethod
def getGenres(item):
genres = list()
genres: List[str] = []
if 'genres' in item:
if item['genres']:
for genre in item['genres']:
Expand Down
34 changes: 23 additions & 11 deletions resources/lib/uzg.py
Expand Up @@ -9,9 +9,18 @@

from resources.lib.npoapihelpers import NpoHelpers
from resources.lib.npoapiclasses import AddonItems, QueryItems, SeasonItems, Channels, SeasonItems, EpisodesOfSeasonItems, EpisodesOfSerieItems, AllItems, CollectionItems
from typing import List

class Uzg:

def __init__(self):
self.channels = Channels()
self.allItems = AllItems()
self.queryItems = QueryItems()
self.episodesOfSeasonItems = EpisodesOfSeasonItems()
self.episodesOfSerieItems = EpisodesOfSerieItems()
self.collectionItems = CollectionItems()
self.seasonItems = SeasonItems()

@staticmethod
def getPlayInfo(externalId):
token = NpoHelpers.getToken(externalId)
Expand All @@ -21,22 +30,25 @@ def getPlayInfo(externalId):
licenseKey = NpoHelpers.getLicenseKey(info["stream"]["drmToken"])
return info, licenseKey

@staticmethod
def getItems(action, guid = None, productId = None, slug = None, text = None) -> list[AddonItems]:
def getItems(self, action, guid = None, productId = None, slug = None, text = None) -> List[AddonItems]:
if action == 'Live kanalen':
return Channels().getItems()
return self.channels.getItems()
elif action == 'Alle programmas':
return AllItems().getItems()
buildId = self.allItems.getBuildId()
return self.allItems.getItems('https://npo.nl/start/_next/data/{}/categorie/programmas.json?slug=programmas'.format(buildId))
elif action == 'webcollectie':
buildId = self.allItems.getBuildId()
return self.allItems.getItems('https://npo.nl/start/_next/data/{}/collectie/{}.json?slug={}'.format(buildId, slug, slug))
elif action == 'Zoeken':
if text:
return QueryItems(text).getItems()
return list()
return self.queryItems.getItems(text)
return List()
elif action == 'episodesSeason':
return EpisodesOfSeasonItems(guid).getItems()
return self.episodesOfSeasonItems.getItems(guid)
elif action == 'episodesSerie':
return EpisodesOfSerieItems(guid).getItems()
return self.episodesOfSerieItems.getItems(guid)
elif action == 'collection':
return CollectionItems(guid).getItems()
return self.collectionItems.getItems(guid)
elif action == 'seasons':
return SeasonItems(slug).getItems()
return self.seasonItems.getItems(slug)
return None
25 changes: 14 additions & 11 deletions uzgtest.py
@@ -1,7 +1,9 @@
from resources.lib.uzg import Uzg
from resources.lib.npoapihelpers import NpoHelpers
from resources.lib.npoapiclasses import AddonItems
from typing import List

uzg = Uzg()

a = NpoHelpers.getToken('LI_NL3_4188107')

Expand All @@ -27,39 +29,40 @@

info, licenseKey = Uzg.getPlayInfo('VARA_101381121')

def loopItems(items: list[AddonItems]):
def loopItems(items: List[AddonItems]):
for item in items:
print(item.kodiInfo.label)
print(item.kodiInfo.action)
print(item.npoInfo.productId)
print(item.npoInfo.guid)
print(item.npoInfo.slug)
print(item.kodiInfo.isFolder)
print(item.kodiInfo.isPlayable)
print('---')


# https://npo.nl/start/api/domain/guide-channels
loopItems(Uzg.getItems('Live kanalen'))
loopItems(uzg.getItems('Live kanalen'))

# https://npo.nl/start/api/domain/search-results?query=bijna&searchType=series&subscriptionType=anonymous
loopItems(Uzg.getItems('Zoeken', text="bijna"))
loopItems(uzg.getItems('Zoeken', text="bijna"))

# https://npo.nl/start/api/domain/series-seasons?slug=freeks-wilde-wereld
loopItems(Uzg.getItems('seasons', slug="freeks-wilde-wereld"))
loopItems(uzg.getItems('seasons', slug="freeks-wilde-wereld"))

# https://npo.nl/start/api/domain/programs-by-season?guid=7e1d457a-ec0f-4c25-853d-2085e55567b7&sort=-firstBroadcastDate
loopItems(Uzg.getItems('episodesSeason', guid='7e1d457a-ec0f-4c25-853d-2085e55567b7'))
loopItems(uzg.getItems('episodesSeason', guid='7e1d457a-ec0f-4c25-853d-2085e55567b7'))

# https://npo.nl/start/api/domain/programs-by-series?seriesGuid=5328ea0b-beff-4c14-959e-675cc6eb8261&sort=-firstBroadcastDate
loopItems(Uzg.getItems('episodesSerie', guid='5328ea0b-beff-4c14-959e-675cc6eb8261'))
loopItems(uzg.getItems('episodesSerie', guid='5328ea0b-beff-4c14-959e-675cc6eb8261'))

# https://npo.nl/start/_next/data/9gPO_EpYVoXUgPbn57qRY/categorie/programmas.json?slug=programmas
loopItems(Uzg.getItems('Alle programmas'))

# https://npo.nl/start/api/domain/page-collection?guid=bcd8b931-c2df-4d53-9bcf-01faa4ac7050
loopItems(Uzg.getItems('collection', guid='bcd8b931-c2df-4d53-9bcf-01faa4ac7050')) # SERIES
loopItems(Uzg.getItems('collection', guid='9443ce0c-b219-4f29-ba55-a96aca95beae')) # PROGRAM
items = uzg.getItems('Alle programmas')
loopItems(items)

for item in items:
loopItems(uzg.getItems(item.kodiInfo.action, guid=item.npoInfo.guid, slug=item.npoInfo.slug))
print('---')

# {
# "guid": "2042e1ee-0e79-4766-aea2-5b300d6839b2",
Expand Down

0 comments on commit 94701f7

Please sign in to comment.