Exemple #1
0
 def video_channels(self, video_id, cache_age=3600):
     vs = VideoSearch(self.get_locale())
     vs.add_term('video.id', video_id)
     vs.add_sort('child_instance_count')
     vs.set_paging(*self.get_page(default_size=5))
     videos = vs.videos(with_channels=True)
     if not videos:
         abort(404)
     return {'channels': {'items': [v['channel'] for v in videos], 'total': vs.total}}
Exemple #2
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)
Exemple #3
0
 def _search_es(query):
     vs = VideoSearch(self.get_locale())
     # Split the term so that the search phrase is
     # over each individual word, and not the phrase
     # as a whole - the index will have tokenised
     # each word and without splitting we won't get
     # any results back (standard indexer on video title)
     if not app.config.get("DOLLY"):
         vs.add_term("title", query.split())
     else:
         # Snowball analyzer is on the Dolly mapping
         # so we can do a proper search here
         vs.search_terms(sub_string(query))
         vs.add_term("most_influential", True, occurs=MUST)
         # also clear any favs from search
     start, size = self.get_page()
     vs.set_paging(offset=start, limit=size)
     total = vs.total
     return total, vs.videos(add_tracking=_add_tracking)