Exemplo n.º 1
0
 def handle(self, **options):
     verbosity = int(options['verbosity'])
     import_ = not options['no_import']
     fetch_screencaptures(max_=int(options['max']),
                          dry_run=options['dry_run'],
                          save_locally=options['save_locally'],
                          save_locally_some=options['save_locally_some'],
                          import_=import_,
                          verbose=verbosity > 1)
Exemplo n.º 2
0
 def handle(self, **options):
     verbosity = int(options['verbosity'])
     fetch_screencaptures(
         max_=int(options['max']),
         dry_run=options['dry_run'],
         save_locally=options['save_locally'],
         save_locally_some=options['save_locally_some'],
         verbose=verbosity > 1
     )
Exemplo n.º 3
0
 def handle(self, **options):
     verbosity = int(options["verbosity"])
     import_ = not options["no_import"]
     fetch_screencaptures(
         max_=int(options["max"]),
         dry_run=options["dry_run"],
         save_locally=options["save_locally"],
         save_locally_some=options["save_locally_some"],
         import_=import_,
         verbose=verbosity > 1,
     )
Exemplo n.º 4
0
    def test_fetch_screencapture_without_import(
        self, mock_popen, rhead, p_urllib2, p_log
    ):
        """This test is effectively the same as test_fetch_screencapture()
        but with `import_=False` set.
        """
        def mocked_urlopen(request):
            return StringIO("""
            <?xml version="1.0"?>
            <Response>
              <Message>OK</Message>
              <MessageCode>7.4</MessageCode>
              <Success>
                <MediaShortLink>xxx999</MediaShortLink>
                <Token>MXCsxINnVtycv6j02ZVIlS4FcWP</Token>
              </Success>
            </Response>
            """)

        p_urllib2.urlopen = mocked_urlopen

        def mocked_head(url, **options):
            return Response(
                '',
                200
            )

        rhead.side_effect = mocked_head

        ffmpeged_urls = []

        sample_jpg = self.sample_jpg
        sample_jpg2 = self.sample_jpg2

        def mocked_popen(command, **kwargs):
            url = command[4]
            ffmpeged_urls.append(url)
            destination = command[-1]
            assert os.path.isdir(os.path.dirname(destination))

            class Inner:
                def communicate(self):
                    out = err = ''
                    if 'xyz123' in url:
                        # Let's create two jpeg's in that directory
                        if '01.jpg' in destination:
                            shutil.copyfile(sample_jpg, destination)
                        else:
                            shutil.copyfile(sample_jpg2, destination)
                    else:
                        raise NotImplementedError(url)
                    return out, err

            return Inner()

        mock_popen.side_effect = mocked_popen

        event = Event.objects.get(title='Test event')
        template = Template.objects.create(
            name='Vid.ly Something',
            content="{{ tag }}"
        )
        event.duration = 1157
        event.template = template
        event.save()

        # Make sure it has a HD VidlySubmission
        VidlySubmission.objects.create(
            event=event,
            url='https://s3.com/asomething.mov',
            tag='xyz123',
            hd=True,
        )
        event.template_environment = {'tag': 'xyz123'}
        event.save()
        videoinfo.fetch_screencaptures(import_=False)
        assert ffmpeged_urls
        eq_(Picture.objects.filter(event=event).count(), 0)

        # there should now be some JPEGs in the dedicated temp directory
        temp_dir = os.path.join(
            tempfile.gettempdir(),
            settings.SCREENCAPTURES_TEMP_DIRECTORY_NAME
        )
        # expect there to be a directory with the event's ID
        directory_name = '%s_%s' % (event.id, event.slug)
        event_temp_dir = os.path.join(temp_dir, directory_name)
        ok_(os.path.isdir(event_temp_dir))
        # there should be X JPEGs in there
        no_screencaptures = settings.SCREENCAPTURES_NO_PICTURES
        eq_(
            sorted(os.listdir(event_temp_dir)),
            ["screencap-%02d.jpg" % x for x in range(1, no_screencaptures + 1)]
        )
Exemplo n.º 5
0
    def test_fetch_screencapture(self, mock_popen, rhead, p_urllib2, p_log):

        assert Picture.objects.all().count() == 0, Picture.objects.all()

        def mocked_urlopen(request):
            return StringIO("""
            <?xml version="1.0"?>
            <Response>
              <Message>OK</Message>
              <MessageCode>7.4</MessageCode>
              <Success>
                <MediaShortLink>xxx999</MediaShortLink>
                <Token>MXCsxINnVtycv6j02ZVIlS4FcWP</Token>
              </Success>
            </Response>
            """)

        p_urllib2.urlopen = mocked_urlopen

        def mocked_head(url, **options):
            return Response(
                '',
                200
            )

        rhead.side_effect = mocked_head

        ffmpeged_urls = []

        sample_jpg = self.sample_jpg
        sample_jpg2 = self.sample_jpg2

        def mocked_popen(command, **kwargs):
            url = command[4]
            ffmpeged_urls.append(url)
            destination = command[-1]
            assert os.path.isdir(os.path.dirname(destination))

            class Inner:
                def communicate(self):
                    out = err = ''
                    if 'xyz123' in url:
                        if '01.jpg' in destination:
                            shutil.copyfile(sample_jpg, destination)
                        else:
                            shutil.copyfile(sample_jpg2, destination)
                    else:
                        raise NotImplementedError(url)
                    return out, err

            return Inner()

        mock_popen.side_effect = mocked_popen

        event = Event.objects.get(title='Test event')
        template = Template.objects.create(
            name='Vid.ly Something',
            content="{{ tag }}"
        )
        event.template = template
        event.save()
        assert event.duration is None

        videoinfo.fetch_screencaptures()
        assert not ffmpeged_urls  # because no event has a duration yet
        event.duration = 1157
        event.save()

        # Make sure it has a HD VidlySubmission
        VidlySubmission.objects.create(
            event=event,
            url='https://s3.com/asomething.mov',
            tag='xyz123',
            hd=True,
        )
        event.template_environment = {'tag': 'xyz123'}
        event.save()
        videoinfo.fetch_screencaptures()
        assert ffmpeged_urls
        no_screencaptures = settings.SCREENCAPTURES_NO_PICTURES
        eq_(Picture.objects.filter(event=event).count(), no_screencaptures)

        # When viewed, like it's viewed in the picture gallery and gallery
        # select widget, we want the one called "Screencap 1" to appear
        # before the one called "Screencap 2"
        pictures = Picture.objects.all().order_by('event', '-created')
        notes = [x.notes for x in pictures]
        eq_(
            notes,
            ["Screencap %d" % x for x in range(1, no_screencaptures + 1)]
        )

        # Try to do it again and it shouldn't run it again
        # because there are pictures in the gallery already.
        assert len(ffmpeged_urls) == no_screencaptures, len(ffmpeged_urls)
        videoinfo.fetch_screencaptures()
        eq_(len(ffmpeged_urls), no_screencaptures)
        # and still
        eq_(Picture.objects.filter(event=event).count(), no_screencaptures)
Exemplo n.º 6
0
    def test_fetch_screencapture_import_immediately(self, mock_popen, rhead,
                                                    p_urllib2, p_log):
        """This test is effectively the same as test_fetch_screencapture()
        but with `import_immediately=True` set.
        """
        def mocked_urlopen(request):
            return StringIO("""
            <?xml version="1.0"?>
            <Response>
              <Message>OK</Message>
              <MessageCode>7.4</MessageCode>
              <Success>
                <MediaShortLink>xxx999</MediaShortLink>
                <Token>MXCsxINnVtycv6j02ZVIlS4FcWP</Token>
              </Success>
            </Response>
            """)

        p_urllib2.urlopen = mocked_urlopen

        def mocked_head(url, **options):
            return Response('', 200)

        rhead.side_effect = mocked_head

        ffmpeged_urls = []

        sample_jpg = self.sample_jpg
        sample_jpg2 = self.sample_jpg2

        def mocked_popen(command, **kwargs):
            url = command[4]
            ffmpeged_urls.append(url)
            destination = command[-1]
            assert os.path.isdir(os.path.dirname(destination))

            class Inner:
                def communicate(self):
                    out = err = ''
                    if 'xyz123' in url:
                        # Let's create two jpeg's in that directory
                        if '01.jpg' in destination:
                            shutil.copyfile(sample_jpg, destination)
                        else:
                            shutil.copyfile(sample_jpg2, destination)
                    else:
                        raise NotImplementedError(url)
                    return out, err

            return Inner()

        mock_popen.side_effect = mocked_popen

        event = Event.objects.get(title='Test event')
        template = Template.objects.create(name='Vid.ly Something',
                                           content="{{ tag }}")
        event.duration = 1157
        event.template = template
        event.save()

        # Make sure it has a HD VidlySubmission
        VidlySubmission.objects.create(
            event=event,
            url='https://s3.com/asomething.mov',
            tag='xyz123',
            hd=True,
        )
        event.template_environment = {'tag': 'xyz123'}
        event.save()
        videoinfo.fetch_screencaptures(import_immediately=True)
        assert ffmpeged_urls
        eq_(
            Picture.objects.filter(event=event).count(),
            settings.SCREENCAPTURES_NO_PICTURES)

        # there should now be some JPEGs in the dedicated temp directory
        temp_dir = os.path.join(tempfile.gettempdir(),
                                settings.SCREENCAPTURES_TEMP_DIRECTORY_NAME)
        # expect there to be a directory with the event's ID
        directory_name = '%s_%s' % (event.id, event.slug)
        event_temp_dir = os.path.join(temp_dir, directory_name)
        ok_(not os.path.isdir(event_temp_dir))
Exemplo n.º 7
0
    def test_fetch_screencapture(self, mock_popen, rhead, p_urllib2, p_log):

        assert Picture.objects.all().count() == 0, Picture.objects.all()

        def mocked_urlopen(request):
            return StringIO("""
            <?xml version="1.0"?>
            <Response>
              <Message>OK</Message>
              <MessageCode>7.4</MessageCode>
              <Success>
                <MediaShortLink>xxx999</MediaShortLink>
                <Token>MXCsxINnVtycv6j02ZVIlS4FcWP</Token>
              </Success>
            </Response>
            """)

        p_urllib2.urlopen = mocked_urlopen

        def mocked_head(url, **options):
            return Response('', 200)

        rhead.side_effect = mocked_head

        ffmpeged_urls = []

        sample_jpg = self.sample_jpg
        sample_jpg2 = self.sample_jpg2

        def mocked_popen(command, **kwargs):
            url = command[4]
            ffmpeged_urls.append(url)
            destination = command[-1]
            assert os.path.isdir(os.path.dirname(destination))

            class Inner:
                def communicate(self):
                    out = err = ''
                    if 'xyz123' in url:
                        if '01.jpg' in destination:
                            shutil.copyfile(sample_jpg, destination)
                        else:
                            shutil.copyfile(sample_jpg2, destination)
                    else:
                        raise NotImplementedError(url)
                    return out, err

            return Inner()

        mock_popen.side_effect = mocked_popen

        event = Event.objects.get(title='Test event')
        template = Template.objects.create(name='Vid.ly Something',
                                           content="{{ tag }}")
        event.template = template
        event.save()
        assert event.duration is None

        videoinfo.fetch_screencaptures()
        assert not ffmpeged_urls  # because no event has a duration yet
        event.duration = 1157
        event.save()

        # Make sure it has a HD VidlySubmission
        VidlySubmission.objects.create(
            event=event,
            url='https://s3.com/asomething.mov',
            tag='xyz123',
            hd=True,
        )
        event.template_environment = {'tag': 'xyz123'}
        event.save()
        videoinfo.fetch_screencaptures()
        assert ffmpeged_urls
        no_screencaptures = settings.SCREENCAPTURES_NO_PICTURES
        eq_(Picture.objects.filter(event=event).count(), no_screencaptures)

        # When viewed, like it's viewed in the picture gallery and gallery
        # select widget, we want the one called "Screencap 1" to appear
        # before the one called "Screencap 2"
        pictures = Picture.objects.all().order_by('event', '-created')
        notes = [x.notes for x in pictures]
        eq_(notes,
            ["Screencap %d" % x for x in range(1, no_screencaptures + 1)])

        # Try to do it again and it shouldn't run it again
        # because there are pictures in the gallery already.
        assert len(ffmpeged_urls) == no_screencaptures, len(ffmpeged_urls)
        videoinfo.fetch_screencaptures()
        eq_(len(ffmpeged_urls), no_screencaptures)
        # and still
        eq_(Picture.objects.filter(event=event).count(), no_screencaptures)