Пример #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}}
Пример #2
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)
Пример #3
0
    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)
Пример #4
0
    def test_video_comments(self):
        with app.test_request_context():
            user_id = self.create_test_user().id
            with self.app.test_client() as client:
                # create new channel
                r = client.post(
                    '/ws/{}/channels/'.format(user_id),
                    data=json.dumps(dict(
                        title='test',
                        description='test',
                        category='',
                        cover='',
                        public=True,
                    )),
                    content_type='application/json',
                    headers=[get_auth_header(user_id)]
                )
                self.assertEquals(r.status_code, 201)
                channel_id = json.loads(r.data)['id']

                # add videos
                r = client.put(
                    '/ws/{}/channels/{}/videos/'.format(user_id, channel_id),
                    data=json.dumps([
                        VideoInstanceData.video_instance1.id,
                        VideoInstanceData.video_instance2.id,
                    ]),
                    content_type='application/json',
                    headers=[get_auth_header(user_id)]
                )
                self.assertEquals(r.status_code, 204)

                # add comment
                instance_data = dict(userid=user_id, channelid=channel_id)

                r = client.get(
                    '/ws/{userid}/channels/{channelid}/'.format(**instance_data),
                    content_type='application/json',
                    headers=[get_auth_header(user_id)])

                instance_data['videoid'] = json.loads(r.data)['videos']['items'][0]['id']

                r = client.post(
                    '/ws/{userid}/channels/{channelid}/videos/{videoid}/comments/'.format(**instance_data),
                    data=json.dumps(dict(comment="this is a comment")),
                    content_type='application/json',
                    headers=[get_auth_header(user_id)]
                )
                self.assertEquals(r.status_code, 201)

                self.wait_for_es()

                v = VideoSearch('en-gb')
                v.add_id(instance_data['videoid'])
                instance = v.videos()[0]
                self.assertEquals(instance['comments']['total'], 1)

                # delete comment
                r = client.get(
                    '/ws/{userid}/channels/{channelid}/videos/{videoid}/comments/'.format(**instance_data),
                    content_type='application/json',
                    headers=[get_auth_header(user_id)]
                )

                comment_id = json.loads(r.data)['comments']['items'][0]['id']
                instance_data.update({'commentid': comment_id})

                r = client.delete(
                    '/ws/{userid}/channels/{channelid}/videos/{videoid}/comments/{commentid}/'.format(**instance_data),
                    content_type='application/json',
                    headers=[get_auth_header(user_id)]
                )

                self.wait_for_es()

                v = VideoSearch('en-gb')
                v.add_id(instance_data['videoid'])
                instance = v.videos()[0]
                self.assertEquals(instance['comments']['total'], 0)
Пример #5
0
def search_video(videoid):
    v = VideoSearch('en-us')
    v.add_id(videoid)
    return v.videos()[0]