Exemplo n.º 1
0
    def _get_oesp_token(self):
        refresh_token = PluginCache.get_by_key("refreshToken")

        json_payload = {
            "refreshToken": refresh_token,
            "username": self.username
        }

        r = Utils.make_request(
            self.session,
            method="POST",
            url=
            "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/session?token=true",
            headers=self.construct_header(),
            data=json_payload)

        json_data = r.json()

        oesp_token = json_data["oespToken"]
        shared_profile_id = json_data["customer"]["sharedProfileId"]
        entitlements = json_data["entitlements"]

        PluginCache.set_data({
            "oespToken": oesp_token,
            "sharedProfileId": shared_profile_id,
            "entitlements": entitlements
        })
Exemplo n.º 2
0
    def _get_refresh_token(self):
        token = PluginCache.get_by_key("token")
        validity_token = PluginCache.get_by_key("validityToken")
        state = PluginCache.get_by_key("state")

        json_payload = {
            "authorizationGrant": {
                "authorizationCode": token,
                "validityToken": validity_token,
                "state": state
            }
        }

        r = Utils.make_request(
            self.session,
            method="POST",
            url=
            "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/authorization",
            headers=self.construct_header(),
            data=json_payload)

        json_data = r.json()

        refresh_token = json_data["refreshToken"]

        PluginCache.set_data({
            "refreshToken": refresh_token,
        })
Exemplo n.º 3
0
    def refresh_token(self):
        r = Utils.make_request(
            self.session,
            method="GET",
            url="https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/session",
            headers=self.construct_header())

        json_data = r.json()

        oesp_token = json_data["oespToken"]
        PluginCache.set_data({"oespToken": oesp_token})
Exemplo n.º 4
0
    def __init__(self, session, logger_instance=None):
        super(self.__class__, self).__init__(session)
        self.logger = logger_instance

        self.device_id = PluginCache.get_by_key("deviceId")
        self.oesp_token = PluginCache.get_by_key("oespToken")
        self.shared_profile_id = PluginCache.get_by_key("sharedProfileId")
        self.license_token = ""

        if self.must_login():
            self.web_authorization()
            self.authorize()
            self.login()
            self.request_tokens()

        self._check_oesp_validity()
Exemplo n.º 5
0
    def web_authorization(self):
        r = Utils.make_request(
            self.session,
            method="GET",
            url=
            "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/authorization",
            headers=self.construct_header())

        json_data = r.json()

        self.authorization_uri = json_data["session"]["authorizationUri"]

        validity_token = json_data["session"]["validityToken"]
        state = json_data["session"]["state"]

        PluginCache.set_data({"validityToken": validity_token, "state": state})
Exemplo n.º 6
0
    def login(self):
        r = Utils.make_request(
            self.session,
            method="POST",
            url="https://login.prd.telenet.be/openid/login.do",
            headers=self.construct_header(
                content_type="application/x-www-form-urlencoded"),
            data={
                'j_username': '******'.format(self.username),
                'j_password': '******'.format(self.passwd),
                'rememberme': 'true'
            },
            is_json=False)

        last_response = r.history[-1]

        if "Location" in last_response.headers:
            token = Utils.extract_auth_token(
                last_response.headers.get('Location'))

            PluginCache.set_data({"token": token, "username": self.username})
Exemplo n.º 7
0
    def request_license_token(self, content_locator):
        # retry once
        for _ in range(2):
            status_code, json_data = self._request_license_token(
                content_locator)

            if status_code == 200:
                license_token = json_data.get("token")

                PluginCache.set_data({"licenseToken": license_token})

                break
            elif status_code == 400:
                new_device_id = Utils.create_token(64)
                bad_request = BadRequest.parse_error_object(json_data)

                if bad_request.code == BadRequest.KnownErrorCodes.DEVICE_UNREGISTERED:
                    self._register_device(new_device_id)
                    PluginCache.set_data({"deviceId": new_device_id})
                elif bad_request.code == BadRequest.KnownErrorCodes.DEVICE_UNREGISTERED_DEVICE_LIMIT_REACHED:
                    # get the existing registered devices
                    existing_devices = self.get_registered_device_list()

                    # select a random device to swap
                    random_device = random.choice(existing_devices)

                    # replace registered device with the randomly selected one
                    self.replace_registered_device(random_device.device_id,
                                                   new_device_id)
                    PluginCache.set_data({"deviceId": new_device_id})
Exemplo n.º 8
0
    def create_manifest_url(self, base_uri, channel):
        self.license_token = PluginCache.get_by_key("licenseToken")

        streaming_format = StreamingFormat.get_streaming_format()
        if streaming_format == StreamingFormat.MPEG_DASH:
            url = Stream.BASE_URL_MPD
        elif streaming_format == StreamingFormat.SMOOTH_STREAM:
            url = Stream.BASE_URL_HSS
        else:
            url = ""

        formatted_url = url.format(base_uri, channel, self.license_token)

        return formatted_url
Exemplo n.º 9
0
 def must_login():
     return not PluginCache.key_exists(
         "oespToken") or not PluginCache.key_exists("token")
Exemplo n.º 10
0
    def get_channels(self):
        r = Utils.make_request(
            self.session,
            method="GET",
            headers=self.construct_header(),
            url="https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/channels?"
            "includeInvisible=false"
            "&sort=channelNumber")

        json_data = r.json()

        useful_channel_data = []
        entitlements = PluginCache.get_by_key("entitlements")

        if not entitlements:
            return useful_channel_data

        if "channels" in json_data:
            fetched_channel_data = json_data["channels"]
            for channel_data in fetched_channel_data:
                station = channel_data["stationSchedules"][0]["station"]
                video_streams = station["videoStreams"]

                if video_streams:
                    channel = Channel(channel_data["id"], station["id"],
                                      channel_data["title"],
                                      channel_data["channelNumber"],
                                      bool(station["hasLiveStream"]),
                                      station["entitlements"])

                    if not any(x in entitlements
                               for x in channel.entitlements):
                        continue

                    HLS_stream = {}
                    DASH_stream = {}
                    HSS_stream = {}

                    for video_stream in video_streams:
                        if "Orion-HLS" in video_stream["assetTypes"]:
                            HLS_stream = Stream(video_stream["streamingUrl"],
                                                video_stream["contentLocator"],
                                                video_stream["protectionKey"])

                        if "Orion-DASH" in video_stream["assetTypes"]:
                            DASH_stream = Stream(
                                video_stream["streamingUrl"],
                                video_stream["contentLocator"],
                                video_stream["protectionKey"])

                        if "Orion-HSS" in video_stream["assetTypes"]:
                            HSS_stream = Stream(video_stream["streamingUrl"],
                                                video_stream["contentLocator"],
                                                video_stream["protectionKey"])

                    thumbnail = [
                        img["url"] for img in station["images"]
                        if img["assetType"] == "station-logo-xlarge"
                    ][0]

                    imageStream = [
                        img["url"] for img in station["images"]
                        if img["assetType"] == "imageStream"
                    ][0]

                    channel.thumbnail = thumbnail
                    channel.stream_thumbnail = imageStream
                    channel.stream_DASH = DASH_stream
                    channel.stream_HLS = HLS_stream
                    channel.stream_HSS = HSS_stream

                    useful_channel_data.append(channel)

        return useful_channel_data
Exemplo n.º 11
0
from resources.lib.Classes.Stream import Stream
from resources.lib.Utils.PluginCache import PluginCache
from resources.lib.Classes.StreamingFormat import StreamingFormat
import random
import json
import base64
from datetime import datetime, timedelta
import time

from resources.lib.kodiwrapper import KodiWrapper

DEVICE_NAME = "Mijn computer - Google Chrome"
DEVICE_CLASS = "other"
TOKEN_EXPIRY_GAP_MINUTES = 30

if not PluginCache.key_exists("deviceId"):
    PluginCache.set_data({
        "deviceId":
        "fe88cd8ace897d72c78441f648a2f92a4e298cced867179932d7c2751d79fb83"
    })


class BadRequest(object):
    class KnownErrorCodes:
        DEVICE_UNREGISTERED = "deviceUnregistered"
        DEVICE_UNREGISTERED_DEVICE_LIMIT_REACHED = "deviceUnregisteredDeviceLimitReached"

    def __init__(self, error_type="", code="", reason=""):
        self.type = error_type
        self.code = code
        self.reason = reason