예제 #1
0
    def _getMultImages(self, images, n):
        """
        Chooses the best n images and returns them as a list.
        If n<0, all images will be returned.
        """
        image_urls = []
        pool = []
        for image in images:
            if image.get('lang') == 'en':
                pool.append(image)
        orig_pool_size = len(pool)

        while len(pool) > 0 and (n < 0 or orig_pool_size - len(pool) < n):
            best = None
            highscore = -1
            for image in pool:
                if tryInt(image.get('likes')) > highscore:
                    highscore = tryInt(image.get('likes'))
                    best = image
            url = best.get('url') or best.get('href')
            if url:
                image_urls.append(url)
            pool.remove(best)

        return image_urls
예제 #2
0
    def _getMultImages(self, images, n):
        """
        Chooses the best n images and returns them as a list.
        If n<0, all images will be returned.
        """
        image_urls = []
        pool = []
        for image in images:
            if image.get('lang') == 'fr':
                pool.append(image)

        if len(pool) == 0:
            for image in images:
                if image.get('lang') == 'en':
                    pool.append(image)

        orig_pool_size = len(pool)

        while len(pool) > 0 and (n < 0 or orig_pool_size - len(pool) < n):
            best = None
            highscore = -1
            for image in pool:
                if tryInt(image.get('likes')) > highscore:
                    highscore = tryInt(image.get('likes'))
                    best = image
            url = best.get('url') or best.get('href')
            if url:
                image_urls.append(url)
            pool.remove(best)

        return image_urls
예제 #3
0
    def _getImage(self, images):
        image_url = None
        highscore = -1
        for image in images:
            if tryInt(image.get('likes')) > highscore:
                highscore = tryInt(image.get('likes'))
                image_url = image.get('url') or image.get('href')

        return image_url
예제 #4
0
    def _getImage(self, images):
        image_url = None
        highscore = -1
        for image in images:
            if tryInt(image.get('likes')) > highscore:
                highscore = tryInt(image.get('likes'))
                image_url = image.get('url') or image.get('href')

        return image_url
예제 #5
0
    def updateViewCache(self):

        if self.update_in_progress:
            while self.update_in_progress:
                time.sleep(1)
            catched_charts = self.getCache('charts_cached')
            if catched_charts:
                return catched_charts

        charts = []
        try:
            self.update_in_progress = True
            charts = fireEvent('automation.get_chart_list', merge=True)
            for chart in charts:
                chart['hide_wanted'] = self.conf('hide_wanted')
                chart['hide_library'] = self.conf('hide_library')
            self.setCache('charts_cached',
                          charts,
                          timeout=7200 *
                          tryInt(self.conf('update_interval', default=12)))
        except:
            log.error('Failed refreshing charts')

        self.update_in_progress = False

        return charts
예제 #6
0
    def save(self, **kwargs):

        try:
            db = get_db()

            profile = {
                '_t': 'profile',
                'label': toUnicode(kwargs.get('label')),
                'order': tryInt(kwargs.get('order', 999)),
                'core': kwargs.get('core', False),
                'qualities': [],
                'wait_for': [],
                'finish': [],
                '3d': []
            }

            # Update types
            order = 0
            for type in kwargs.get('types', []):
                profile['qualities'].append(type.get('quality'))
                profile['wait_for'].append(tryInt(kwargs.get('wait_for', 0)))
                profile['finish'].append((tryInt(type.get('finish')) == 1) if order > 0 else True)
                profile['3d'].append(tryInt(type.get('3d')))
                order += 1

            id = kwargs.get('id')
            try:
                p = db.get('id', id)
                profile['order'] = tryInt(kwargs.get('order', p.get('order', 999)))
            except:
                p = db.insert(profile)

            p.update(profile)
            db.update(p)

            return {
                'success': True,
                'profile': p
            }
        except:
            log.error('Failed: %s', traceback.format_exc())

        return {
            'success': False
        }
예제 #7
0
    def save(self, **kwargs):

        try:
            db = get_db()

            profile = {
                '_t': 'profile',
                'label': toUnicode(kwargs.get('label')),
                'order': tryInt(kwargs.get('order', 999)),
                'core': kwargs.get('core', False),
                'qualities': [],
                'wait_for': [],
                'finish': [],
                '3d': []
            }

            # Update types
            order = 0
            for type in kwargs.get('types', []):
                profile['qualities'].append(type.get('quality'))
                profile['wait_for'].append(tryInt(kwargs.get('wait_for', 0)))
                profile['finish'].append((
                    tryInt(type.get('finish')) == 1) if order > 0 else True)
                profile['3d'].append(tryInt(type.get('3d')))
                order += 1

            id = kwargs.get('id')
            try:
                p = db.get('id', id)
                profile['order'] = tryInt(
                    kwargs.get('order', p.get('order', 999)))
            except:
                p = db.insert(profile)

            p.update(profile)
            db.update(p)

            return {'success': True, 'profile': p}
        except:
            log.error('Failed: %s', traceback.format_exc())

        return {'success': False}
예제 #8
0
    def refresh(self, id="", **kwargs):
        handlers = []
        ids = splitString(id)

        for x in ids:

            refresh_handler = self.createRefreshHandler(x)
            if refresh_handler:
                handlers.append(refresh_handler)

        fireEvent("notify.frontend", type="media.busy", data={"id": [tryInt(x) for x in ids]})
        fireEventAsync("schedule.queue", handlers=handlers)

        return {"success": True}
예제 #9
0
    def refresh(self, id = '', **kwargs):
        handlers = []
        ids = splitString(id)

        for x in ids:

            refresh_handler = self.createRefreshHandler(x)
            if refresh_handler:
                handlers.append(refresh_handler)

        fireEvent('notify.frontend', type = 'media.busy', data = {'id': [tryInt(x) for x in ids]})
        fireEventAsync('schedule.queue', handlers = handlers)

        return {
            'success': True,
        }
예제 #10
0
    def refresh(self, id = '', **kwargs):
        db = get_session()

        handlers = []
        ids = splitString(id)

        for x in ids:

            refresh_handler = self.createRefreshHandler(x)
            if refresh_handler:
                handlers.append(refresh_handler)

        fireEvent('notify.frontend', type = 'media.busy', data = {'id': [tryInt(x) for x in ids]})
        fireEventAsync('schedule.queue', handlers = handlers)

        return {
            'success': True,
        }
예제 #11
0
    def updateViewCache(self):

        if self.update_in_progress:
            while self.update_in_progress:
                time.sleep(1)
            catched_charts = self.getCache('charts_cached')
            if catched_charts:
                return catched_charts

        try:
            self.update_in_progress = True
            charts = fireEvent('automation.get_chart_list', merge = True)
            self.setCache('charts_cached', charts, timeout = 7200 * tryInt(self.conf('update_interval', default = 12)))
        except:
            log.error('Failed refreshing charts')

        self.update_in_progress = False

        return charts
예제 #12
0
    def saveOrder(self, **kwargs):

        try:
            db = get_db()

            order = 0

            for profile_id in kwargs.get("ids", []):
                p = db.get("id", profile_id)
                p["hide"] = tryInt(kwargs.get("hidden")[order]) == 1
                p["order"] = order
                db.update(p)

                order += 1

            return {"success": True}
        except:
            log.error("Failed: %s", traceback.format_exc())

        return {"success": False}
예제 #13
0
    def getMovie(self, url):

        try:
            data = self.getUrl(url)
        except:
            return

        try:
            id = re.search("FilmId.*=.*\'(?P<id>.*)\';", data)
            id = id.group('id')

            data = self.getJsonData('https://trailers.apple.com/trailers/feeds/data/%s.json' % id)

            name = data['page']['movie_title']
            year = tryInt(data['page']['release_date'][0:4])

            return self.search(name, year)
        except:
            log.error('Failed getting apple trailer info: %s', traceback.format_exc())
            return None
예제 #14
0
    def saveOrder(self, **kwargs):

        try:
            db = get_db()

            order = 0

            for profile_id in kwargs.get('ids', []):
                p = db.get('id', profile_id)
                p['hide'] = tryInt(kwargs.get('hidden')[order]) == 1
                p['order'] = order
                db.update(p)

                order += 1

            return {'success': True}
        except:
            log.error('Failed: %s', traceback.format_exc())

        return {'success': False}
예제 #15
0
    def save(self, **kwargs):

        try:
            db = get_db()

            profile = {
                "_t": "profile",
                "label": toUnicode(kwargs.get("label")),
                "order": tryInt(kwargs.get("order", 999)),
                "core": kwargs.get("core", False),
                "minimum_score": tryInt(kwargs.get("minimum_score", 1)),
                "qualities": [],
                "wait_for": [],
                "stop_after": [],
                "finish": [],
                "3d": [],
            }

            # Update types
            order = 0
            for type in kwargs.get("types", []):
                profile["qualities"].append(type.get("quality"))
                profile["wait_for"].append(tryInt(kwargs.get("wait_for", 0)))
                profile["stop_after"].append(tryInt(kwargs.get("stop_after", 0)))
                profile["finish"].append((tryInt(type.get("finish")) == 1) if order > 0 else True)
                profile["3d"].append(tryInt(type.get("3d")))
                order += 1

            id = kwargs.get("id")
            try:
                p = db.get("id", id)
                profile["order"] = tryInt(kwargs.get("order", p.get("order", 999)))
            except:
                p = db.insert(profile)

            p.update(profile)
            db.update(p)

            return {"success": True, "profile": p}
        except:
            log.error("Failed: %s", traceback.format_exc())

        return {"success": False}
예제 #16
0
    def getMovie(self, url):

        try:
            data = self.getUrl(url)
        except:
            return

        try:
            id = re.search("FilmId.*=.*\'(?P<id>.*)\';", data)
            id = id.group('id')

            data = self.getJsonData(
                'https://trailers.apple.com/trailers/feeds/data/%s.json' % id)

            name = data['page']['movie_title']
            year = tryInt(data['page']['release_date'][0:4])

            return self.search(name, year)
        except:
            log.error('Failed getting apple trailer info: %s',
                      traceback.format_exc())
            return None
예제 #17
0
파일: main.py 프로젝트: Adelscott/persomov
    def saveOrder(self, **kwargs):

        try:
            db = get_db()

            order = 0

            for profile_id in kwargs.get('ids', []):
                p = db.get('id', profile_id)
                p['hide'] = tryInt(kwargs.get('hidden')[order]) == 1
                p['order'] = order
                db.update(p)

                order += 1

            return {
                'success': True
            }
        except:
            log.error('Failed: %s', traceback.format_exc())

        return {
            'success': False
        }
예제 #18
0
    def list(self, types = None, status = None, release_status = None, status_or = False, limit_offset = None, with_tags = None, starts_with = None, search = None):

        db = get_db()

        # Make a list from string
        if status and not isinstance(status, (list, tuple)):
            status = [status]
        if release_status and not isinstance(release_status, (list, tuple)):
            release_status = [release_status]
        if types and not isinstance(types, (list, tuple)):
            types = [types]
        if with_tags and not isinstance(with_tags, (list, tuple)):
            with_tags = [with_tags]

        # query media ids
        if types:
            all_media_ids = set()
            for media_type in types:
                all_media_ids = all_media_ids.union(set([x['_id'] for x in db.get_many('media_by_type', media_type)]))
        else:
            all_media_ids = set([x['_id'] for x in db.all('media')])

        media_ids = list(all_media_ids)
        filter_by = {}

        # Filter on movie status
        if status and len(status) > 0:
            filter_by['media_status'] = set()
            for media_status in fireEvent('media.with_status', status, with_doc = False, single = True):
                filter_by['media_status'].add(media_status.get('_id'))

        # Filter on release status
        if release_status and len(release_status) > 0:
            filter_by['release_status'] = set()
            for release_status in fireEvent('release.with_status', release_status, with_doc = False, single = True):
                filter_by['release_status'].add(release_status.get('media_id'))

        # Add search filters
        if starts_with:
            starts_with = toUnicode(starts_with.lower())[0]
            starts_with = starts_with if starts_with in ascii_lowercase else '#'
            filter_by['starts_with'] = [x['_id'] for x in db.get_many('media_startswith', starts_with)]

        # Add tag filter
        if with_tags:
            filter_by['with_tags'] = set()
            for tag in with_tags:
                for x in db.get_many('media_tag', tag):
                    filter_by['with_tags'].add(x['_id'])

        # Filter with search query
        if search:
            filter_by['search'] = [x['_id'] for x in db.get_many('media_search_title', search)]

        if status_or and 'media_status' in filter_by and 'release_status' in filter_by:
            filter_by['status'] = list(filter_by['media_status']) + list(filter_by['release_status'])
            del filter_by['media_status']
            del filter_by['release_status']

        # Filter by combining ids
        for x in filter_by:
            media_ids = [n for n in media_ids if n in filter_by[x]]

        total_count = len(media_ids)
        if total_count == 0:
            return 0, []

        offset = 0
        limit = -1
        if limit_offset:
            splt = splitString(limit_offset) if isinstance(limit_offset, (str, unicode)) else limit_offset
            limit = tryInt(splt[0])
            offset = tryInt(0 if len(splt) is 1 else splt[1])

        # List movies based on title order
        medias = []
        for m in db.all('media_title'):
            media_id = m['_id']
            if media_id not in media_ids: continue
            if offset > 0:
                offset -= 1
                continue

            media = fireEvent('media.get', media_id, single = True)

            # Merge releases with movie dict
            medias.append(media)

            # remove from media ids
            media_ids.remove(media_id)
            if len(media_ids) == 0 or len(medias) == limit: break

        return total_count, medias
예제 #19
0
    def list(self,
             types=None,
             status=None,
             release_status=None,
             status_or=False,
             limit_offset=None,
             starts_with=None,
             search=None):

        db = get_db()

        # Make a list from string
        if status and not isinstance(status, (list, tuple)):
            status = [status]
        if release_status and not isinstance(release_status, (list, tuple)):
            release_status = [release_status]
        if types and not isinstance(types, (list, tuple)):
            types = [types]

        # query media ids
        if types:
            all_media_ids = set()
            for media_type in types:
                all_media_ids = all_media_ids.union(
                    set([
                        x['_id']
                        for x in db.get_many('media_by_type', media_type)
                    ]))
        else:
            all_media_ids = set([x['_id'] for x in db.all('media')])

        media_ids = list(all_media_ids)
        filter_by = {}

        # Filter on movie status
        if status and len(status) > 0:
            filter_by['media_status'] = set()
            for media_status in fireEvent('media.with_status',
                                          status,
                                          with_doc=False,
                                          single=True):
                filter_by['media_status'].add(media_status.get('_id'))

        # Filter on release status
        if release_status and len(release_status) > 0:
            filter_by['release_status'] = set()
            for release_status in fireEvent('release.with_status',
                                            release_status,
                                            with_doc=False,
                                            single=True):
                filter_by['release_status'].add(release_status.get('media_id'))

        # Add search filters
        if starts_with:
            filter_by['starts_with'] = set()
            starts_with = toUnicode(starts_with.lower())[0]
            starts_with = starts_with if starts_with in ascii_lowercase else '#'
            filter_by['starts_with'] = [
                x['_id'] for x in db.get_many('media_startswith', starts_with)
            ]

        # Filter with search query
        if search:
            filter_by['search'] = [
                x['_id'] for x in db.get_many('media_search_title', search)
            ]

        if status_or and 'media_status' in filter_by and 'release_status' in filter_by:
            filter_by['status'] = list(filter_by['media_status']) + list(
                filter_by['release_status'])
            del filter_by['media_status']
            del filter_by['release_status']

        # Filter by combining ids
        for x in filter_by:
            media_ids = [n for n in media_ids if n in filter_by[x]]

        total_count = len(media_ids)
        if total_count == 0:
            return 0, []

        offset = 0
        limit = -1
        if limit_offset:
            splt = splitString(limit_offset) if isinstance(
                limit_offset, (str, unicode)) else limit_offset
            limit = tryInt(splt[0])
            offset = tryInt(0 if len(splt) is 1 else splt[1])

        # List movies based on title order
        medias = []
        for m in db.all('media_title'):
            media_id = m['_id']
            if media_id not in media_ids: continue
            if offset > 0:
                offset -= 1
                continue

            media = fireEvent('media.get', media_id, single=True)

            # Merge releases with movie dict
            medias.append(media)

            # remove from media ids
            media_ids.remove(media_id)
            if len(media_ids) == 0 or len(medias) == limit: break

        return total_count, medias