From 29480f767155bf959f12bf21aef506b132a9191f Mon Sep 17 00:00:00 2001 From: TonyPythoneer Date: Sat, 31 Mar 2018 12:58:41 +0800 Subject: [PATCH 1/5] Cleanup --- dj_elastictranscoder/transcoder.py | 37 ++++++++---------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/dj_elastictranscoder/transcoder.py b/dj_elastictranscoder/transcoder.py index 571271b..f2019d9 100644 --- a/dj_elastictranscoder/transcoder.py +++ b/dj_elastictranscoder/transcoder.py @@ -123,35 +123,19 @@ def __init__( region=None, notify_url=None ): - if not access_key_id: - access_key_id = get_setting_or_raise('ALIYUN_TRANSCODE_ACCESS_KEY_ID') - self.access_key_id = access_key_id - - if not access_key_secret: - access_key_secret = get_setting_or_raise('ALIYUN_TRANSCODE_ACCESS_KEY_SECRET') - self.access_key_secret = access_key_secret - - if not pipeline_id: - pipeline_id = get_setting_or_raise('ALIYUN_TRANSCODE_PIPELINE_ID') - self.pipeline_id = pipeline_id - - if not region: - region = get_setting_or_raise('ALIYUN_TRANSCODE_REGION') - self.region = region - - if not notify_url: - notify_url = get_setting_or_raise('ALIYUN_TRANSCODE_NOTIFY_URL') - self.notify_url = notify_url + self.access_key_id = access_key_id if access_key_id else get_setting_or_raise('ALIYUN_TRANSCODE_ACCESS_KEY_ID') + self.access_key_secret = access_key_secret if access_key_secret else get_setting_or_raise('ALIYUN_TRANSCODE_ACCESS_KEY_SECRET') + self.pipeline_id = pipeline_id if pipeline_id else get_setting_or_raise('ALIYUN_TRANSCODE_ACCESS_KEY_SECRET') + self.region = region if region else get_setting_or_raise('ALIYUN_TRANSCODE_REGION') + self.notify_url = notify_url if notify_url else get_setting_or_raise('ALIYUN_TRANSCODE_NOTIFY_URL') from aliyunsdkcore import client - self.client = client.AcsClient(self.access_key_id, self.access_key_secret, self.region) def start_job(self, obj, transcode_kwargs, message=''): """ - https://help.aliyun.com/document_detail/57347.html?spm=5176.doc56767.6.724.AJ8z3E + Transcoder reference: https://help.aliyun.com/document_detail/67664.html """ - import json from aliyunsdkmts.request.v20140618 import SubmitJobsRequest @@ -165,9 +149,8 @@ def start_job(self, obj, transcode_kwargs, message=''): response = json.loads(self.client.do_action_with_exception(request).decode('utf-8')) content_type = ContentType.objects.get_for_model(obj) - job = EncodeJob() - job.id = response['JobResultList']['JobResult'][0]['Job']['JobId'] - job.content_type = content_type - job.object_id = obj.pk - job.message = message + job = EncodeJob(id=response['JobResultList']['JobResult'][0]['Job']['JobId'], + content_type=content_type, + object_id=obj.pk, + message=message) job.save() From f8e9a9d16d45361990213581c5e70f40d58a0f30 Mon Sep 17 00:00:00 2001 From: sean Date: Sat, 31 Mar 2018 14:06:03 +0800 Subject: [PATCH 2/5] improve version --- dj_elastictranscoder/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dj_elastictranscoder/__init__.py b/dj_elastictranscoder/__init__.py index cd7ca49..a6221b3 100644 --- a/dj_elastictranscoder/__init__.py +++ b/dj_elastictranscoder/__init__.py @@ -1 +1 @@ -__version__ = '1.0.1' +__version__ = '1.0.2' From 54dc6c5c87196c3e75ca95bdb762b03e40868b7f Mon Sep 17 00:00:00 2001 From: TonyPythoneer Date: Sat, 31 Mar 2018 16:12:19 +0800 Subject: [PATCH 3/5] Extend accepted keyarguments when AliyunTranscoder initializing --- dj_elastictranscoder/transcoder.py | 35 ++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/dj_elastictranscoder/transcoder.py b/dj_elastictranscoder/transcoder.py index f2019d9..07152ec 100644 --- a/dj_elastictranscoder/transcoder.py +++ b/dj_elastictranscoder/transcoder.py @@ -120,18 +120,45 @@ def __init__( access_key_id=None, access_key_secret=None, pipeline_id=None, + template_id=None, + bucket_name=None, region=None, + location=None, notify_url=None ): self.access_key_id = access_key_id if access_key_id else get_setting_or_raise('ALIYUN_TRANSCODE_ACCESS_KEY_ID') self.access_key_secret = access_key_secret if access_key_secret else get_setting_or_raise('ALIYUN_TRANSCODE_ACCESS_KEY_SECRET') self.pipeline_id = pipeline_id if pipeline_id else get_setting_or_raise('ALIYUN_TRANSCODE_ACCESS_KEY_SECRET') + self.template_id = template_id if template_id else get_setting_or_raise('ALIYUN_TRANSCODE_TEMPLATE_ID') + self.bucket_name = bucket_name if bucket_name else get_setting_or_raise('ALIYUN_OSS_LOCATION') self.region = region if region else get_setting_or_raise('ALIYUN_TRANSCODE_REGION') + self.location = location if location else get_setting_or_raise('ALIYUN_OSS_LOCATION') self.notify_url = notify_url if notify_url else get_setting_or_raise('ALIYUN_TRANSCODE_NOTIFY_URL') from aliyunsdkcore import client self.client = client.AcsClient(self.access_key_id, self.access_key_secret, self.region) + def make_outputs(self, filename): + try: + from urllib import quote # Python 2.X + except ImportError: + from urllib.parse import quote # Python 3+ + import json + + return json.dumps([{'OutputObject': quote(filename), + 'TemplateId': self.template_id}]) + + def make_input(self, filename): + try: + from urllib import quote # Python 2.X + except ImportError: + from urllib.parse import quote # Python 3+ + import json + + return json.dumps({'Location': self.location, + 'Bucket': self.bucket_name, + 'Object': quote(filename)}) + def start_job(self, obj, transcode_kwargs, message=''): """ Transcoder reference: https://help.aliyun.com/document_detail/67664.html @@ -141,10 +168,10 @@ def start_job(self, obj, transcode_kwargs, message=''): request = SubmitJobsRequest.SubmitJobsRequest() request.set_accept_format('json') - request.set_Input(json.dumps(transcode_kwargs.get('input_file'))) - request.set_OutputBucket(transcode_kwargs.get('bucket')) - request.set_OutputLocation(transcode_kwargs.get('oss_location')) - request.set_Outputs(json.dumps(transcode_kwargs.get('outputs'))) + request.set_Input(json.dumps(transcode_kwargs.get('input'))) + request.set_OutputBucket(self.bucket_name) + request.set_OutputLocation(self.location) + request.set_Outputs(transcode_kwargs.get('outputs')) request.set_PipelineId(self.pipeline_id) response = json.loads(self.client.do_action_with_exception(request).decode('utf-8')) From fa5b38920bf2174fda2ace31c78b7374dbecaf74 Mon Sep 17 00:00:00 2001 From: TonyPythoneer Date: Sat, 31 Mar 2018 16:19:18 +0800 Subject: [PATCH 4/5] Add docstring for AliyunTranscoder --- dj_elastictranscoder/transcoder.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dj_elastictranscoder/transcoder.py b/dj_elastictranscoder/transcoder.py index 07152ec..141f1f1 100644 --- a/dj_elastictranscoder/transcoder.py +++ b/dj_elastictranscoder/transcoder.py @@ -160,7 +160,12 @@ def make_input(self, filename): 'Object': quote(filename)}) def start_job(self, obj, transcode_kwargs, message=''): - """ + """Invoking task of AliyunTranscoder + + transcode_kwargs(dict): Detail how to invoke task of AliyunTranscoder + input(str): A json string by make_input + outputs(str): A json string by make_outputs + Transcoder reference: https://help.aliyun.com/document_detail/67664.html """ import json From 6462587a4d175659ad3872ca3821e48b5ec74675 Mon Sep 17 00:00:00 2001 From: TonyPythoneer Date: Sat, 31 Mar 2018 17:56:05 +0800 Subject: [PATCH 5/5] Fix bucket_name used setting name --- dj_elastictranscoder/transcoder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dj_elastictranscoder/transcoder.py b/dj_elastictranscoder/transcoder.py index 141f1f1..ee7bbb2 100644 --- a/dj_elastictranscoder/transcoder.py +++ b/dj_elastictranscoder/transcoder.py @@ -130,7 +130,7 @@ def __init__( self.access_key_secret = access_key_secret if access_key_secret else get_setting_or_raise('ALIYUN_TRANSCODE_ACCESS_KEY_SECRET') self.pipeline_id = pipeline_id if pipeline_id else get_setting_or_raise('ALIYUN_TRANSCODE_ACCESS_KEY_SECRET') self.template_id = template_id if template_id else get_setting_or_raise('ALIYUN_TRANSCODE_TEMPLATE_ID') - self.bucket_name = bucket_name if bucket_name else get_setting_or_raise('ALIYUN_OSS_LOCATION') + self.bucket_name = bucket_name if bucket_name else get_setting_or_raise('ALIYUN_AUDIO_OSS_BUCKET_NAME') self.region = region if region else get_setting_or_raise('ALIYUN_TRANSCODE_REGION') self.location = location if location else get_setting_or_raise('ALIYUN_OSS_LOCATION') self.notify_url = notify_url if notify_url else get_setting_or_raise('ALIYUN_TRANSCODE_NOTIFY_URL')