예제 #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
파일: api.py 프로젝트: wonderpl/dolly-web
    def video_list(self):
        if not use_elasticsearch():
            data, total = get_local_videos(self.get_locale(), self.get_page(), star_order=True, **request.args)
            return dict(videos=dict(items=data, total=total))

        date_order = request.args.get('date_order')
        if app.config.get('DOLLY'):
            date_order = 'desc'
        category = request.args.get('category')
        if category:
            try:
                int(category)
            except ValueError:
                abort(400)

        vs = VideoSearch(self.get_locale())
        offset, limit = self.get_page()
        vs.set_paging(offset, limit)
        vs.filter_category(category)

        if app.config.get('DOLLY'):
            # Filter by tagged/added date
            vs.add_filter(filters.date_tagged_sort())
            vs.add_sort('_score', order='desc')

            # exclude favs
            f = pyes.TermFilter(field='is_favourite', value=False)
            vs._exclusion_filters.append(f)
        else:
            vs.star_order_sort(request.args.get('star_order'))
            vs.date_sort(date_order)

        location = self.get_location()
        if location:
            vs.check_country_allowed(location)

        videos = vs.videos(with_channels=True)
        total = vs.total

        return dict(videos={'items': videos}, total=total)