def test_fetch_duration_fail_to_fetch_0_content_length( self, rhead, p_urllib2, p_logging): def mocked_head(url, **options): return Response('<html>', 200, headers={'Content-Length': '0'}) rhead.side_effect = mocked_head event = Event.objects.get(title='Test event') template = Template.objects.create(name='Vid.ly Something', content="{{ tag }}") event.template = template event.template_environment = {'tag': 'abc123'} event.save() assert event.duration is None buffer = StringIO() sys.stdout = buffer try: videoinfo.fetch_durations() finally: sys.stdout = sys.__stdout__ event = Event.objects.get(id=event.id) eq_(event.duration, None) # because it failed output = buffer.getvalue() ok_('{0}/abc123?content=video&format=mp4 has a 0 byte ' 'Content-Length'.format(settings.VIDLY_BASE_URL) in output)
def test_fetch_duration_fail_to_fetch( self, rhead, p_urllib2, p_logging ): def mocked_head(url, **options): return Response( 'Not Found', 404 ) rhead.side_effect = mocked_head event = Event.objects.get(title='Test event') template = Template.objects.create( name='Vid.ly Something', content="{{ tag }}" ) event.template = template event.template_environment = {'tag': 'abc123'} event.save() assert event.duration is None buffer = StringIO() sys.stdout = buffer try: videoinfo.fetch_durations() finally: sys.stdout = sys.__stdout__ event = Event.objects.get(id=event.id) eq_(event.duration, None) # because it failed output = buffer.getvalue() ok_('404' in output)
def test_fetch_duration_fail_to_fetch(self, rhead, p_urllib2, p_logging): def mocked_head(url, **options): return Response('Not Found', 404) rhead.side_effect = mocked_head event = Event.objects.get(title='Test event') template = Template.objects.create(name='Vid.ly Something', content="{{ tag }}") event.template = template event.template_environment = {'tag': 'abc123'} event.save() assert event.duration is None buffer = StringIO() sys.stdout = buffer try: videoinfo.fetch_durations() finally: sys.stdout = sys.__stdout__ event = Event.objects.get(id=event.id) eq_(event.duration, None) # because it failed output = buffer.getvalue() ok_('404' in output)
def handle(self, **options): verbosity = int(options['verbosity']) fetch_durations(max_=int(options['max']), dry_run=options['dry_run'], save_locally=options['save_locally'], save_locally_some=options['save_locally_some'], verbose=verbosity > 1)
def handle(self, **options): verbosity = int(options['verbosity']) fetch_durations( max_=int(options['max']), dry_run=options['dry_run'], save_locally=options['save_locally'], save_locally_some=options['save_locally_some'], verbose=verbosity > 1 )
def handle(self, **options): verbosity = int(options["verbosity"]) fetch_durations( max_=int(options["max"]), dry_run=options["dry_run"], save_locally=options["save_locally"], save_locally_some=options["save_locally_some"], verbose=verbosity > 1, )
def test_fetch_duration_ogg_videos( self, mock_popen, rhead, p_urllib2, p_logging ): def mocked_head(url, **options): return Response( '', 200 ) rhead.side_effect = mocked_head ffmpeged_urls = [] def mocked_popen(command, **kwargs): url = command[2] assert url.endswith('foo.ogg') ffmpeged_urls.append(url) class Inner: def communicate(self): err = """ Duration: 00:10:31.52, start: 0.000000, bitrate: 77 kb/s """ out = '' return out, err return Inner() mock_popen.side_effect = mocked_popen event = Event.objects.get(title='Test event') template = Template.objects.create( name='Ogg Video', content='<source src="{{ url }}" type="video/ogg" />' ) event.template = template event.template_environment = {'url': 'http://videos.m.org/foo.ogg'} event.save() assert event.duration is None videoinfo.fetch_durations() event = Event.objects.get(id=event.id) eq_(event.duration, 631)
def test_fetch_duration_ogg_videos( self, mock_popen, rhead, p_urllib2, p_logging ): def mocked_head(url, **options): return _Response( '', 200 ) rhead.side_effect = mocked_head ffmpeged_urls = [] def mocked_popen(command, **kwargs): url = command[2] assert url.endswith('foo.ogg') ffmpeged_urls.append(url) class Inner: def communicate(self): err = """ Duration: 00:10:31.52, start: 0.000000, bitrate: 77 kb/s """ out = '' return out, err return Inner() mock_popen.side_effect = mocked_popen event = Event.objects.get(title='Test event') template = Template.objects.create( name='Ogg Video', content='<source src="{{ url }}" type="video/ogg" />' ) event.template = template event.template_environment = {'url': 'http://videos.m.org/foo.ogg'} event.save() assert event.duration is None videoinfo.fetch_durations() event = Event.objects.get(id=event.id) eq_(event.duration, 631)
def test_fetch_duration_fail_to_fetch_0_content_length( self, rhead, p_urllib2, p_logging ): def mocked_head(url, **options): return Response( '<html>', 200, headers={ 'Content-Length': '0' } ) rhead.side_effect = mocked_head event = Event.objects.get(title='Test event') template = Template.objects.create( name='Vid.ly Something', content="{{ tag }}" ) event.template = template event.template_environment = {'tag': 'abc123'} event.save() assert event.duration is None buffer = StringIO() sys.stdout = buffer try: videoinfo.fetch_durations() finally: sys.stdout = sys.__stdout__ event = Event.objects.get(id=event.id) eq_(event.duration, None) # because it failed output = buffer.getvalue() ok_( '{0}/abc123?content=video&format=mp4 has a 0 byte ' 'Content-Length'.format(settings.VIDLY_BASE_URL) in output )
def test_fetch_duration_fail_to_fetch_not_video( self, rhead, p_urllib2, p_logging ): def mocked_head(url, **options): return _Response( '<html>', 200, headers={ 'Content-Type': 'text/html; charset=utf-8' } ) rhead.side_effect = mocked_head event = Event.objects.get(title='Test event') template = Template.objects.create( name='Vid.ly Something', content="{{ tag }}" ) event.template = template event.template_environment = {'tag': 'abc123'} event.save() assert event.duration is None buffer = StringIO() sys.stdout = buffer try: videoinfo.fetch_durations() finally: sys.stdout = sys.__stdout__ event = Event.objects.get(id=event.id) eq_(event.duration, None) # because it failed output = buffer.getvalue() ok_( 'https://vid.ly/abc123?content=video&format=mp4 is a ' 'text/html document' in output )
def test_fetch_duration_save_locally_some_by_vidly_submission( self, mock_popen, rget, rhead, p_urllib2, p_logging ): """This time we're going to have two events to ponder. One is public and one is staff only. With passing `save_locally_some` it should do `ffmpeg -i http://url...` on the public one and `wget https://...; ffmpeg -i /local/file.mpg` on the private one. """ 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): # print "HEAD URL", url if 'file.mp4' in url: return Response( '', 200 ) return Response( '', 302, headers={ 'Location': 'https://otherplace.com/file.mp4' } ) rhead.side_effect = mocked_head def mocked_get(url, **options): # print "GET URL", url return Response( '0' * 100000, 200, headers={ 'Content-Length': 100000 } ) rget.side_effect = mocked_get ffmpeged_urls = [] def mocked_popen(command, **kwargs): url = command[2] ffmpeged_urls.append(url) class Inner: def communicate(self): out = '' if 'abc123.mp4' in url and url.startswith('/'): err = """ Duration: 01:05:00.47, start: 0.000000, bitrate: 1076 kb/s """ 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.template_environment = {'tag': 'abc123'} assert event.privacy == Event.PRIVACY_PUBLIC event.save() # The event is public but the relevant vidly submission # for it says it requires a token. VidlySubmission.objects.create( event=event, tag='somethingelse', ) VidlySubmission.objects.create( event=event, tag='abc123', token_protection=True, ) videoinfo.fetch_durations(save_locally_some=True) event = Event.objects.get(id=event.id) eq_(event.duration, 3900) ok_('http://otherplace.com/file.mp4' not in ffmpeged_urls) filename, = ffmpeged_urls ok_(filename.endswith('abc123.mp4'))
def test_fetch_duration(self, mock_popen, rhead, p_urllib2, p_logging): 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 = [] def mocked_popen(command, **kwargs): # print (args, kwargs) url = command[2] ffmpeged_urls.append(url) class Inner: def communicate(self): out = '' if 'abc123' in url: err = "bla bla" elif 'xyz123' in url: err = """ Duration: 00:19:17.47, start: 0.000000, bitrate: 1076 kb/s """ 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.template_environment = {'tag': 'abc123'} event.save() assert event.duration is None videoinfo.fetch_durations() event = Event.objects.get(id=event.id) assert event.duration is None # need to change to a different tag # and make sure it has a 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_durations() event = Event.objects.get(id=event.id) eq_(event.duration, 1157)
def test_fetch_duration_save_locally_some_by_vidly_submission( self, mock_popen, rget, rhead, p_urllib2, p_logging): """This time we're going to have two events to ponder. One is public and one is staff only. With passing `save_locally_some` it should do `ffmpeg -i http://url...` on the public one and `wget https://...; ffmpeg -i /local/file.mpg` on the private one. """ 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): # print "HEAD URL", url if 'file.mp4' in url: return Response('', 200) return Response( '', 302, headers={'Location': 'https://otherplace.com/file.mp4'}) rhead.side_effect = mocked_head def mocked_get(url, **options): # print "GET URL", url return Response('0' * 100000, 200, headers={'Content-Length': 100000}) rget.side_effect = mocked_get ffmpeged_urls = [] def mocked_popen(command, **kwargs): url = command[2] ffmpeged_urls.append(url) class Inner: def communicate(self): out = '' if 'abc123.mp4' in url and url.startswith('/'): err = """ Duration: 01:05:00.47, start: 0.000000, bitrate: 1076 kb/s """ 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.template_environment = {'tag': 'abc123'} assert event.privacy == Event.PRIVACY_PUBLIC event.save() # The event is public but the relevant vidly submission # for it says it requires a token. VidlySubmission.objects.create( event=event, tag='somethingelse', ) VidlySubmission.objects.create( event=event, tag='abc123', token_protection=True, ) videoinfo.fetch_durations(save_locally_some=True) event = Event.objects.get(id=event.id) eq_(event.duration, 3900) ok_('http://otherplace.com/file.mp4' not in ffmpeged_urls) filename, = ffmpeged_urls ok_(filename.endswith('abc123.mp4'))
def test_fetch_duration(self, mock_popen, rhead, p_urllib2, p_logging): 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 = [] def mocked_popen(command, **kwargs): # print (args, kwargs) url = command[2] ffmpeged_urls.append(url) class Inner: def communicate(self): out = '' if 'abc123' in url: err = "bla bla" elif 'xyz123' in url: err = """ Duration: 00:19:17.47, start: 0.000000, bitrate: 1076 kb/s """ 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.template_environment = {'tag': 'abc123'} event.save() assert event.duration is None videoinfo.fetch_durations() event = Event.objects.get(id=event.id) assert event.duration is None # need to change to a different tag # and make sure it has a 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_durations() event = Event.objects.get(id=event.id) eq_(event.duration, 1157)