コード例 #1
0
ファイル: vtmgo.py プロジェクト: add-ons/plugin.video.vtm.go
    def get_catalog_ids(self):
        """ Returns the IDs of the contents of the Catalog """
        # Try to fetch from cache
        items = kodiutils.get_cache(['catalog_id'], 300)  # 5 minutes ttl
        if items:
            return items

        # Fetch from API
        response = util.http_get(
            API_ENDPOINT + '/%s/catalog' % self._mode(),
            params={
                'pageSize': 2000,
                'filter': None
            },
            token=self._tokens.jwt_token if self._tokens else None,
            profile=self._tokens.profile if self._tokens else None)
        info = json.loads(response.text)

        items = [
            item.get('target', {}).get('id')
            for item in info.get('pagedTeasers', {}).get('content', [])
        ]

        kodiutils.set_cache(['catalog_id'], items)
        return items
コード例 #2
0
    def get_mylist_ids(self):
        """ Returns the IDs of the contents of My List """
        # Try to fetch from cache
        items = kodiutils.get_cache(['mylist_id'], 300)  # 5 minutes ttl
        if items:
            return items

        # Fetch from API
        response = util.http_get(API_ENDPOINT + '/%s/main/swimlane/%s' % (self._mode(), 'my-list'),
                                 token=self._tokens.jwt_token,
                                 profile=self._tokens.profile)

        # Result can be empty
        result = json.loads(response.text) if response.text else []

        items = [item.get('target', {}).get('id') for item in result.get('teasers', [])]

        kodiutils.set_cache(['mylist_id'], items)
        return items
コード例 #3
0
ファイル: api.py プロジェクト: add-ons/plugin.video.streamz
    def get_movie(self, movie_id, cache=CACHE_AUTO):
        """ Get the details of the specified movie.

        :type movie_id: str
        :type cache: int
        :rtype Movie
        """
        if cache in [CACHE_AUTO, CACHE_ONLY]:
            # Try to fetch from cache
            movie = kodiutils.get_cache(['movie', movie_id])
            if movie is None and cache == CACHE_ONLY:
                return None
        else:
            movie = None

        if movie is None:
            # Fetch from API
            response = util.http_get(API_ENDPOINT + '/%s/movies/%s' %
                                     (self._mode(), movie_id),
                                     token=self._tokens.access_token,
                                     profile=self._tokens.profile)
            info = json.loads(response.text)
            movie = info.get('movie', {})
            kodiutils.set_cache(['movie', movie_id], movie)

        return Movie(
            movie_id=movie.get('id'),
            name=movie.get('name'),
            description=movie.get('description'),
            duration=movie.get('durationSeconds'),
            thumb=movie.get('teaserImageUrl'),
            fanart=movie.get('bigPhotoUrl'),
            year=movie.get('productionYear'),
            geoblocked=movie.get('geoBlocked'),
            remaining=movie.get('remainingDaysAvailable'),
            legal=movie.get('legalIcons'),
            # aired=movie.get('broadcastTimestamp'),
            channel=self._parse_channel(movie.get('channelLogoUrl')),
            # my_list=program.get('addedToMyList'),  # Don't use addedToMyList, since we might have cached this info
            available=movie.get('blockedFor') != 'SUBSCRIPTION',
        )
コード例 #4
0
    def get_movie(self, movie_id, cache=CACHE_AUTO):
        """ Get the details of the specified movie.
        :type movie_id: str
        :type cache: int
        :rtype Movie
        """
        if cache in [CACHE_AUTO, CACHE_ONLY]:
            # Try to fetch from cache
            movie = kodiutils.get_cache(['movie', movie_id])
            if movie is None and cache == CACHE_ONLY:
                return None
        else:
            movie = None

        if movie is None:
            # Fetch from API
            response = util.http_get(API_ENDPOINT + '/%s/movies/%s' %
                                     (self._mode(), movie_id),
                                     token=self._tokens.jwt_token,
                                     profile=self._tokens.profile)
            info = json.loads(response.text)
            movie = info.get('movie', {})
            kodiutils.set_cache(['movie', movie_id], movie)

        return Movie(
            movie_id=movie.get('id'),
            name=movie.get('name'),
            description=movie.get('description'),
            duration=movie.get('durationSeconds'),
            cover=movie.get('bigPhotoUrl'),
            image=movie.get('bigPhotoUrl'),
            year=movie.get('productionYear'),
            geoblocked=movie.get('geoBlocked'),
            remaining=movie.get('remainingDaysAvailable'),
            legal=movie.get('legalIcons'),
            # aired=movie.get('broadcastTimestamp'),
            channel=self._parse_channel(movie.get('channelLogoUrl')),
        )
コード例 #5
0
    def get_program(self, program_id, cache=CACHE_AUTO):
        """ Get the details of the specified program.
        :type program_id: str
        :type cache: int
        :rtype Program
        """
        if cache in [CACHE_AUTO, CACHE_ONLY]:
            # Try to fetch from cache
            program = kodiutils.get_cache(['program', program_id])
            if program is None and cache == CACHE_ONLY:
                return None
        else:
            program = None

        if program is None:
            # Fetch from API
            response = util.http_get(API_ENDPOINT + '/%s/programs/%s' %
                                     (self._mode(), program_id),
                                     token=self._tokens.jwt_token,
                                     profile=self._tokens.profile)
            info = json.loads(response.text)
            program = info.get('program', {})
            kodiutils.set_cache(['program', program_id], program)

        channel = self._parse_channel(program.get('channelLogoUrl'))

        seasons = {}
        for item_season in program.get('seasons', []):
            episodes = {}

            for item_episode in item_season.get('episodes', []):
                episodes[item_episode.get('index')] = Episode(
                    episode_id=item_episode.get('id'),
                    program_id=program_id,
                    program_name=program.get('name'),
                    number=item_episode.get('index'),
                    season=item_season.get('index'),
                    name=item_episode.get('name'),
                    description=item_episode.get('description'),
                    duration=item_episode.get('durationSeconds'),
                    cover=item_episode.get('bigPhotoUrl'),
                    geoblocked=program.get('geoBlocked'),
                    remaining=item_episode.get('remainingDaysAvailable'),
                    channel=channel,
                    legal=program.get('legalIcons'),
                    aired=item_episode.get('broadcastTimestamp'),
                    progress=item_episode.get('playerPositionSeconds', 0),
                    watched=item_episode.get('doneWatching', False),
                )

            seasons[item_season.get('index')] = Season(
                number=item_season.get('index'),
                episodes=episodes,
                cover=item_season.get('episodes', [{}])[0].get('bigPhotoUrl')
                if episodes else program.get('bigPhotoUrl'),
                geoblocked=program.get('geoBlocked'),
                channel=channel,
                legal=program.get('legalIcons'),
            )

        return Program(
            program_id=program.get('id'),
            name=program.get('name'),
            description=program.get('description'),
            cover=program.get('bigPhotoUrl'),
            image=program.get('bigPhotoUrl'),
            geoblocked=program.get('geoBlocked'),
            seasons=seasons,
            channel=channel,
            legal=program.get('legalIcons'),
        )
コード例 #6
0
ファイル: vtmgo.py プロジェクト: add-ons/plugin.video.vtm.go
    def get_program(self, program_id, cache=CACHE_AUTO):
        """ Get the details of the specified program.
        :type program_id: str
        :type cache: int
        :rtype Program
        """
        if cache in [CACHE_AUTO, CACHE_ONLY]:
            # Try to fetch from cache
            program = kodiutils.get_cache(['program', program_id])
            if program is None and cache == CACHE_ONLY:
                return None
        else:
            program = None

        if program is None:
            # Fetch from API
            response = util.http_get(
                API_ENDPOINT + '/%s/programs/%s' % (self._mode(), program_id),
                token=self._tokens.jwt_token if self._tokens else None,
                profile=self._tokens.profile if self._tokens else None)
            info = json.loads(response.text)
            program = info.get('program', {})
            kodiutils.set_cache(['program', program_id], program)

        channel = self._parse_channel(program.get('channelLogoUrl'))

        # Calculate a hash value of the ids of all episodes
        program_hash = hashlib.md5()
        program_hash.update(program.get('id').encode())

        seasons = {}
        for item_season in program.get('seasons', []):
            episodes = {}

            for item_episode in item_season.get('episodes', []):
                episodes[item_episode.get('index')] = Episode(
                    episode_id=item_episode.get('id'),
                    program_id=program_id,
                    program_name=program.get('name'),
                    number=item_episode.get('index'),
                    season=item_season.get('index'),
                    name=item_episode.get('name'),
                    description=item_episode.get('description'),
                    duration=item_episode.get('durationSeconds'),
                    thumb=item_episode.get('bigPhotoUrl'),
                    fanart=item_episode.get('bigPhotoUrl'),
                    geoblocked=program.get('geoBlocked'),
                    remaining=item_episode.get('remainingDaysAvailable'),
                    channel=channel,
                    legal=program.get('legalIcons'),
                    aired=item_episode.get('broadcastTimestamp'),
                    progress=item_episode.get('playerPositionSeconds', 0),
                    watched=item_episode.get('doneWatching', False),
                )
                program_hash.update(item_episode.get('id').encode())

            seasons[item_season.get('index')] = Season(
                number=item_season.get('index'),
                episodes=episodes,
                channel=channel,
                legal=program.get('legalIcons'),
            )

        return Program(
            program_id=program.get('id'),
            name=program.get('name'),
            description=program.get('description'),
            year=program.get('productionYear'),
            thumb=program.get('teaserImageUrl'),
            fanart=program.get('bigPhotoUrl'),
            geoblocked=program.get('geoBlocked'),
            seasons=seasons,
            channel=channel,
            legal=program.get('legalIcons'),
            content_hash=program_hash.hexdigest().upper(),
            # my_list=program.get('addedToMyList'),  # Don't use addedToMyList, since we might have cached this info
        )