Esempio n. 1
0
    def retrieve_data(self):
        from notification_handler import get_img_info, set_hash_image_info

        if not self.config['incl_libraries']:
            logger.warn(u"Tautulli Newsletters :: Failed to retrieve %s newsletter data: no libraries selected." % self.NAME)

        media_types = {s['section_type'] for s in self._get_sections()
                       if str(s['section_id']) in self.config['incl_libraries']}

        recently_added = {}
        for media_type in media_types:
            if media_type not in recently_added:
                recently_added[media_type] = self._get_recently_added(media_type)

        movies = recently_added.get('movie', [])
        shows = recently_added.get('show', [])
        artists = recently_added.get('artist', [])
        albums = [a for artist in artists for a in artist['album']]

        if self.is_preview or plexpy.CONFIG.NEWSLETTER_SELF_HOSTED:
            for item in movies + shows + albums:
                if item['media_type'] == 'album':
                    height = 150
                    fallback = 'cover'
                else:
                    height = 225
                    fallback = 'poster'

                item['thumb_hash'] = set_hash_image_info(
                    img=item['thumb'], width=150, height=height, fallback=fallback)

                if item['art']:
                    item['art_hash'] = set_hash_image_info(
                        img=item['art'], width=500, height=280,
                        opacity=25, background='282828', blur=3, fallback='art')
                else:
                    item['art_hash'] = ''

                item['poster_url'] = ''
                item['art_url'] = ''

        else:
            # Upload posters and art to image hosting service
            for item in movies + shows + albums:
                if item['media_type'] == 'album':
                    height = 150
                    fallback = 'cover'
                else:
                    height = 225
                    fallback = 'poster'

                img_info = get_img_info(
                    img=item['thumb'], rating_key=item['rating_key'], title=item['title'],
                    width=150, height=height, fallback=fallback)

                item['poster_url'] = img_info.get('img_url') or common.ONLINE_POSTER_THUMB

                img_info = get_img_info(
                    img=item['art'], rating_key=item['rating_key'], title=item['title'],
                    width=500, height=280, opacity=25, background='282828', blur=3, fallback='art')

                item['art_url'] = img_info.get('img_url')

                item['thumb_hash'] = ''
                item['art_hash'] = ''

        self.data['recently_added'] = recently_added

        return self.data
Esempio n. 2
0
    def retrieve_data(self):
        from notification_handler import get_img_info, set_hash_image_info

        if not self.config['incl_libraries']:
            logger.warn(
                u"Tautulli Newsletters :: Failed to retrieve %s newsletter data: no libraries selected."
                % self.NAME)

        media_types = set()
        for s in self._get_sections():
            if str(s['section_id']) in self.config['incl_libraries']:
                if s['section_type'] == 'movie' and s[
                        'agent'] == 'com.plexapp.agents.none':
                    media_types.add('other_video')
                else:
                    media_types.add(s['section_type'])

        recently_added = {}
        for media_type in media_types:
            if media_type not in recently_added:
                recently_added[media_type] = self._get_recently_added(
                    media_type)

        movies = recently_added.get('movie', [])
        shows = recently_added.get('show', [])
        artists = recently_added.get('artist', [])
        albums = [a for artist in artists for a in artist['album']]
        other_video = recently_added.get('other_video', [])

        if self.is_preview or helpers.get_img_service(
                include_self=True) == 'self-hosted':
            for item in movies + shows + albums + other_video:
                if item['media_type'] == 'album':
                    height = 150
                    fallback = 'cover'
                else:
                    height = 225
                    fallback = 'poster'

                item['thumb_hash'] = set_hash_image_info(img=item['thumb'],
                                                         width=150,
                                                         height=height,
                                                         fallback=fallback)

                if item['art']:
                    item['art_hash'] = set_hash_image_info(img=item['art'],
                                                           width=500,
                                                           height=280,
                                                           opacity=25,
                                                           background='282828',
                                                           blur=3,
                                                           fallback='art')
                else:
                    item['art_hash'] = ''

                item['thumb_url'] = ''
                item['art_url'] = ''
                item['poster_url'] = item[
                    'thumb_url']  # Keep for backwards compatibility

        elif helpers.get_img_service():
            # Upload posters and art to image hosting service
            for item in movies + shows + albums + other_video:
                if item['media_type'] == 'album':
                    height = 150
                    fallback = 'cover'
                else:
                    height = 225
                    fallback = 'poster'

                img_info = get_img_info(img=item['thumb'],
                                        rating_key=item['rating_key'],
                                        title=item['title'],
                                        width=150,
                                        height=height,
                                        fallback=fallback)

                item['thumb_url'] = img_info.get(
                    'img_url') or common.ONLINE_POSTER_THUMB

                img_info = get_img_info(img=item['art'],
                                        rating_key=item['rating_key'],
                                        title=item['title'],
                                        width=500,
                                        height=280,
                                        opacity=25,
                                        background='282828',
                                        blur=3,
                                        fallback='art')

                item['art_url'] = img_info.get('img_url')

                item['thumb_hash'] = ''
                item['art_hash'] = ''
                item['poster_url'] = item[
                    'thumb_url']  # Keep for backwards compatibility

        else:
            for item in movies + shows + albums + other_video:
                item['thumb_hash'] = ''
                item['art_hash'] = ''
                item['thumb_url'] = ''
                item['art_url'] = ''
                item['poster_url'] = item[
                    'thumb_url']  # Keep for backwards compatibility

        self.data['recently_added'] = recently_added

        return self.data