Example #1
0
    def sign_resource(self, provider_id, resource_id, video_id, player, version):
        proxy = control.proxy_url
        proxy = None if proxy is None or proxy == '' else {
            'http': proxy,
            'https': proxy,
        }

        provider = control.setting('globosat_provider').lower().replace(' ', '_')
        username = control.setting('globosat_username')
        password = control.setting('globosat_password')

        # authenticate
        authenticator = getattr(auth, provider)()
        credentials = authenticator.authenticate(provider_id, username, password)

        hash_url = 'https://security.video.globo.com/videos/%s/hash?resource_id=%s&version=%s&player=%s' % (video_id, resource_id, PLAYER_VERSION, PLAYER_SLUG)
        hash_json = client.request(hash_url, cookie=credentials, mobile=True, headers={"Accept-Encoding": "gzip"}, proxy=proxy)

        if not hash_json or hash_json is None or 'message' in hash_json and hash_json['message']:
            control.infoDialog(message=control.lang(34102).encode('utf-8'), sound=True, icon='ERROR')
            return None

        hash = util.get_signed_hashes(hash_json['hash'])[0]

        return hash, hash_json["user"] if 'user' in hash_json else None, credentials
Example #2
0
    def sign_resource(self, provider_id, resource_id, video_id, player,
                      version):
        proxy = control.proxy_url
        proxy = None if proxy is None or proxy == '' else {
            'http': proxy,
            'https': proxy,
        }

        credentials = auth_helper.get_globosat_cookie(provider_id)

        hash_url = 'https://security.video.globo.com/videos/%s/hash?resource_id=%s&version=%s&player=%s' % (
            video_id, resource_id, PLAYER_VERSION, PLAYER_SLUG)
        hash_json = client.request(hash_url,
                                   cookie=credentials,
                                   mobile=True,
                                   headers={"Accept-Encoding": "gzip"},
                                   proxy=proxy)

        if not hash_json or hash_json is None or 'message' in hash_json and hash_json[
                'message']:
            control.infoDialog(message=control.lang(34102).encode('utf-8'),
                               sound=True,
                               icon='ERROR')
            return None

        hash = util.get_signed_hashes(hash_json['hash'])[0]

        return hash, hash_json[
            "user"] if 'user' in hash_json else None, credentials
Example #3
0
    def __getLiveVideoInfo(self, id, geolocation):

        proxy = control.proxy_url
        proxy = None if proxy is None or proxy == '' else {
            'http': proxy,
            'https': proxy,
        }

        credentials = auth_helper.get_credentials()

        if credentials is None:
            return None

        post_data = "%s&player=%s&version=%s" % (geolocation, PLAYER_SLUG,
                                                 PLAYER_VERSION)

        # 4452349
        hashUrl = 'http://security.video.globo.com/videos/%s/hash' % id
        hashJson = client.request(hashUrl,
                                  error=True,
                                  cookie=credentials,
                                  mobile=True,
                                  headers={
                                      "Accept-Encoding": "gzip",
                                      "Content-Type":
                                      "application/x-www-form-urlencoded",
                                      "User-Agent": "Globo Play/0 (iPhone)"
                                  },
                                  post=post_data,
                                  proxy=proxy)

        hash = get_signed_hashes(hashJson['hash'])[0]

        return {
            "id": "-1",
            "title": hashJson["name"],
            # "program": playlistJson["program"],
            # "program_id": playlistJson["program_id"],
            # "provider_id": playlistJson["provider_id"],
            # "channel": playlistJson["channel"],
            # "channel_id": playlistJson["channel_id"],
            "category": 'Live',
            # "subscriber_only": playlistJson["subscriber_only"],
            "subscriber_only": 'true',
            # "exhibited_at": playlistJson["exhibited_at"],
            "player": PLAYER_SLUG,
            "url": hashJson["url"],
            "query_string_template":
            "h={{hash}}&k={{key}}&a={{openClosed}}&u={{user}}",
            "thumbUri": hashJson["thumbUri"],
            "hash": hash,
            "user": hashJson["user"],
            "credentials": credentials,
            "encrypted": False
        }
Example #4
0
    def sign_resource(self,
                      provider_id,
                      resource_id,
                      video_id,
                      player,
                      version,
                      cdn=None):
        proxy = control.proxy_url
        proxy = None if proxy is None or proxy == '' else {
            'http': proxy,
            'https': proxy,
        }

        credentials = auth_helper.get_globosat_cookie(provider_id)

        hash_url = 'https://security.video.globo.com/videos/%s/hash?resource_id=%s&version=%s&player=%s' % (
            video_id, resource_id, PLAYER_VERSION, PLAYER_SLUG)
        if cdn:
            hash_url = hash_url + '&cdn=' + cdn
        control.log('GET %s' % hash_url)
        response = requests.get(hash_url,
                                cookies=credentials,
                                headers={"Accept-Encoding": "gzip"},
                                proxies=proxy)
        response.raise_for_status()

        hash_json = response.json()

        control.log(hash_json)

        if not hash_json or hash_json is None or 'message' in hash_json and hash_json[
                'message']:
            message = hash_json[
                'message'] if hash_json and 'message' in hash_json else control.lang(
                    34102)
            message = str(
                hash_json['http_status_code']) + u'|' + message.encode(
                    'utf-8'
                ) if hash_json and 'http_status_code' in hash_json else message
            control.infoDialog(message=message.encode('utf-8'),
                               sound=True,
                               icon='ERROR')
            raise Exception(message)

        hash_token = util.get_signed_hashes(
            hash_json['hash']
        )[0] if 'hash' in hash_json else hash_json['token']
        user = hash_json["user"] if 'user' in hash_json else None
        return hash_token, user, credentials
Example #5
0
    def sign_resource(self,
                      resource_id,
                      video_id,
                      player,
                      version,
                      anonymous=False,
                      cdn=None):
        proxy = control.proxy_url
        proxy = None if proxy is None or proxy == '' else {
            'http': proxy,
            'https': proxy,
        }

        if not anonymous:
            # authenticate
            credentials = auth_helper.get_credentials()
        else:
            credentials = None

        hash_url = 'https://security.video.globo.com/videos/%s/hash?resource_id=%s&version=%s&player=%s' % (
            video_id, resource_id, PLAYER_VERSION, PLAYER_SLUG)
        if cdn:
            hash_url = hash_url + '&cdn=' + cdn

        control.log('GET %s' % hash_url)
        response = requests.get(hash_url,
                                cookies=credentials,
                                headers={"Accept-Encoding": "gzip"},
                                proxies=proxy)

        response.raise_for_status()

        hash_json = response.json()

        if not hash_json or ('hash' not in hash_json
                             and 'token' not in hash_json):
            message = (hash_json or {}
                       ).get('message') or control.lang(34101).encode('utf-8')
            control.log(hash_json or message, control.LOGERROR)
            control.infoDialog(message=message, sound=True, icon='ERROR')
            control.idle()
            sys.exit()

        hash_token = get_signed_hashes(
            hash_json['hash']
        )[0] if 'hash' in hash_json else hash_json['token']

        return hash_token, hash_json.get('user'), credentials
Example #6
0
    def sign_resource(self,
                      resource_id,
                      video_id,
                      player,
                      version,
                      anonymous=False):
        proxy = control.proxy_url
        proxy = None if proxy is None or proxy == '' else {
            'http': proxy,
            'https': proxy,
        }

        if not anonymous:
            username = control.setting('globoplay_username')
            password = control.setting('globoplay_password')

            # authenticate
            credentials = auth.auth().authenticate(username, password)
        else:
            credentials = None

        hashUrl = 'https://security.video.globo.com/videos/%s/hash?resource_id=%s&version=%s&player=%s' % (
            video_id, resource_id, PLAYER_VERSION, PLAYER_SLUG)
        hashJson = client.request(hashUrl,
                                  cookie=credentials,
                                  mobile=False,
                                  headers={"Accept-Encoding": "gzip"},
                                  proxy=proxy)

        if not hashJson or 'hash' not in hashJson:
            control.infoDialog(message=control.lang(34101).encode('utf-8'),
                               sound=True,
                               icon='ERROR')
            control.idle()
            sys.exit()
            return None

        hash = get_signed_hashes(hashJson['hash'])[0]

        return hash, hashJson[
            'user'] if 'user' in hashJson else None, credentials
Example #7
0
    def play_vod(self, id, meta):

        self.retry = 0

        control.log("PLAY SEXYHOT - ID: %s" % id)

        if id is None:
            return

        id = self.__get_globo_id(id)

        control.log('globo_midia_id: %s' % str(id))

        if id is None:
            return

        info = self.__get_video_info(id)

        if info is None:
            return

        title = info['title']

        signed_hashes = get_signed_hashes(info['hash'])

        query_string = re.sub(r'{{(\w*)}}', r'%(\1)s',
                              info['query_string_template'])

        query_string = query_string % {
            'hash': signed_hashes[0],
            'key': 'html5'
        }

        url = '?'.join([info['url'], query_string])

        control.log("live media url: %s" % url)

        try:
            meta = json.loads(meta)
        except:
            meta = {
                "playcount": 0,
                "overlay": 6,
                "title": title,
                "thumb": None,
                "mediatype": "video"
            }

        meta.update({
            "genre": info["category"],
        })

        poster = meta['poster'] if 'poster' in meta else control.addonPoster()
        thumb = meta['thumb'] if 'thumb' in meta else info["thumbUri"]

        url, mime_type, stopEvent = hlshelper.pick_bandwidth(url)
        control.log("Resolved URL: %s" % repr(url))

        item = control.item(path=url)
        item.setArt({
            'icon': thumb,
            'thumb': thumb,
            'poster': poster,
            'tvshow.poster': poster,
            'season.poster': poster
        })
        item.setProperty('IsPlayable', 'true')
        item.setInfo(type='Video', infoLabels=meta)

        if mime_type:
            item.setMimeType(mime_type)

        item.setContentLookup(False)

        control.resolve(int(sys.argv[1]), id != None, item)

        self.stopPlayingEvent = threading.Event()
        self.stopPlayingEvent.clear()

        while not self.stopPlayingEvent.isSet():
            if control.monitor.abortRequested():
                control.log("Abort requested")
                break
            control.sleep(500)

        if stopEvent:
            control.log("Setting stop event for proxy player")
            stopEvent.set()
Example #8
0
    def play_stream(self, id, meta):

        if id == None: return

        try:
            meta = json.loads(meta)
        except:
            meta = {
                "playcount": 0,
                "overlay": 6,
                "mediatype": "video",
                "aired": None
            }

        is_live = False

        if 'live' in meta and meta['live'] == True:
            is_live = True
            info = self.__getLiveVideoInfo(
                id, meta['affiliate'] if 'affiliate' in meta else None)
        else:
            info = self.__getVideoInfo(id)

        title = meta['title'] if 'title' in meta else info['title']

        signed_hashes = get_signed_hashes(info['hash'])

        query_string = re.sub(r'{{(\w*)}}', r'%(\1)s',
                              info['query_string_template'])

        query_string = query_string % {
            'hash': signed_hashes[0],
            'key': 'app',
            'openClosed': 'F',
            'user': info['user'] if info['subscriber_only'] else ''
        }

        url = '?'.join([info['url'], query_string])

        control.log("live media url: %s" % url)

        meta.update({
            "genre": info["category"],
            "plot": info["title"],
            "plotoutline": info["title"],
            "title": title
        })

        poster = meta['poster'] if 'poster' in meta else control.addonPoster()
        thumb = meta['thumb'] if 'thumb' in meta else info["thumbUri"]

        syshandle = int(sys.argv[1])

        # self.offset = float(meta['milliseconds_watched']) / 1000.0 if 'milliseconds_watched' in meta else 0

        self.isLive = 'live' in meta and meta['live'] == True

        self.url, mime_type, stopEvent = hlshelper.pickBandwidth(url)
        control.log("Resolved URL: %s" % repr(self.url))

        item = control.item(path=self.url)
        item.setInfo(type='video', infoLabels=meta)
        item.setArt({
            'icon': thumb,
            'thumb': thumb,
            'poster': poster,
            'tvshow.poster': poster,
            'season.poster': poster
        })
        item.setProperty('IsPlayable', 'true')

        if mime_type:
            item.setMimeType(mime_type)

        item.setContentLookup(False)

        control.resolve(syshandle, True, item)

        self.stopPlayingEvent = threading.Event()
        self.stopPlayingEvent.clear()

        last_time = 0.0
        while not self.stopPlayingEvent.isSet():
            if control.monitor.abortRequested():
                control.log("Abort requested")
                break
            control.log("IS PLAYING: %s" % self.isPlaying())
            if not is_live and self.isPlaying():
                total_time = self.getTotalTime()
                current_time = self.getTime()
                if current_time - last_time > 10 or (last_time == 0
                                                     and current_time > 1):
                    last_time = current_time
                    percentage_watched = current_time / total_time if total_time > 0 else 1.0 / 1000000.0
                    self.save_video_progress(
                        info['credentials'],
                        info['program_id'],
                        info['id'],
                        current_time / 1000.0,
                        fully_watched=percentage_watched > 0.9
                        and percentage_watched <= 1)
            control.sleep(1000)

        if stopEvent:
            control.log("Setting stop event for proxy player")
            stopEvent.set()

        control.log("Done playing. Quitting...")
    def playlive(self, id, meta):

        if id is None: return

        info = self.__get_video_info(id)

        if not info or 'channel' not in info:
            return

        if 'encrypted' in info and info['encrypted'] == 'true':
            control.infoDialog(message=control.lang(34103).encode('utf-8'), icon='Wr')
            return

        title = info['channel']

        signed_hashes = util.get_signed_hashes(info['hash'])

        query_string = re.sub(r'{{(\w*)}}', r'%(\1)s', info['query_string_template'])

        query_string = query_string % {
            'hash': signed_hashes[0],
            'key': 'app',
            'openClosed': 'F' if info['subscriber_only'] else 'A',
            'user': info['user'] if info['subscriber_only'] else ''
        }

        url = '?'.join([info['url'], query_string])

        control.log("live media url: %s" % url)

        try:
            meta = json.loads(meta)
        except:
            meta = {
                "playcount": 0,
                "overlay": 6,
                "title": title,
                "thumb": info["thumbUri"],
                "mediatype": "video",
                "aired": info["exhibited_at"]
            }

        meta.update({
            "genre": info["category"],
            "plot": info["title"],
            "plotoutline": info["title"]
        })

        poster = meta['poster'] if 'poster' in meta else control.addonPoster()
        thumb = meta['thumb'] if 'thumb' in meta else info["thumbUri"]

        self.offset = float(meta['milliseconds_watched']) / 1000.0 if 'milliseconds_watched' in meta else 0

        self.isLive = 'livefeed' in meta and meta['livefeed'] == 'true'

        self.url, mime_type, stopEvent = hlshelper.pick_bandwidth(url)

        if self.url is None:
            if stopEvent:
                control.log("Setting stop event for proxy player")
                stopEvent.set()
            control.infoDialog(control.lang(34100).encode('utf-8'), icon='ERROR')
            return

        control.log("Resolved URL: %s" % repr(self.url))

        item = control.item(path=self.url)
        item.setArt({'icon': thumb, 'thumb': thumb, 'poster': poster, 'tvshow.poster': poster, 'season.poster': poster})
        item.setProperty('IsPlayable', 'true')
        item.setInfo(type='Video', infoLabels=meta)

        if mime_type:
            item.setMimeType(mime_type)

        item.setContentLookup(False)

        item.setProperty('inputstream.adaptive.manifest_type', 'hls')
        item.setProperty('inputstreamaddon', 'inputstream.adaptive')

        control.resolve(int(sys.argv[1]), True, item)

        self.stopPlayingEvent = threading.Event()
        self.stopPlayingEvent.clear()

        self.token = auth_helper.get_globosat_token()

        self.video_id = info['id'] if 'id' in info else None

        last_time = 0.0
        while not self.stopPlayingEvent.isSet():
            if control.monitor.abortRequested():
                control.log("Abort requested")
                break
            if self.isPlaying() and not self.isLive:
                current_time = self.getTime()
                if current_time - last_time > 5 or (last_time == 0 and current_time > 1):
                    last_time = current_time
                    self.save_video_progress(self.token, self.video_id, current_time)
            control.sleep(1000)

        if stopEvent:
            control.log("Setting stop event for proxy player")
            stopEvent.set()

        control.log("Done playing. Quitting...")
Example #10
0
def get_geofence_video_info(video_id, latitude, longitude, credentials, cdn=None):

    if credentials is None:
        return None

    proxy = control.proxy_url
    proxy = None if proxy is None or proxy == '' else {
        'http': proxy,
        'https': proxy,
    }

    version = PLAYER_VERSION

    # enable_4k = control.is_4k_enabled
    # enable_hdr = control.setting('enable_hdr') == 'true'

    players_preference = []

    # if enable_4k:
    #     if enable_hdr:
    #         players_preference.extend([
    #             'androidtv_hdr',
    #         ])
    #     else:
    #         players_preference.extend([
    #             'androidtv_sdr'
    #         ])

    players_preference.extend([
        # 'androidtv',
        'android',
        # 'android_native',

    ])

    selected_player = players_preference[0]

    post_data = {
        'player': selected_player,
        'version': version,
        'lat': latitude,
        'long': longitude,
        'cdn': cdn or 'globo'
    }

    # tz:       00:00
    # player:  ios_native
    # cdn:     globo
    # ts:      1613693205
    # udid:    bbec61e5f3a06ca54624e84accc232b5d49971a6
    # version: 10.25.0
    # lat:     51.49502563476562
    # long:    -0.03278398965019131

    hash_url = 'http://security.video.globo.com/videos/%s/hash' % video_id
    control.log('POST %s' % hash_url)
    control.log(post_data)
    control.log(credentials)
    response = requests.post(hash_url, cookies=credentials, headers={
                                                            "Accept-Encoding": "gzip",
                                                            "Content-Type": "application/x-www-form-urlencoded",
                                                            "User-Agent": "Canais Globo (Globosat Play)/444 (iPhone)"
                                                        }, data=post_data, proxies=proxy)

    response.raise_for_status()

    hash_json = response.json()

    control.log(hash_json)

    return {
        "id": video_id,
        "title": hash_json.get("name"),
        "category": 'Live',
        "subscriber_only": True,
        "channel": None,
        "player": selected_player,
        "url": hash_json.get("url"),
        "query_string_template": hash_json.get('query_string_template') or "h={{hash}}&k={{key}}&a={{openClosed}}&u={{user}}",
        "thumbUri": hash_json.get("thumbUri"),
        "hash_token": util.get_signed_hashes(hash_json.get('hash'))[0] if 'hash' in hash_json else hash_json.get('token'),
        "user": hash_json.get("user"),
        "credentials": credentials,
        "encrypted": hash_json.get('encrypted', False)
    }
Example #11
0
    def __getLiveVideoInfo(self, id, geolocation):

        username = control.setting('globoplay_username')
        password = control.setting('globoplay_password')

        # authenticateurl
        credentials = auth.auth().authenticate(username, password)

        if credentials is None:
            return None

        affiliate_temp = control.setting('globo_affiliate')

        # In settings.xml - globo_affiliate
        # 0 = All
        # 1 = Rio de Janeiro
        # 2 = Sao Paulo
        # 3 = Brasilia
        # 4 = Belo Horizonte
        # 5 = Recife
        if affiliate_temp == "0":
            affiliate = "All"
        elif affiliate_temp == "2":
            affiliate = "Sao Paulo"
        elif affiliate_temp == "3":
            affiliate = "Brasilia"
        elif affiliate_temp == "4":
            affiliate = "Belo Horizonte"
        elif affiliate_temp == "5":
            affiliate = "Recife"
        else:
            affiliate = "Rio de Janeiro"

        if affiliate == "All" and geolocation != None:
            pass
        elif affiliate == "Sao Paulo":
            geolocation = 'lat=-23.5505&long=-46.6333'
        elif affiliate == 'Brasilia':
            geolocation = 'lat=-15.7942&long=-47.8825'
        elif affiliate == 'Belo Horizonte':
            geolocation = 'lat=-19.9245&long=-43.9352'
        elif affiliate == "Recife":
            geolocation = 'lat=-8.0476&long=-34.8770'
        else:  # Rio de Janeiro
            geolocation = 'lat=-22.900&long=-43.172'

        post_data = "%s&player=%s&version=%s" % (geolocation, PLAYER_SLUG,
                                                 PLAYER_VERSION)

        # 4452349
        hashUrl = 'http://security.video.globo.com/videos/%s/hash' % id
        hashJson = client.request(hashUrl,
                                  error=True,
                                  cookie=credentials,
                                  mobile=True,
                                  headers={
                                      "Accept-Encoding": "gzip",
                                      "Content-Type":
                                      "application/x-www-form-urlencoded",
                                      "User-Agent": "Globo Play/0 (iPhone)"
                                  },
                                  post=post_data)

        hash = get_signed_hashes(hashJson['hash'])[0]

        return {
            "id": "-1",
            "title": hashJson["name"],
            # "program": playlistJson["program"],
            # "program_id": playlistJson["program_id"],
            # "provider_id": playlistJson["provider_id"],
            # "channel": playlistJson["channel"],
            # "channel_id": playlistJson["channel_id"],
            "category": 'Live',
            # "subscriber_only": playlistJson["subscriber_only"],
            "subscriber_only": 'true',
            # "exhibited_at": playlistJson["exhibited_at"],
            "player": PLAYER_SLUG,
            "url": hashJson["url"],
            "query_string_template":
            "h={{hash}}&k={{key}}&a={{openClosed}}&u={{user}}",
            "thumbUri": hashJson["thumbUri"],
            "hash": hash,
            "user": hashJson["user"],
            "credentials": credentials,
            "encrypted": False
        }
Example #12
0
    def playVod(self, id, meta):

        self.retry = 0

        control.log("PLAY SEXYHOT - ID: %s" % id)

        if id == None: return
        try:
            id = self.__getGloboId(id)

            control.log('globo_midia_id: %s' % str(id))

            info = self.__getVideoInfo(id)

            title = info['title']

            signed_hashes = get_signed_hashes(info['hash'])

            query_string = re.sub(r'{{(\w*)}}', r'%(\1)s',
                                  info['query_string_template'])

            query_string = query_string % {
                'hash': signed_hashes[0],
                'key': 'html5'
            }

            url = '?'.join([info['url'], query_string])

            control.log("live media url: %s" % url)

            try:
                meta = json.loads(meta)
            except:
                meta = {
                    "playcount": 0,
                    "overlay": 6,
                    "title": title,
                    "thumb": None,
                    "mediatype": "video"
                }

            meta.update({
                "genre": info["category"],
            })

            poster = meta[
                'poster'] if 'poster' in meta else control.addonPoster()
            thumb = meta['thumb'] if 'thumb' in meta else info["thumbUri"]

            item = control.item(path=url)
            item.setArt({
                'icon': thumb,
                'thumb': thumb,
                'poster': poster,
                'tvshow.poster': poster,
                'season.poster': poster
            })
            item.setProperty('IsPlayable', 'true')
            item.setInfo(type='Video', infoLabels=meta)

            control.resolve(int(sys.argv[1]), id != None, item)
        except:
            pass
Example #13
0
    def play_vod(self, id, meta):

        self.retry = 0

        control.log("PLAY SEXYHOT - ID: %s" % id)

        if id is None:
            return

        id = self.__get_globo_id(id)

        control.log('globo_midia_id: %s' % str(id))

        if id is None:
            return

        meta = json.loads(meta)

        if 'url' not in meta or meta['url'] is None:
            return

        token = self.__get_token(meta['url'])

        info = self.__get_video_info(id, token)

        if info is None:
            return

        signed_hashes = get_signed_hashes(info['hash'])

        query_string = re.sub(r'{{(\w*)}}', r'%(\1)s', info['query_string_template'])

        query_string = query_string % {
            'hash': signed_hashes[0],
            'key': 'app',
            'openClosed': 'F' if info['subscriber_only'] else 'A',
            'user': info["user"] if info['subscriber_only'] else ''
        }

        self.url = '?'.join([info['url'], query_string])

        control.log("live media url: %s" % self.url)

        meta.update({
            "genre": info["category"],
        })

        poster = meta['poster'] if 'poster' in meta else control.addonPoster()
        thumb = meta['thumb'] if 'thumb' in meta else info["thumbUri"]

        url, mime_type, stopEvent, cookies = hlshelper.pick_bandwidth(self.url)
        control.log("Resolved URL: %s" % repr(url))

        if self.url is None:
            if stopEvent:
                control.log("Setting stop event for proxy player")
                stopEvent.set()
            control.infoDialog(control.lang(34100).encode('utf-8'), icon='ERROR')
            return

        item = control.item(path=url)
        item.setArt({'icon': thumb, 'thumb': thumb, 'poster': poster, 'tvshow.poster': poster, 'season.poster': poster})
        item.setProperty('IsPlayable', 'true')
        item.setInfo(type='Video', infoLabels=control.filter_info_labels(meta))

        item.setContentLookup(False)

        if mime_type:
            item.setMimeType(mime_type)

        if not cookies:
            item.setProperty('inputstream.adaptive.manifest_type', 'hls')
            item.setProperty('inputstreamaddon', 'inputstream.adaptive')
            # if cookies:
            #     item.setProperty('inputstream.adaptive.stream_headers', 'Cookie=' + cookies)

        control.resolve(int(sys.argv[1]), id is not None, item)

        self.stopPlayingEvent = threading.Event()
        self.stopPlayingEvent.clear()

        while not self.stopPlayingEvent.isSet():
            if control.monitor.abortRequested():
                control.log("Abort requested")
                break
            control.sleep(100)

        if stopEvent:
            control.log("Setting stop event for proxy player")
            stopEvent.set()
Example #14
0
    def playlive(self, id, meta):
        if id == None: return

        info = self.__getVideoInfo(id)

        # if info['encrypted'] == 'true':
        #     control.infoDialog(control.lang(31200).encode('utf-8'), heading=str("Content is DRM encrypted it won't play in Kodi at this moment"), icon='Wr')

        title = info['channel']

        signed_hashes = util.get_signed_hashes(info['hash'])

        query_string = re.sub(r'{{(\w*)}}', r'%(\1)s',
                              info['query_string_template'])

        query_string = query_string % {
            'hash': signed_hashes[0],
            'key': 'app',
            'openClosed': 'F' if info['subscriber_only'] else 'A',
            'user': info['user'] if info['subscriber_only'] else ''
        }

        url = '?'.join([info['url'], query_string])

        control.log("live media url: %s" % url)

        try:
            meta = json.loads(meta)
        except:
            meta = {
                "playcount": 0,
                "overlay": 6,
                "title": title,
                "thumb": info["thumbUri"],
                "mediatype": "video",
                "aired": info["exhibited_at"]
            }

        meta.update({
            "genre": info["category"],
            "plot": info["title"],
            "plotoutline": info["title"]
        })

        poster = meta['poster'] if 'poster' in meta else control.addonPoster()
        thumb = meta['thumb'] if 'thumb' in meta else info["thumbUri"]

        self.isLive = 'livefeed' in meta and meta['livefeed'] == 'true'

        self.url, mime_type, stopEvent = hlshelper.pickBandwidth(url)
        control.log("Resolved URL: %s" % repr(self.url))

        item = control.item(path=self.url)
        item.setArt({
            'icon': thumb,
            'thumb': thumb,
            'poster': poster,
            'tvshow.poster': poster,
            'season.poster': poster
        })
        item.setProperty('IsPlayable', 'true')
        item.setInfo(type='Video', infoLabels=meta)

        if mime_type:
            item.setMimeType(mime_type)

        item.setContentLookup(False)

        control.resolve(int(sys.argv[1]), True, item)

        self.stopPlayingEvent = threading.Event()
        self.stopPlayingEvent.clear()

        last_time = 0.0
        while not self.stopPlayingEvent.isSet():
            if control.monitor.abortRequested():
                control.log("Abort requested")
                break
            if self.isPlaying():
                total_time = self.getTotalTime()
                current_time = self.getTime()
                if current_time - last_time > 10 or (last_time == 0
                                                     and current_time > 1):
                    last_time = current_time
                    percentage_watched = current_time / total_time if total_time > 0 else 1.0 / 1000000.0
                    self.save_video_progress(
                        info['credentials'],
                        info['program_id'],
                        info['id'],
                        current_time / 1000.0,
                        fully_watched=percentage_watched > 0.9
                        and percentage_watched <= 1)
            control.sleep(1000)

        if stopEvent:
            control.log("Setting stop event for proxy player")
            stopEvent.set()

        control.log("Done playing. Quitting...")
Example #15
0
    def __getLiveVideoInfo(self, id, latitude, longitude):

        proxy = control.proxy_url
        proxy = None if proxy is None or proxy == '' else {
            'http': proxy,
            'https': proxy,
        }

        credentials = auth_helper.get_credentials()

        if credentials is None:
            return None

        post_data = {
            'player': PLAYER_SLUG,
            'version': PLAYER_VERSION,
            'lat': latitude,
            'long': longitude
        }

        # 4452349
        hash_url = 'http://security.video.globo.com/videos/%s/hash' % id
        control.log('POST %s' % hash_url)
        response = requests.post(hash_url,
                                 cookies=credentials,
                                 headers={
                                     "Accept-Encoding": "gzip",
                                     "Content-Type":
                                     "application/x-www-form-urlencoded",
                                     "User-Agent": "Globo Play/0 (iPhone)"
                                 },
                                 data=post_data,
                                 proxies=proxy)

        response.raise_for_status()

        hash_json = response.json()

        hash_token = get_signed_hashes(hash_json['hash'])[0]

        return {
            "id": "-1",
            "title": hash_json["name"],
            # "program": playlistJson["program"],
            # "program_id": playlistJson["program_id"],
            # "provider_id": playlistJson["provider_id"],
            # "channel": playlistJson["channel"],
            # "channel_id": playlistJson["channel_id"],
            "category": 'Live',
            # "subscriber_only": playlistJson["subscriber_only"],
            "subscriber_only": 'true',
            # "exhibited_at": playlistJson["exhibited_at"],
            "player": PLAYER_SLUG,
            "url": hash_json["url"],
            "query_string_template":
            "h={{hash}}&k={{key}}&a={{openClosed}}&u={{user}}",
            "thumbUri": hash_json["thumbUri"],
            "hash": hash_token,
            "user": hash_json["user"],
            "credentials": credentials,
            "encrypted": False
        }
Example #16
0
    def play_stream(self, id, meta):

        if id is None: return

        try:
            meta = json.loads(meta)
        except:
            meta = {
                "playcount": 0,
                "overlay": 6,
                "mediatype": "video",
                "aired": None
            }

        self.isLive = False

        if 'live' in meta and meta['live'] == True:
            self.isLive = True
            info = self.__getLiveVideoInfo(
                id, meta['affiliate'] if 'affiliate' in meta else None)
        else:
            info = self.__getVideoInfo(id)

        title = meta['title'] if 'title' in meta else info['title']

        signed_hashes = get_signed_hashes(info['hash'])

        query_string = re.sub(r'{{(\w*)}}', r'%(\1)s',
                              info['query_string_template'])

        query_string = query_string % {
            'hash': signed_hashes[0],
            'key': 'app',
            'openClosed': 'F' if info['subscriber_only'] else 'A',
            'user': info['user'] if info['subscriber_only'] else ''
        }

        url = '?'.join([info['url'], query_string])

        control.log("live media url: %s" % url)

        meta.update({
            "genre": info["category"],
            "plot": info["title"],
            "plotoutline": info["title"],
            "title": title
        })

        poster = meta['poster'] if 'poster' in meta else control.addonPoster()
        thumb = meta['thumb'] if 'thumb' in meta else info["thumbUri"]

        syshandle = int(sys.argv[1])

        self.offset = float(meta['milliseconds_watched']
                            ) / 1000.0 if 'milliseconds_watched' in meta else 0

        self.isLive = 'live' in meta and meta['live']

        parsed_url = urlparse(url)
        if parsed_url.path.endswith(".m3u8"):
            self.url, mime_type, stopEvent, cookies = hlshelper.pick_bandwidth(
                url)
        else:
            self.url = url
            mime_type, stopEvent, cookies = 'video/mp4', None, None

        if self.url is None:
            if stopEvent:
                control.log("Setting stop event for proxy player")
                stopEvent.set()
            control.infoDialog(message=control.lang(34100).encode('utf-8'),
                               icon='ERROR')
            return

        control.log("Resolved URL: %s" % repr(self.url))

        item = control.item(path=self.url)
        item.setInfo(type='video', infoLabels=meta)
        item.setArt({
            'icon': thumb,
            'thumb': thumb,
            'poster': poster,
            'tvshow.poster': poster,
            'season.poster': poster
        })
        item.setProperty('IsPlayable', 'true')

        item.setContentLookup(False)

        if mime_type:
            item.setMimeType(mime_type)
        elif not cookies:
            item.setProperty('inputstream.adaptive.manifest_type', 'hls')
            item.setProperty('inputstreamaddon', 'inputstream.adaptive')

        # if self.offset > 0:
        #     duration = float(meta['duration']) if 'duration' in meta else 0
        #     if duration > 0:
        #         item.setProperty('StartPercent', str((self.offset / duration) * 100))

        # if self.offset > 0:
        #     item.setProperty('resumetime', str(self.offset))
        #     duration = float(meta['duration']) if 'duration' in meta else self.offset
        #     duration = duration * 1000.0
        #     item.setProperty('totaltime', str(duration))

        control.resolve(syshandle, True, item)

        self.stopPlayingEvent = threading.Event()
        self.stopPlayingEvent.clear()

        self.credentials = info[
            'credentials'] if 'credentials' in info else None
        self.program_id = info['program_id'] if 'program_id' in info else None
        self.video_id = info['id'] if 'id' in info else None

        last_time = 0.0
        while not self.stopPlayingEvent.isSet():
            if control.monitor.abortRequested():
                control.log("Abort requested")
                break
            if not self.isLive and self.isPlaying():
                total_time = self.getTotalTime()
                current_time = self.getTime()
                if current_time - last_time > 5 or (last_time == 0
                                                    and current_time > 1):
                    last_time = current_time
                    percentage_watched = current_time / total_time if total_time > 0 else 1.0 / 1000000.0
                    self.save_video_progress(
                        self.credentials,
                        self.program_id,
                        self.video_id,
                        current_time * 1000,
                        fully_watched=0.9 < percentage_watched <= 1)
            control.sleep(500)

        if stopEvent:
            control.log("Setting stop event for proxy player")
            stopEvent.set()

        control.log("Done playing. Quitting...")