From b8cdf4884bac7ab2393a78c71d11037ea8a38774 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 2 Jun 2015 15:42:24 -0700 Subject: [PATCH] fixes bug 1163754 - Start submitting S3 URLs to Vid.ly with ?nocopy --- airmozilla/base/tests/test_utils.py | 10 ++++++++++ airmozilla/base/utils.py | 16 ++++++++++++++++ airmozilla/manage/views/events.py | 3 +++ airmozilla/manage/views/vidly_media.py | 11 ++++++++--- airmozilla/new/views.py | 7 ++++--- bin/crontab/crontab.tpl | 4 ++-- 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/airmozilla/base/tests/test_utils.py b/airmozilla/base/tests/test_utils.py index ac721039..97cecca3 100644 --- a/airmozilla/base/tests/test_utils.py +++ b/airmozilla/base/tests/test_utils.py @@ -24,6 +24,16 @@ def test_unhtml(self): input_ = 'A FOO BAR' eq_(utils.unhtml(input_), 'A FOO BAR') + def test_prepare_vidly_video_url(self): + url = 'https://foo.bar/file.flv' + eq_(utils.prepare_vidly_video_url(url), url) + + url = 'https://mybucket.s3.amazonaws.com/file.mp4' + eq_(utils.prepare_vidly_video_url(url), url + '?nocopy') + + url = 'https://mybucket.s3.amazonaws.com/file.mp4?cachebust=1' + eq_(utils.prepare_vidly_video_url(url), url + '&nocopy') + class _Communicator(object): def __init__(self, response): diff --git a/airmozilla/base/utils.py b/airmozilla/base/utils.py index 1a2f10ea..eeba58fd 100644 --- a/airmozilla/base/utils.py +++ b/airmozilla/base/utils.py @@ -196,3 +196,19 @@ def get_base_url(request): RequestSite(request).domain ) ) + + +def prepare_vidly_video_url(url): + """Return the URL prepared for Vid.ly + See # See http://help.encoding.com/knowledge-base/article/\ + save-some-time-on-your-encodes/ + + Hopefully this will make the transcoding faster. + """ + if 's3.amazonaws.com' in url: + if '?' in url: + url += '&' + else: + url += '?' + url += 'nocopy' + return url diff --git a/airmozilla/manage/views/events.py b/airmozilla/manage/views/events.py index c9dacd01..68326c69 100644 --- a/airmozilla/manage/views/events.py +++ b/airmozilla/manage/views/events.py @@ -33,6 +33,7 @@ unhtml, shorten_url, get_base_url, + prepare_vidly_video_url, ) from airmozilla.main.models import ( Approval, @@ -1523,6 +1524,8 @@ def vidly_url_to_shortcode(request, id): base_url = get_base_url(request) webhook_url = base_url + reverse('manage:vidly_media_webhook') + url = prepare_vidly_video_url(url) + shortcode, error = vidly.add_media( url, token_protection=token_protection, diff --git a/airmozilla/manage/views/vidly_media.py b/airmozilla/manage/views/vidly_media.py index fbd8dbfe..89295cc9 100644 --- a/airmozilla/manage/views/vidly_media.py +++ b/airmozilla/manage/views/vidly_media.py @@ -15,7 +15,11 @@ from jsonview.decorators import json_view import xmltodict -from airmozilla.base.utils import paginate, get_base_url +from airmozilla.base.utils import ( + paginate, + get_base_url, + prepare_vidly_video_url, +) from airmozilla.main.models import Event, VidlySubmission from airmozilla.manage import forms from airmozilla.manage import vidly @@ -244,15 +248,16 @@ def vidly_media_resubmit(request): webhook_url = base_url + reverse('manage:vidly_media_webhook') old_tag = environment['tag'] + url = prepare_vidly_video_url(form.cleaned_data['url']) shortcode, error = vidly.add_media( - url=form.cleaned_data['url'], + url=url, hd=form.cleaned_data['hd'], token_protection=token_protection, notify_url=webhook_url, ) VidlySubmission.objects.create( event=event, - url=form.cleaned_data['url'], + url=url, token_protection=token_protection, hd=form.cleaned_data['hd'], tag=shortcode, diff --git a/airmozilla/new/views.py b/airmozilla/new/views.py index 60a3e239..799fbd8f 100644 --- a/airmozilla/new/views.py +++ b/airmozilla/new/views.py @@ -26,7 +26,7 @@ from PIL import Image from airmozilla.manage import vidly -from airmozilla.base.utils import get_base_url +from airmozilla.base.utils import get_base_url, prepare_vidly_video_url from airmozilla.main.models import ( Event, VidlySubmission, @@ -244,8 +244,9 @@ def event_archive(request, event): base_url = get_base_url(request) webhook_url = base_url + reverse('new:vidly_media_webhook') + video_url = prepare_vidly_video_url(upload.url) tag, error = vidly.add_media( - upload.url, + video_url, hd=True, notify_url=webhook_url, # Note that we deliberately don't bother yet to set @@ -257,7 +258,7 @@ def event_archive(request, event): # then we need to record that we did this vidly_submission = VidlySubmission.objects.create( event=event, - url=upload.url, + url=video_url, tag=tag, hd=True, submission_error=error or None diff --git a/bin/crontab/crontab.tpl b/bin/crontab/crontab.tpl index b8a3fff9..816ee43e 100644 --- a/bin/crontab/crontab.tpl +++ b/bin/crontab/crontab.tpl @@ -9,8 +9,8 @@ HOME=/tmp # Every 1 hour 0 */1 * * * {{ cron }} send_unsent_tweets 2>&1 | grep -Ev '(DeprecationWarning|UserWarning|simplejson|from pkg_resources)' -# Every 15 minutes -*/15 * * * * {{ cron }} auto_archive 2>&1 | grep -Ev '(DeprecationWarning|UserWarning|simplejson|from pkg_resources)' +# Every 10 minutes +*/10 * * * * {{ cron }} auto_archive 2>&1 | grep -Ev '(DeprecationWarning|UserWarning|simplejson|from pkg_resources)' # Daily 7 0 * * * {{ cron }} pester_approvals 2>&1 | grep -Ev '(DeprecationWarning|UserWarning|simplejson|from pkg_resources)'