Пример #1
0
    def channel_videos(self, locale, channelid):
        offset, limit = request.args.get('start', 0), request.args.get('size', 20)
        order_by_position = request.args.get('position', 'f')

        vs = VideoSearch(locale)
        vs.add_term('channel', [channelid])
        if not order_by_position == 't':
            vs.add_sort('position', 'asc')
        vs.date_sort('desc')
        vs.add_sort('video.date_published', 'desc')
        vs.set_paging(offset, limit)

        ctx = {
            'videos': [],
            'image_cdn': app.config['IMAGE_CDN'],
            'referrer': request.args.get('referrer', request.referrer),
            'url': request.url,
            'path': request.path,
            'position': order_by_position,
        }

        for video in vs.results():
            c = {}
            c['id'] = video.id
            c['title'] = video.title
            try:
                c['date_added'] = video.date_added[:10]
            except TypeError:
                c['date_added'] = video.date_added.isoformat()[:10]
            c['thumbnail_url'] = video.video.thumbnail_url
            c['explanation'] = video.__dict__['_meta']['explanation']
            c['duration'] = video.video.duration
            c['source'] = Source.id_to_label(video.video.source)
            c['source_id'] = video.video.source_id
            c['subscriber_count'] = video.subscriber_count
            c['gbcount'] = video.locales['en-gb']['view_count']
            c['uscount'] = video.locales['en-us']['view_count']
            c['gbstarcount'] = video.locales['en-gb']['star_count']
            c['usstarcount'] = video.locales['en-us']['star_count']
            ctx['videos'].append(c)

        cs = ChannelSearch(locale)
        cs.add_id(channelid)
        channel = cs.channels()[0]
        ctx['channel'] = channel
        ctx['video_count'] = vs.total

        return self.render('admin/ranking.html', **ctx)
Пример #2
0
 def search_channels(self):
     if use_elasticsearch():
         ch = ChannelSearch(self.get_locale())
         offset, limit = self.get_page()
         ch.set_paging(offset, limit)
         ch.search_terms(request.args.get("q", ""))
         ch.add_filter(filters.verified_channel_boost())
         ch.add_filter(filters.negatively_boost_favourites())
         if request.args.get("order") == "latest":
             ch.date_sort("desc")
         items, total = ch.channels(with_owners=True), ch.total
     else:
         # DB fallback
         date_order = True if request.args.get("order") == "latest" else False
         items, total = get_db_channels(
             self.get_locale(), self.get_page(), query=request.args.get("q", ""), date_order=date_order
         )
     return dict(channels=dict(items=items, total=total))
Пример #3
0
    def ranking_locale(self, locale):
        category = int(request.args.get('category', 0))
        search = request.args.get('search')

        toggle_locale = {'en-us': 'en-gb', 'en-gb': 'en-us'}.get(locale)
        ctx = {
            'locale_base': self.url + '/locale/' + locale + '/',
            'locale_toggle_name': toggle_locale,
            'locale_toggle': self.url + '/locale/' + toggle_locale + '/',
            'categories': category_list(),
            'image_cdn': app.config['IMAGE_CDN'],
            'category': category,
            'locale': locale,
            'search_term': request.args.get('search', 'Search for a channel')}

        if category == 0:
            category = None

        cs = ChannelSearch(locale)
        offset, limit = request.args.get('start', 0), request.args.get('size', 20)
        cs.set_paging(offset, limit)
        if search:
            cs.add_text('title', search)
        else:
            cs.add_filter(filters.boost_from_field_value('editorial_boost'))
            cs.add_filter(filters.channel_rank_boost(locale))
            cs.add_filter(filters.negatively_boost_favourites())
            cs.filter_category(category)
            cs.promotion_settings(category)
        processed_channels = cs.channels(with_owners=True)

        ctx['channels'] = []

        # loop once to get the raw data
        raw_channels = {}
        for channel in cs.results():
            c = {}
            c['id'] = channel.id
            c['title'] = channel.title
            c['editorial_boost'] = channel.editorial_boost
            try:
                c['date_added'] = channel.date_added[:10]
            except TypeError:
                c['date_added'] = channel.date_added.isoformat()[:10]
            c['cover_thumbnail_large_url'] = channel.cover_thumbnail_large_url
            c['explanation'] = channel.__dict__['_meta']['explanation']
            c['subscriber_frequency'] = channel.subscriber_frequency
            c['subscriber_count'] = channel.subscriber_count
            c['video_update_frequency'] = channel.update_frequency
            c['subscriber_count'] = channel.subscriber_count
            c['promotion'] = channel.promotion
            c['gbcount'] = channel.locales['en-gb']['view_count']
            c['uscount'] = channel.locales['en-us']['view_count']
            c['normalised_rank'] = channel.normalised_rank
            raw_channels[channel.id] = c

        # loop again to get the correct order
        for channel in processed_channels:
            c = raw_channels[channel['id']]
            promo_string = '|'.join([locale, str(category or 0), str(channel['position'] + 1)])
            c['promoted'] = False
            if c.get('promotion', []) and promo_string in c.get('promotion', []):
                c['promoted'] = True
            ctx['channels'].append(c)

        return self.render('admin/ranking.html', **ctx)
Пример #4
0
def get_es_channels(locale, paging, category, category_boosts=None,
                    prefix_boosts=None, add_tracking=None, enable_promotion=True):
    cs = ChannelSearch(locale)
    cs.set_paging(*paging)
    # Boost popular channels based on ...
    if category_boosts:
        for boost in category_boosts:
            cs.add_filter(filters.category_boost(*boost))
    if prefix_boosts:
        for boost in prefix_boosts:
            cs.add_filter(filters.channel_prefix_boost(*boost))
    cs.add_filter(filters.boost_from_field_value('editorial_boost'))
    cs.add_filter(filters.negatively_boost_favourites())
    cs.add_filter(filters.channel_rank_boost(locale))
    cs.filter_category(category)
    if enable_promotion:
        cs.promotion_settings(category)
    cs.date_sort(request.args.get('date_order'))
    if request.args.get('user_id'):
        cs.add_term('owner', request.args.get('user_id'))
    channels = cs.channels(with_owners=True, add_tracking=add_tracking)
    return channels, cs.total