Exemplo n.º 1
0
 def mylist_add(self, video_type, content_id):
     """ Add an item to "My List"
     :type video_type: str
     :type content_id: str
      """
     self._vtm_go.add_mylist(video_type, content_id)
     kodiutils.end_of_directory()
Exemplo n.º 2
0
    def show_search(self, query=None):
        """ Shows the search dialog
        :type query: str
        """
        if not query:
            # Ask for query
            query = kodiutils.get_search_string(
                heading=kodiutils.localize(30009))  # Search
            if not query:
                kodiutils.end_of_directory()
                return

        # Do search
        try:
            items = self._search.search(query)
        except Exception as ex:  # pylint: disable=broad-except
            kodiutils.notification(message=str(ex))
            kodiutils.end_of_directory()
            return

        # Display results
        listing = [self._menu.generate_titleitem(item) for item in items]

        # Sort like we get our results back.
        kodiutils.show_listing(listing, 30009, content='tvshows')
Exemplo n.º 3
0
    def show_program_season(self, program, season):
        """ Show the episodes of a program from the catalog
        :type program: str
        :type season: int
        """
        try:
            program_obj = self._vtm_go.get_program(
                program
            )  # Use CACHE_AUTO since the data is just refreshed in show_program
        except UnavailableException:
            kodiutils.ok_dialog(
                message=kodiutils.localize(30717)
            )  # This program is not available in the VTM GO catalogue.
            kodiutils.end_of_directory()
            return

        if season == -1:
            # Show all seasons
            seasons = list(program_obj.seasons.values())
        else:
            # Show the season that was selected
            seasons = [program_obj.seasons[season]]

        listing = [
            self._menu.generate_titleitem(e) for s in seasons
            for e in list(s.episodes.values())
        ]

        # Sort by episode number by default. Takes seasons into account.
        kodiutils.show_listing(listing,
                               30003,
                               content='episodes',
                               sort=['episode', 'duration'])
Exemplo n.º 4
0
    def show_program_season(self, program_id, season_uuid):
        """ Show the episodes of a program from the catalog
        :type program_id: str
        :type season_uuid: str
        """
        try:
            program = self._api.get_program(program_id)
        except UnavailableException:
            kodiutils.ok_dialog(message=kodiutils.localize(
                30717))  # This program is not available in the catalogue.
            kodiutils.end_of_directory()
            return

        if season_uuid == "-1":
            # Show all episodes
            episodes = program.episodes
        else:
            # Show the episodes of the season that was selected
            episodes = [
                e for e in program.episodes if e.season_uuid == season_uuid
            ]

        listing = [Menu.generate_titleitem(episode) for episode in episodes]

        # Sort by episode number by default. Takes seasons into account.
        kodiutils.show_listing(listing,
                               30003,
                               content='episodes',
                               sort=['episode', 'duration'])
Exemplo n.º 5
0
    def mylist_add(self, uuid):
        """ Add a program to My List """
        if not uuid:
            kodiutils.end_of_directory()
            return

        mylist, sync_info = self._auth.get_dataset('myList', 'myList')

        if not mylist:
            mylist = []

        if uuid not in [item.get('id') for item in mylist]:
            # Python 2.7 doesn't support .timestamp(), and windows doesn't do '%s', so we need to calculate it ourself
            epoch = datetime(1970, 1, 1, tzinfo=dateutil.tz.gettz('UTC'))
            now = datetime.now(tz=dateutil.tz.gettz('UTC'))
            timestamp = int((now - epoch).total_seconds()) * 1000

            mylist.append({
                'id': uuid,
                'timestamp': timestamp,
            })

            self._auth.put_dataset('myList', 'myList', mylist, sync_info)

        kodiutils.end_of_directory()
Exemplo n.º 6
0
    def show_search(self, query=None):
        """ Shows the search dialog.

        :type query: str
        """
        if not query:
            # Ask for query
            query = kodiutils.get_search_string(
                heading=kodiutils.localize(30009))  # Search Streamz
            if not query:
                kodiutils.end_of_directory()
                return

        # Do search
        try:
            items = self._api.do_search(query)
        except Exception as ex:  # pylint: disable=broad-except
            kodiutils.notification(message=str(ex))
            kodiutils.end_of_directory()
            return

        # Display results
        show_unavailable = kodiutils.get_setting_bool(
            'interface_show_unavailable')
        listing = []
        for item in items:
            if show_unavailable or item.available:
                listing.append(Menu.generate_titleitem(item))

        # Sort like we get our results back.
        kodiutils.show_listing(listing, 30009, content='tvshows')
Exemplo n.º 7
0
    def _resolve_stream(uuid):
        """ Resolve the stream for the requested item
        :type uuid: string
        """
        try:
            # Check if we have credentials
            if not kodiutils.get_setting('username') or not kodiutils.get_setting('password'):
                confirm = kodiutils.yesno_dialog(
                    message=kodiutils.localize(30701))  # To watch a video, you need to enter your credentials. Do you want to enter them now?
                if confirm:
                    kodiutils.open_settings()
                kodiutils.end_of_directory()
                return None

            # Fetch an auth token now
            try:
                auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path())

                # Get stream information
                resolved_stream = ContentApi(auth).get_stream_by_uuid(uuid)
                return resolved_stream

            except (InvalidLoginException, AuthenticationException) as ex:
                _LOGGER.exception(ex)
                kodiutils.ok_dialog(message=kodiutils.localize(30702, error=str(ex)))
                kodiutils.end_of_directory()
                return None

        except GeoblockedException:
            kodiutils.ok_dialog(message=kodiutils.localize(30710))  # This video is geo-blocked...
            return None

        except UnavailableException:
            kodiutils.ok_dialog(message=kodiutils.localize(30712))  # The video is unavailable...
            return None
Exemplo n.º 8
0
    def show_search(self, query=None):
        """ Shows the search dialog.

        :param str query:               The query to search for.
        """
        if not query:
            # Ask for query
            query = kodiutils.get_search_string(
                heading=kodiutils.localize(30009))  # Search
            if not query:
                kodiutils.end_of_directory()
                return

        # Do search
        items = self._search_api.search(query)

        # Generate the results
        listing = []
        for item in items:
            if isinstance(item, Program):
                if item.series_id:
                    listing.append(Menu.generate_titleitem_series(item))
                else:
                    listing.append(Menu.generate_titleitem_program(item))

            if isinstance(item, Channel) and item.available is not False:
                listing.append(Menu.generate_titleitem_channel(item))

        # Sort like we get our results back.
        kodiutils.show_listing(listing, 30009, content='files')
Exemplo n.º 9
0
    def mylist_del(self, video_type, content_id):
        """ Remove an item from "My List".

        :type video_type: str
        :type content_id: str
        """
        self._api.del_mylist(video_type, content_id)
        kodiutils.end_of_directory()
Exemplo n.º 10
0
 def mylist_del(self, video_type, content_id):
     """ Remove an item from "My List"
     :type video_type: str
     :type content_id: str
     """
     self._vtm_go.del_mylist(video_type, content_id)
     kodiutils.end_of_directory()
     kodiutils.container_refresh()
Exemplo n.º 11
0
 def live(channel):
     """ Play the live channel.
     :type channel: string
     """
     channel_name = CHANNELS.get(channel, dict(name=channel))
     kodiutils.ok_dialog(message=kodiutils.localize(
         30718, channel=channel_name.get(
             'name')))  # There is no live stream available for {channel}.
     kodiutils.end_of_directory()
Exemplo n.º 12
0
    def play(item):
        """ Play the requested item.
        :type item: string
        """

        # Workaround for Raspberry Pi 3 and older
        omxplayer = kodiutils.get_global_setting('videoplayer.useomxplayer')
        if omxplayer is False:
            kodiutils.set_global_setting('videoplayer.useomxplayer', True)

        try:
            # Check if we have credentials
            if not kodiutils.get_setting(
                    'username') or not kodiutils.get_setting('password'):
                confirm = kodiutils.yesno_dialog(
                    message=kodiutils.localize(30701)
                )  # To watch a video, you need to enter your credentials. Do you want to enter them now?
                if confirm:
                    kodiutils.open_settings()
                kodiutils.end_of_directory()
                return

            # Fetch an auth token now
            try:
                auth = AuthApi(kodiutils.get_setting('username'),
                               kodiutils.get_setting('password'),
                               kodiutils.get_tokens_path())

                # Get stream information
                resolved_stream = ContentApi(auth).get_stream_by_uuid(item)

            except (InvalidLoginException, AuthenticationException) as ex:
                _LOGGER.error(ex)
                kodiutils.ok_dialog(
                    message=kodiutils.localize(30702, error=str(ex)))
                kodiutils.end_of_directory()
                return

        except GeoblockedException:
            kodiutils.ok_dialog(heading=kodiutils.localize(30709),
                                message=kodiutils.localize(
                                    30710))  # This video is geo-blocked...
            return

        except UnavailableException:
            kodiutils.ok_dialog(heading=kodiutils.localize(30711),
                                message=kodiutils.localize(
                                    30712))  # The video is unavailable...
            return

        # Play this item
        kodiutils.play(resolved_stream)
Exemplo n.º 13
0
    def play_epg_datetime(self, channel, timestamp):
        """ Play a program based on the channel and the timestamp when it was aired
        :type channel: str
        :type timestamp: str
        """
        broadcast = self._vtm_go_epg.get_broadcast(channel, timestamp)
        if not broadcast:
            kodiutils.ok_dialog(heading=kodiutils.localize(30711), message=kodiutils.localize(30713))  # The requested video was not found in the guide.
            kodiutils.end_of_directory()
            return

        kodiutils.redirect(
            kodiutils.url_for('play', category=broadcast.playable_type, item=broadcast.playable_uuid))
Exemplo n.º 14
0
def index():
    """ Show the profile selection, or go to the main menu. """
    # Verify credentials
    from resources.lib.modules.authentication import Authentication
    if not Authentication.verify_credentials():
        kodiutils.end_of_directory()
        kodiutils.execute_builtin('ActivateWindow(Home)')
        return

    if kodiutils.get_setting_bool('auto_login') and kodiutils.get_setting('profile'):
        show_main_menu()
    else:
        select_profile()
Exemplo n.º 15
0
    def live(channel):
        """ Play the live channel.
        :type channel: string
        """
        # TODO: this doesn't work correctly, playing a live program from the PVR won't play something from the beginning
        # Lookup current program
        # broadcast = self._epg.get_broadcast(channel, datetime.datetime.now().isoformat())
        # if broadcast and broadcast.video_url:
        #     self.play_from_page(broadcast.video_url)
        #     return

        channel_name = CHANNELS.get(channel, dict(name=channel))
        kodiutils.ok_dialog(message=kodiutils.localize(30718, channel=channel_name.get('name')))  # There is no live stream available for {channel}.
        kodiutils.end_of_directory()
Exemplo n.º 16
0
    def mylist_del(self, uuid):
        """ Remove a program from My List """
        if not uuid:
            kodiutils.end_of_directory()
            return

        mylist, sync_info = self._auth.get_dataset('myList', 'myList')

        if not mylist:
            mylist = []

        new_mylist = [item for item in mylist if item.get('id') != uuid]
        self._auth.put_dataset('myList', 'myList', new_mylist, sync_info)

        kodiutils.end_of_directory()
Exemplo n.º 17
0
    def play_epg_datetime(self, channel, timestamp):
        """ Play a program based on the channel and the timestamp when it was aired
        :type channel: str
        :type timestamp: str
        """
        broadcast = self._epg.get_broadcast(channel, timestamp)
        if not broadcast:
            kodiutils.ok_dialog(message=kodiutils.localize(30713))  # The requested video was not found in the guide.
            kodiutils.end_of_directory()
            return

        if not broadcast.video_url:
            kodiutils.ok_dialog(message=kodiutils.localize(30712))  # The video is unavailable and can't be played right now.
            kodiutils.end_of_directory()
            return

        Player().play_from_page(channel, broadcast.video_url)
Exemplo n.º 18
0
    def show_program_clips(self, channel, program_id):
        """ Show the clips of a program from the catalog
        :type channel: str
        :type program_id: str
        """
        try:
            # We need to query the backend, since we don't cache clips.
            program = self._api.get_program(channel, program_id, extract_clips=True, cache=CACHE_PREVENT)
        except UnavailableException:
            kodiutils.ok_dialog(message=kodiutils.localize(30717))  # This program is not available in the catalogue.
            kodiutils.end_of_directory()
            return

        listing = [Menu.generate_titleitem(episode) for episode in program.clips]

        # Sort like we get our results back.
        kodiutils.show_listing(listing, 30003, content='episodes')
Exemplo n.º 19
0
    def play_epg_datetime(self, channel, timestamp):
        """ Play a program based on the channel and the timestamp when it was aired
        :type channel: str
        :type timestamp: str
        """
        broadcast = self._epg.get_broadcast(channel, timestamp)
        if not broadcast:
            kodiutils.ok_dialog(
                heading=kodiutils.localize(30711),
                message=kodiutils.localize(
                    30713))  # The requested video was not found in the guide.
            kodiutils.end_of_directory()
            return

        kodiutils.container_update(
            kodiutils.url_for('play',
                              channel=channel,
                              uuid=broadcast.video_url))
Exemplo n.º 20
0
    def play_asset(self, asset_id):
        """ Play an asset (can be a program of a live channel).

        :param string asset_id:         The ID of the asset to play.
        """
        # Get asset info
        if len(asset_id) == 32:
            # a locId is 32 chars
            asset = self._channel_api.get_asset_by_locid(asset_id)
        else:
            # an asset_id is 40 chars
            asset = self._channel_api.get_asset(asset_id)

        if isinstance(asset, Program):
            item = Menu.generate_titleitem_program(asset)
        elif isinstance(asset, Channel):
            item = Menu.generate_titleitem_channel(asset)
        else:
            raise Exception('Unknown asset type: %s' % asset)

        # Get stream info
        try:
            stream_info = self._channel_api.get_stream(asset.uid)
        except InvalidTokenException:
            # Retry with fresh tokens
            self._auth.login(True)
            stream_info = self._channel_api.get_stream(asset.uid)
        except (NotAvailableInOfferException, UnavailableException) as exc:
            _LOGGER.error(exc)
            kodiutils.ok_dialog(
                message=kodiutils.localize(30712)
            )  # The video is unavailable and can't be played right now.
            kodiutils.end_of_directory()
            return

        license_key = self._create_license_key(
            stream_info.drm_license_url,
            key_headers={'Content-Type': 'application/octet-stream'})

        _LOGGER.debug('Starting playing %s with license key %s',
                      stream_info.url, license_key)
        kodiutils.play(stream_info.url, license_key, item.title, item.art_dict,
                       item.info_dict, item.prop_dict)
    def show_search(self, query=None):
        """ Shows the search dialog
        :type query: str
        """
        if not query:
            # Ask for query
            query = kodiutils.get_search_string(heading=kodiutils.localize(30009))  # Search
            if not query:
                kodiutils.end_of_directory()
                return

        # Do search
        items = self._search_api.search(query)

        # Display results
        listing = [Menu.generate_titleitem(item) for item in items]

        # Sort like we get our results back.
        kodiutils.show_listing(listing, 30009, content='episodes')
    def select_profile(self, key=None):
        """ Show your profiles.

        :type key: str
        """
        profiles = self._auth.get_profiles()

        # Show warning when you have no profiles
        if not profiles:
            # Your account has no profiles defined. Please login on www.streamz.be/streamz and create a profile.
            kodiutils.ok_dialog(message=kodiutils.localize(30703))
            kodiutils.end_of_directory()
            return

        # Select the first profile when you only have one
        if len(profiles) == 1:
            key = profiles[0].key

        # Save the selected profile
        if key:
            profile = [x for x in profiles if x.key == key][0]
            _LOGGER.debug('Setting profile to %s', profile)
            kodiutils.set_setting('profile',
                                  '%s:%s' % (profile.key, profile.product))
            kodiutils.set_setting('profile_name', profile.name)

            kodiutils.redirect(kodiutils.url_for('show_main_menu'))
            return

        # Show profile selection when you have multiple profiles
        listing = [
            TitleItem(
                title=self._get_profile_name(p),
                path=kodiutils.url_for('select_profile', key=p.key),
                art_dict=dict(icon='DefaultUser.png'),
                info_dict=dict(plot=p.name, ),
            ) for p in profiles
        ]

        kodiutils.show_listing(listing, sort=['unsorted'],
                               category=30057)  # Select Profile
Exemplo n.º 23
0
def index():
    """ Ask to login, or go to the main menu. """
    if not kodiutils.has_credentials():
        if not kodiutils.yesno_dialog(message=kodiutils.localize(
                30701)):  # You need to configure your credentials...
            # We have no credentials, return to the Home Menu
            kodiutils.end_of_directory()
            kodiutils.execute_builtin('ActivateWindow(Home)')
            return

        kodiutils.open_settings()

    try:
        # Try authentication
        AuthApi(username=kodiutils.get_setting('username'),
                password=kodiutils.get_setting('password'),
                tenant=kodiutils.get_setting('tenant'),
                token_path=kodiutils.get_tokens_path())
    except InvalidLoginException:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30203))  # Your credentials are not valid!
        kodiutils.open_settings()
        kodiutils.execute_builtin('ActivateWindow(Home)')
        kodiutils.end_of_directory()
        return

    except HTTPError as exc:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30702, code='HTTP %d' % exc.response.status_code)
                            )  # Unknown error while logging in: {code}
        kodiutils.end_of_directory()
        return

    show_main_menu()
Exemplo n.º 24
0
def index():
    """ Show the profile selection, or go to the main menu. """
    try:
        if (kodiutils.get_setting_bool('auto_login')
                and kodiutils.get_setting('username')
                and kodiutils.get_setting('password')
                and kodiutils.get_setting('profile')):
            # We have credentials
            show_main_menu()

        else:
            # Ask the user for the profile to use
            select_profile()

    except NoLoginException:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30701))  # You need to configure your credentials...
        kodiutils.open_settings()
        kodiutils.container_refresh()

    except InvalidLoginException:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30203))  # Your credentials are not valid!
        kodiutils.open_settings()
        kodiutils.end_of_directory()

    except NoStreamzSubscriptionException:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30201))  # Your Streamz account has no valid subscription!
        kodiutils.end_of_directory()

    except NoTelenetSubscriptionException:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30202))  # Your Telenet account has no valid subscription!
        kodiutils.end_of_directory()

    except LoginErrorException as exc:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30702, code=exc.code))  # Unknown error while logging in: {code}
        kodiutils.open_settings()
        kodiutils.end_of_directory()
Exemplo n.º 25
0
def index():
    """ Show the profile selection, or go to the main menu. """
    while True:
        if not kodiutils.has_credentials():
            if not kodiutils.yesno_dialog(message=kodiutils.localize(
                    30701)):  # You need to configure your credentials...
                # We have no credentials
                kodiutils.end_of_directory()
                kodiutils.execute_builtin('ActivateWindow(Home)')
                return

            kodiutils.open_settings()
        else:
            break

    try:
        if kodiutils.get_setting_bool('auto_login') and kodiutils.get_setting(
                'profile'):
            # We have a profile
            show_main_menu()

        else:
            # Ask the user for the profile to use
            select_profile()

    except InvalidLoginException:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30203))  # Your credentials are not valid!
        kodiutils.open_settings()
        kodiutils.end_of_directory()

    except LoginErrorException as exc:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30702, code=exc.code))  # Unknown error while logging in: {code}
        kodiutils.end_of_directory()

    except HTTPError as exc:
        kodiutils.ok_dialog(message=kodiutils.localize(
            30702, code='HTTP %d' % exc.response.status_code)
                            )  # Unknown error while logging in: {code}
        kodiutils.end_of_directory()
Exemplo n.º 26
0
    def show_channel(self, channel_id):
        """ Shows TV channel details.

        :param str channel_id:          The channel we want to display.
        """
        channel = self._channel_api.get_asset(channel_id.split(':')[0])

        # Verify PIN
        if channel.pin and kodiutils.get_setting_int(
                'interface_adult') != SETTINGS_ADULT_ALLOW:
            pin = kodiutils.get_numeric_input(
                kodiutils.localize(30204))  # Enter PIN
            if not pin:
                # Cancelled
                kodiutils.end_of_directory()
                return

            if not self._channel_api.verify_pin(pin):
                kodiutils.ok_dialog(message=kodiutils.localize(
                    30205))  # The PIN you have entered is invalid!
                kodiutils.end_of_directory()
                return

        listing = []

        # Play live
        live_titleitem = Menu.generate_titleitem_channel(channel)
        live_titleitem.info_dict['title'] = kodiutils.localize(
            30051, channel=channel.title)  # Watch live [B]{channel}[/B]
        listing.append(live_titleitem)

        # Restart currently airing program
        if channel.epg_now and channel.epg_now.restart:
            restart_titleitem = Menu.generate_titleitem_program(
                channel.epg_now)
            restart_titleitem.info_dict['title'] = kodiutils.localize(
                30052,
                program=channel.epg_now.title)  # Restart [B]{program}[/B]
            restart_titleitem.art_dict['thumb'] = 'DefaultInProgressShows.png'
            listing.append(restart_titleitem)

        # TV Guide
        listing.append(
            TitleItem(
                title=kodiutils.localize(
                    30053, channel=channel.title),  # TV Guide for {channel}
                path=kodiutils.url_for('show_channel_guide',
                                       channel_id=channel_id),
                art_dict=dict(icon='DefaultAddonTvInfo.png', ),
                info_dict=dict(
                    plot=kodiutils.localize(
                        30054, channel=channel.title
                    ),  # Browse the TV Guide for {channel}
                ),
            ))

        if channel.replay:
            listing.append(
                TitleItem(
                    title=kodiutils.localize(
                        30055, channel=channel.title),  # Catalog for {channel}
                    path=kodiutils.url_for('show_channel_replay',
                                           channel_id=channel_id),
                    art_dict=dict(icon='DefaultMovieTitle.png', ),
                    info_dict=dict(
                        plot=kodiutils.localize(
                            30056, channel=channel.title
                        ),  # Browse the Catalog for {channel}
                    ),
                ))

        kodiutils.show_listing(listing, 30007)
Exemplo n.º 27
0
    def play(self, category, item):
        """ Play the requested item.
        :type category: string
        :type item: string
        """
        if not self._check_credentials():
            kodiutils.end_of_directory()
            return

        # Check if inputstreamhelper is correctly installed
        if not self._check_inputstream():
            kodiutils.end_of_directory()
            return

        try:
            # Get stream information
            resolved_stream = self._vtm_go_stream.get_stream(category, item)

        except StreamGeoblockedException:
            kodiutils.ok_dialog(heading=kodiutils.localize(30709), message=kodiutils.localize(30710))  # This video is geo-blocked...
            kodiutils.end_of_directory()
            return

        except StreamUnavailableException:
            kodiutils.ok_dialog(heading=kodiutils.localize(30711), message=kodiutils.localize(30712))  # The video is unavailable...
            kodiutils.end_of_directory()
            return

        info_dict = {
            'tvshowtitle': resolved_stream.program,
            'title': resolved_stream.title,
            'duration': resolved_stream.duration,
        }

        prop_dict = {}

        stream_dict = {
            'duration': resolved_stream.duration,
        }

        upnext_data = None

        # Lookup metadata
        try:
            if category in ['movies', 'oneoffs']:
                info_dict.update({'mediatype': 'movie'})

                # Get details
                movie_details = self._vtm_go.get_movie(item)
                if movie_details:
                    info_dict.update({
                        'plot': movie_details.description,
                        'year': movie_details.year,
                        'aired': movie_details.aired,
                    })

            elif category == 'episodes':
                info_dict.update({'mediatype': 'episode'})

                # There is no direct API to get episode details, so we go trough the cached program details
                program = self._vtm_go.get_program(resolved_stream.program_id)
                if program:
                    episode_details = self._vtm_go.get_episode_from_program(program, item)
                    if episode_details:
                        info_dict.update({
                            'plot': episode_details.description,
                            'season': episode_details.season,
                            'episode': episode_details.number,
                        })

                        # Lookup the next episode
                        next_episode_details = self._vtm_go.get_next_episode_from_program(program, episode_details.season, episode_details.number)

                        # Create the data for Up Next
                        if next_episode_details:
                            upnext_data = self.generate_upnext(episode_details, next_episode_details)

            elif category == 'channels':
                info_dict.update({'mediatype': 'episode'})

                # For live channels, we need to keep on updating the manifest
                # This might not be needed, and could be done with the Location-tag updates if inputstream.adaptive supports it
                # See https://github.com/peak3d/inputstream.adaptive/pull/298#issuecomment-524206935
                prop_dict.update({
                    'inputstream.adaptive.manifest_update_parameter': 'full',
                })

            else:
                _LOGGER.warning('Unknown category %s', category)

        except UnavailableException:
            # We continue without details.
            # This allows to play some programs that don't have metadata (yet).
            pass

        # If we have enabled the Manifest proxy, route the call trough that.
        if category in ['movies', 'oneoffs', 'episodes'] and kodiutils.get_setting_bool('manifest_proxy'):
            try:  # Python 3
                from urllib.parse import urlencode
            except ImportError:  # Python 2
                from urllib import urlencode

            port = kodiutils.get_setting_int('manifest_proxy_port')
            if not port:
                kodiutils.notification(message=kodiutils.localize(30718), icon='error')
                kodiutils.end_of_directory()
                return

            url = 'http://127.0.0.1:{port}/manifest?{path}'.format(port=port,
                                                                   path=urlencode({'path': resolved_stream.url}))
        else:
            url = resolved_stream.url

        license_key = self._vtm_go_stream.create_license_key(resolved_stream.license_url)

        # Play this item
        kodiutils.play(url, license_key, resolved_stream.title, {}, info_dict, prop_dict, stream_dict)

        # Wait for playback to start
        kodi_player = KodiPlayer()
        if not kodi_player.waitForPlayBack(url=url):
            # Playback didn't start
            kodiutils.end_of_directory()
            return

        # Send Up Next data
        if upnext_data and kodiutils.get_setting_bool('useupnext'):
            _LOGGER.debug("Sending Up Next data: %s", upnext_data)
            self.send_upnext(upnext_data)
    def show_detail(self, channel=None, date=None):
        """ Shows the programs of a specific date in the tv guide
        :type channel: str
        :type date: str
        """
        try:
            programs = self._epg.get_epg(channel=channel, date=date)
        except UnavailableException as ex:
            kodiutils.notification(message=str(ex))
            kodiutils.end_of_directory()
            return

        listing = []
        for program in programs:
            if program.program_url:
                context_menu = [(
                    kodiutils.localize(30102),  # Go to Program
                    'Container.Update(%s)' %
                    kodiutils.url_for('show_catalog_program',
                                      channel=channel,
                                      program=program.program_url))]
            else:
                context_menu = None

            title = '{time} - {title}'.format(
                time=program.start.strftime('%H:%M'),
                title=program.program_title)

            if program.airing:
                title = '[B]{title}[/B]'.format(title=title)

            if program.video_url:
                path = kodiutils.url_for('play_from_page',
                                         channel=channel,
                                         page=quote(program.video_url,
                                                    safe=''))
            else:
                path = kodiutils.url_for('play_catalog', uuid='')
                title = '[COLOR gray]' + title + '[/COLOR]'

            stream_dict = STREAM_DICT.copy()
            stream_dict.update({
                'duration': program.duration,
            })

            info_dict = {
                'title': title,
                'plot': program.description,
                'studio': program.channel,
                'duration': program.duration,
                'tvshowtitle': program.program_title,
                'season': program.season,
                'episode': program.number,
                'mediatype': 'episode',
            }

            listing.append(
                TitleItem(title=title,
                          path=path,
                          art_dict={
                              'thumb': program.thumb,
                          },
                          info_dict=info_dict,
                          stream_dict=stream_dict,
                          context_menu=context_menu,
                          is_playable=True))

        kodiutils.show_listing(listing,
                               30013,
                               content='episodes',
                               sort=['unsorted'])
Exemplo n.º 29
0
    def select_profile(self, key=None):  # pylint: disable=too-many-return-statements
        """ Show your profiles
        :type key: str
        """
        try:
            profiles = self._auth.get_profiles()
        except InvalidLoginException:
            kodiutils.ok_dialog(message=kodiutils.localize(
                30203))  # Your credentials are not valid!
            kodiutils.open_settings()
            return

        except InvalidTokenException:
            self._auth.logout()
            kodiutils.redirect(kodiutils.url_for('select_profile'))
            return

        except LoginErrorException as exc:
            kodiutils.ok_dialog(message=kodiutils.localize(
                30702,
                code=exc.code))  # Unknown error while logging in: {code}
            kodiutils.open_settings()
            return

        except ApiUpdateRequired:
            kodiutils.ok_dialog(message=kodiutils.localize(
                30705))  # The VTM GO Service has been updated...
            return

        except Exception as exc:  # pylint: disable=broad-except
            kodiutils.ok_dialog(message="%s" % exc)
            return

        # Show warning when you have no profiles
        if not profiles:
            # Your account has no profiles defined. Please login on vtm.be/vtmgo and create a Profile.
            kodiutils.ok_dialog(message=kodiutils.localize(30703))
            kodiutils.end_of_directory()
            return

        # Select the first profile when you only have one
        if len(profiles) == 1:
            key = profiles[0].key

        # Save the selected profile
        if key:
            profile = [x for x in profiles if x.key == key][0]
            _LOGGER.debug('Setting profile to %s', profile)
            kodiutils.set_setting('profile',
                                  '%s:%s' % (profile.key, profile.product))
            kodiutils.set_setting('profile_name', profile.name)

            kodiutils.redirect(kodiutils.url_for('show_main_menu'))
            return

        # Show profile selection when you have multiple profiles
        listing = [
            kodiutils.TitleItem(
                title=self._get_profile_name(p),
                path=kodiutils.url_for('select_profile', key=p.key),
                art_dict=dict(icon='DefaultUser.png'),
                info_dict=dict(plot=p.name, ),
            ) for p in profiles
        ]

        kodiutils.show_listing(listing, sort=['unsorted'],
                               category=30057)  # Select Profile
Exemplo n.º 30
0
    def show_program(self, program):
        """ Show a program from the catalog
        :type program: str
         """
        try:
            program_obj = self._vtm_go.get_program(
                program, cache=CACHE_PREVENT
            )  # Use CACHE_PREVENT since we want fresh data
        except UnavailableException:
            kodiutils.ok_dialog(
                message=kodiutils.localize(30717)
            )  # This program is not available in the VTM GO catalogue.
            kodiutils.end_of_directory()
            return

        # Go directly to the season when we have only one season
        if len(program_obj.seasons) == 1:
            self.show_program_season(
                program,
                list(program_obj.seasons.values())[0].number)
            return

        studio = CHANNELS.get(program_obj.channel, {}).get('studio_icon')

        listing = []

        # Add an '* All seasons' entry when configured in Kodi
        if kodiutils.get_global_setting('videolibrary.showallitems') is True:
            listing.append(
                kodiutils.TitleItem(
                    title='* %s' % kodiutils.localize(30204),  # * All seasons
                    path=kodiutils.url_for('show_catalog_program_season',
                                           program=program,
                                           season=-1),
                    art_dict=dict(
                        thumb=program_obj.cover,
                        fanart=program_obj.cover,
                    ),
                    info_dict=dict(
                        tvshowtitle=program_obj.name,
                        title=kodiutils.localize(30204),  # All seasons
                        tagline=program_obj.description,
                        set=program_obj.name,
                        studio=studio,
                        mpaa=', '.join(program_obj.legal)
                        if hasattr(program_obj, 'legal') and program_obj.legal
                        else kodiutils.localize(30216),  # All ages
                    ),
                ))

        # Add the seasons
        for season in list(program_obj.seasons.values()):
            listing.append(
                kodiutils.TitleItem(
                    title=kodiutils.localize(
                        30205, season=season.number),  # Season {season}
                    path=kodiutils.url_for('show_catalog_program_season',
                                           program=program,
                                           season=season.number),
                    art_dict=dict(
                        thumb=season.cover,
                        fanart=program_obj.cover,
                    ),
                    info_dict=dict(
                        tvshowtitle=program_obj.name,
                        title=kodiutils.localize(
                            30205, season=season.number),  # Season {season}
                        tagline=program_obj.description,
                        set=program_obj.name,
                        studio=studio,
                        mpaa=', '.join(program_obj.legal)
                        if hasattr(program_obj, 'legal') and program_obj.legal
                        else kodiutils.localize(30216),  # All ages
                    ),
                ))

        # Sort by label. Some programs return seasons unordered.
        kodiutils.show_listing(listing,
                               30003,
                               content='tvshows',
                               sort=['label'])