Пример #1
0
    def post(self, request):
        # pass filled out HTML-Form from View to NewVideoForm()
        form = NewVideoForm(request.POST, request.FILES)

        if form.is_valid():
            # create a new Video Entry
            title = form.cleaned_data['title']
            description = form.cleaned_data['description']
            file = form.cleaned_data['file']

            random_char = ''.join(
                random.choices(string.ascii_uppercase + string.digits, k=10))
            path = random_char + file.name
            print("TTTTTTT     ", path)
            fs = FileSystemStorage(location=os.path.dirname(
                os.path.dirname(os.path.abspath(__file__))))
            filename = fs.save("core/static/videos/" + path, file)
            file_url = fs.url(filename)

            print(fs)
            print(filename)
            print(file_url)

            new_video = Video(title=title,
                              description=description,
                              user=request.user,
                              path=path)
            new_video.save()

            # redirect to detail view template of a Video
            return HttpResponseRedirect('/video/{}'.format(new_video.id))
        else:
            return HttpResponse(
                'Your form is not valid. Go back and try again.')
Пример #2
0
    def update_units(cls, units_data, lesson):
        units = []
        for unit_data in units_data:
            activities_data = unit_data.pop('activities')
            unit_data.pop('lesson', None)

            video_data = unit_data.pop('video', None)
            if video_data:
                video = Video(**video_data)
                video.save()
            else:
                video = None
            unit = Unit(lesson=lesson, video=video, **unit_data)
            unit.save()
            activities = []
            for activity_data in activities_data:
                # import pdb;pdb.set_trace()
                activity_id = activity_data.pop('id', None)
                activity, _ = Activity.objects.get_or_create(id=activity_id)
                activity.comment = activity_data.get('comment', None)
                activity.data = activity_data.get('data', None)
                activity.expected = activity_data.get('expected', None)
                activity.type = activity_data.get('type', None)
                activity.unit = unit
                activity.save()
                activities.append(activity)
            unit.activities = activities
            units.append(unit)
        return units
Пример #3
0
    def update_units(cls, units_data, lesson):
        units = []
        for unit_data in units_data:
            activities_data = unit_data.pop('activities')
            unit_data.pop('lesson', None)

            video_data = unit_data.pop('video', None)
            if video_data:
                video = Video(**video_data)
                video.save()
            else:
                video = None
            unit = Unit(lesson=lesson, video=video, **unit_data)
            unit.save()
            activities = []
            for activity_data in activities_data:
                # import pdb;pdb.set_trace()
                activity_id = activity_data.pop('id', None)
                activity, _ = Activity.objects.get_or_create(id=activity_id)
                activity.comment = activity_data.get('comment', None)
                activity.data = activity_data.get('data', None)
                activity.expected = activity_data.get('expected', None)
                activity.type = activity_data.get('type', None)
                activity.unit = unit
                activity.save()
                activities.append(activity)
            unit.activities = activities
            units.append(unit)
        return units
Пример #4
0
 def test_get_all(self):
     self.repo.insert(Video(1, 'the name of the playlist', 'thumbnail'))
     self.repo.insert(
         Video(2, 'the name of another playlist', 'another thumbnail'))
     self.assertEqual([
         Video(1, 'the name of the playlist', 'thumbnail'),
         Video(2, 'the name of another playlist', 'another thumbnail')
     ], self.repo.get_all())
Пример #5
0
 def test_get_some_ids(self):
     self.repo.insert(Video(1, 'name1', 'thumbnail1'))
     self.repo.insert(Video(2, 'name2', 'thumbnail2'))
     self.repo.insert(Video(3, 'name3', 'thumbnail3'))
     self.assertEqual(
         [Video(1, 'name1', 'thumbnail1'),
          Video(2, 'name2', 'thumbnail2')], self.repo.get_some(1, 2))
     self.assertEqual([], self.repo.get_some())
Пример #6
0
    async def create_post(self, task_message: PostTaskMessage) -> bool:
        post = get_object_or_none(Post, pk=task_message.post_id)
        if not post:
            logger.error('Post Not Found Post id {}'.format(
                task_message.post_id))
            return False

        user = User.objects.get(pk=task_message.user_id)
        group = Group.objects.get(pk=task_message.target_group_id)
        campaign = AdvertisingCampaign.objects.get(pk=task_message.campaign_id)

        description = task_message.text
        target_video_upload = task_message.target_video_upload

        social_uid, access_token = self._get_vk_credentials(user=user)

        video = Video.objects.filter(group=group,
                                     campaign=campaign,
                                     user=user,
                                     status=Video.IS_ACTIVE).first()

        if not video:
            video = Video(group=group,
                          campaign=campaign,
                          user=user,
                          status=Video.IN_PROGRESS,
                          factor=settings.KOFF)
            video.save()

            to_group = target_video_upload == TargetVideoUpload.GROUP.value
            status_ok = await self._video_save(post=post,
                                               video=video,
                                               access_token=access_token,
                                               campaign=campaign,
                                               description=description,
                                               priority=task_message.priority,
                                               group=group,
                                               to_group=to_group)

            if not status_ok:
                post.status = Post.FAILED
                post.vk_response = video.vk_response
                post.save()
                return False

            if status_ok == VideoSaveMethod.TOO_MUCH_REQUESTS_MSG:
                return False

        return await self._wall_post(access_token=access_token,
                                     group=group,
                                     video=video,
                                     priority=task_message.priority,
                                     description=description,
                                     post=post,
                                     campaign_pk=campaign.pk)
Пример #7
0
 def post(self, request, *args, **kwargs):
     cls_choices = {'电影': 1, 'mv': 2, '搞笑': 3, '综艺': 4, '春节': 5, 'gif': -1}
     json_data = json.loads(request.body)
     cls = json_data.get('classification').lower()
     total_frames = int(json_data.get('frames', 0))
     duration = float(json_data.get('duration', 0.0))
     fps = int(json_data.get('fps', 25))
     tracks = json_data.get('tracks')
     if tracks:
         cls = cls_choices.get(cls, 1)
         title = json_data.get('title')
         author = json_data.get('author')
         reference = json_data.get('reference')
         url = json_data.get('url')
         url = url.replace('oda176fz0.bkt.clouddn.com', 'static.fibar.cn')
         vs = Video.objects.filter(url=url)
         if not vs.exists():
             thumb_nail = '{0}?vframe/jpg/offset/0/w/200/h/200/'.format(url)
             video = Video(title=title,
                           url=url,
                           author=author,
                           reference=reference,
                           thumb_nail=thumb_nail,
                           total_frames=total_frames,
                           duration=duration,
                           hidden=True,
                           fps=fps,
                           classification=cls)
             if cls == -1:
                 video.is_gif = True
             video.save()
         else:
             vs = vs[0]
             vs.title = title
             vs.author = author
             vs.reference = reference
             vs.save()
         video = Video.objects.get(url=url)
         at = AvatarTrack.objects.filter(video=video)
         if at.exists():
             for itm in at:
                 itm.delete()
         tracks = unicode(format_tracks_data(tracks, total_frames,
                                             duration))
         AvatarTrack(data=tracks, video=video).save()
         return self.render_to_response({})
     self.message = '追踪数据缺失'
     self.status_code = INFO_NO_EXIST
     return self.render_to_response({})
Пример #8
0
 def get_some(self, *video_ids):
     if not video_ids:
         return []
     sql = "SELECT ID, TITLE, THUMBNAIL FROM VIDEO WHERE ID in (%s)" % ','.join(self.ph['ph'] for _ in video_ids)
     cursor = self.connection.cursor()
     cursor.execute(sql, video_ids)
     return [Video(*row) for row in cursor.fetchall()]
Пример #9
0
 def get(self, video_id):
     cursor = self.connection.cursor()
     cursor.execute("SELECT ID, TITLE, THUMBNAIL FROM VIDEO WHERE ID=%(ph)s" % self.ph, (video_id,))
     row = cursor.fetchone()
     if not row:
         raise MissingVideo()
     return Video(*row)
Пример #10
0
    def test_url_is_unique(self):
        # Arrange.
        code = Video.objects.get(name="Test 1").url

        # Act.
        video = Video(name="Test 2", url=code)

        # Assert.
        self.assertRaises(ValidationError, video.save)
Пример #11
0
    def test_delete_video(self):
        video_repository = InMemoryVideoRepository({
            1: Video(1, 'the title of the video', 'The url of the video'),
        })
        playlist_video_repository = InMemoryPlaylistVideoRepository({})

        VideosUsecases(video_repository, playlist_video_repository).delete(1)

        self.assertEqual({}, video_repository.storage)
Пример #12
0
    def test_add_video_to_playlist(self):
        video_repository = InMemoryVideoRepository({50: Video(50, None, None)})
        playlist_repository = InMemoryPlaylistRepository({100: [Playlist(100, None)]})
        playlist_video_repository = InMemoryPlaylistVideoRepository({})

        usecase = PlaylistsVideosUsecases(playlist_repository, playlist_video_repository, video_repository)

        usecase.add(100, 50)

        self.assertEqual({100: [50]}, playlist_video_repository.storage)
Пример #13
0
    def test_create_video(self):
        a_video = {
            'title': 'the title of the video',
            'thumbnail': 'The url of the video',
        }
        video_repository = InMemoryVideoRepository({})
        VideosUsecases(video_repository, None).add(a_video)

        self.assertEqual({1: Video(1, 'the title of the video', 'The url of the video')},
                         video_repository.storage)
Пример #14
0
    def test_create_video(self):
        expected_result = {
            'data': [{
                'id': 1,
                'title': 'the title of the video',
                'thumbnail': 'The url of the video',
            },{
                'id': 2,
                'title': 'another title',
                'thumbnail': 'another url',
            }]
        }

        video_repository = InMemoryVideoRepository({
            1: Video(1, 'the title of the video', 'The url of the video'),
            2: Video(2, 'another title', 'another url')
        })

        self.assertEqual(expected_result, VideosUsecases(video_repository, None).get())
Пример #15
0
    def test_get_playlists(self):
        expected_result = {
            'data': [{
                'id': 1,
                'title': 'the title of the video',
                'thumbnail': 'a thumbnail'
            },{
                'id': 2,
                'title': 'another title',
                'thumbnail': 'another thumbnail'
            }]
        }

        playlist_repository = InMemoryPlaylistRepository({10: Playlist(10, 'name'), 11: Playlist(11, 'name')})
        video_repository = InMemoryVideoRepository({1: Video(1, 'the title of the video', 'a thumbnail'),
                                                    2: Video(2, 'another title', 'another thumbnail')})
        playlist_video_repository = InMemoryPlaylistVideoRepository({10: [1, 2]})

        usecase = PlaylistsVideosUsecases(playlist_repository, playlist_video_repository, video_repository)

        self.assertEqual(expected_result, usecase.get_all(10))
        self.assertEqual({'data':[]}, usecase.get_all(11))
Пример #16
0
 def test_delete(self):
     self.repo.insert(Video(1, 'the name of the playlist', 'thumbnail'))
     self.repo.delete(1)
     self.assertEqual([], self.repo.get_all())
Пример #17
0
 def get_all(self):
     cursor = self.connection.cursor()
     cursor.execute("SELECT ID, TITLE, THUMBNAIL FROM VIDEO")
     return [Video(*row) for row in cursor.fetchall()]
Пример #18
0
 def test_create(self):
     self.repo.insert(Video(None, 'the name of the playlist', 'thumbnail'))
     self.assertEqual([Video(1, 'the name of the playlist', 'thumbnail')],
                      self.repo.get_all())
Пример #19
0
 def test_get_a_video(self):
     self.repo.insert(Video(1, 'name1', 'thumbnail1'))
     self.assertEqual(Video(1, 'name1', 'thumbnail1'), self.repo.get(1))
Пример #20
0
 def add(self, data):
     self._validate(data)
     video = Video(None, data['title'], data['thumbnail'])
     self.video_repository.insert(video)
Пример #21
0
 def insert(self, video):
     self.counter = max(self.counter + 1, video.id or 0)
     self.storage[self.counter] = Video(self.counter, video.title,
                                        video.thumbnail)