コード例 #1
0
ファイル: uploader.py プロジェクト: codingkemboi/Vidly
def update_metadata(metadata, public_ids, **options):
    """
    Populates metadata fields with the given values. Existing values will be overwritten.

    Any metadata-value pairs given are merged with any existing metadata-value pairs
    (an empty value for an existing metadata field clears the value)

    :param metadata: A list of custom metadata fields (by external_id) and the values to assign to each
                     of them.
    :param public_ids: An array of Public IDs of assets uploaded to Cloudinary.
    :param options: Options such as
            *resource_type* (the type of file. Default: image. Valid values: image, raw, or video) and
            *type* (The storage type. Default: upload. Valid values: upload, private, or authenticated.)

    :return: A list of public IDs that were updated
    :rtype: mixed
    """
    params = {
        "timestamp": utils.now(),
        "metadata": utils.encode_context(metadata),
        "public_ids": utils.build_array(public_ids),
        "type": options.get("type")
    }

    return call_api("metadata", params, **options)
コード例 #2
0
def explicit(public_id, **options):
    params = {
        "timestamp":
        utils.now(),
        "type":
        options.get("type"),
        "public_id":
        public_id,
        "callback":
        options.get("callback"),
        "headers":
        utils.build_custom_headers(options.get("headers")),
        "eager":
        utils.build_eager(options.get("eager")),
        "eager_notification_url":
        options.get("eager_notification_url"),
        "eager_async":
        options.get("eager_async"),
        "tags":
        options.get("tags") and ",".join(utils.build_array(options["tags"])),
        "face_coordinates":
        utils.encode_double_array(options.get("face_coordinates")),
        "custom_coordinates":
        utils.encode_double_array(options.get("custom_coordinates")),
        "invalidate":
        options.get("invalidate"),
        "context":
        utils.encode_dict(options.get("context")),
        "responsive_breakpoints":
        utils.generate_responsive_breakpoints_string(
            options.get("responsive_breakpoints"))
    }
    return call_api("explicit", params, **options)
コード例 #3
0
 def setUp(self):
     self.timestamp_tag = "api_test_tag_{0}".format(utils.now())
     if ApiTest.initialized: return
     ApiTest.initialized = True
     cloudinary.reset_config()
     if not cloudinary.config().api_secret: return
     try:
         api.delete_resources(["api_test", "api_test2", "api_test3"])
     except Exception:
         pass
     for transformation in ["api_test_transformation", "api_test_transformation2", "api_test_transformation3"]:
         try:
             api.delete_transformation(transformation)
         except Exception:
             pass
     for transformation in ["api_test_upload_preset", "api_test_upload_preset2", "api_test_upload_preset3",
                            "api_test_upload_preset4"]:
         try:
             api.delete_upload_preset(transformation)
         except Exception:
             pass
     
     for id in ["api_test", "api_test2"]:
         uploader.upload("tests/logo.png",
                         public_id=id, tags=["api_test_tag", self.timestamp_tag],
                         context="key=value", eager=[{"width": 100, "crop": "scale"}])
コード例 #4
0
ファイル: uploader.py プロジェクト: tpof314/pycloudinary
def upload_large_part(file, **options):
    """ Upload large raw files. Note that public_id should include an extension for best results. """
    params = {
        "timestamp":
        utils.now(),
        "type":
        options.get("type"),
        "backup":
        options.get("backup"),
        "final":
        options.get("final"),
        "part_number":
        options.get("part_number"),
        "upload_id":
        options.get("upload_id"),
        "tags":
        options.get("tags") and ",".join(utils.build_array(options["tags"])),
        "public_id":
        options.get("public_id")
    }
    return call_api("upload_large",
                    params,
                    resource_type="raw",
                    file=file,
                    **options)
コード例 #5
0
 def setUp(self):
     self.timestamp_tag = "api_test_tag_{0}".format(utils.now())
     if ApiTest.initialized: return
     ApiTest.initialized = True
     cloudinary.reset_config()
     if not cloudinary.config().api_secret: return
     try:
         api.delete_resources(["api_test", "api_test2", "api_test3"])
     except Exception:
         pass
     for transformation in ["api_test_transformation", "api_test_transformation2", "api_test_transformation3"]:
         try:
             api.delete_transformation(transformation)
         except Exception:
             pass
     for transformation in ["api_test_upload_preset", "api_test_upload_preset2", "api_test_upload_preset3",
                            "api_test_upload_preset4"]:
         try:
             api.delete_upload_preset(transformation)
         except Exception:
             pass
     
     for id in ["api_test", "api_test2"]:
         uploader.upload("tests/logo.png",
                         public_id=id, tags=["api_test_tag", self.timestamp_tag],
                         context="key=value", eager=[{"width": 100, "crop": "scale"}])
コード例 #6
0
def destroy(public_id, **options):
    params = {
        "timestamp": utils.now(),
        "type": options.get("type"),
        "invalidate": options.get("invalidate"),
        "public_id": public_id
    }
    return call_api("destroy", params, **options)
コード例 #7
0
ファイル: uploader.py プロジェクト: nloadholtes/pycloudinary
def destroy(public_id, **options):
    params = {
        "timestamp": utils.now(),
        "type": options.get("type"),
        "invalidate": options.get("invalidate"),
        "public_id":    public_id
    }
    return call_api("destroy", params, **options)
コード例 #8
0
ファイル: uploader.py プロジェクト: nloadholtes/pycloudinary
def call_tags_api(tag, command, public_ids = [], **options):
    params = {
        "timestamp": utils.now(),
        "tag": tag,
        "public_ids": utils.build_array(public_ids),
        "command": command,
        "type": options.get("type")
    }
    return call_api("tags", params, **options)
コード例 #9
0
ファイル: uploader.py プロジェクト: cloudinary/pycloudinary
def call_context_api(context, command, public_ids=None, **options):
    params = {
        "timestamp": utils.now(),
        "context": utils.encode_context(context),
        "public_ids": utils.build_array(public_ids),
        "command": command,
        "type": options.get("type")
    }
    return call_api("context", params, **options)
コード例 #10
0
def explode(public_id, **options):
    params = {
        "timestamp": utils.now(),
        "public_id": public_id,
        "format": options.get("format"),
        "notification_url": options.get("notification_url"),
        "transformation": utils.generate_transformation_string(**options)[0]
    }
    return call_api("explode", params, **options)
コード例 #11
0
def call_tags_api(tag, command, public_ids=None, **options):
    params = {
        "timestamp": utils.now(),
        "tag": tag,
        "public_ids": utils.build_array(public_ids),
        "command": command,
        "type": options.get("type")
    }
    return call_api("tags", params, **options)
コード例 #12
0
def call_context_api(context, command, public_ids=None, **options):
    params = {
        "timestamp": utils.now(),
        "context": utils.encode_context(context),
        "public_ids": utils.build_array(public_ids),
        "command": command,
        "type": options.get("type")
    }
    return call_api("context", params, **options)
コード例 #13
0
ファイル: uploader.py プロジェクト: nloadholtes/pycloudinary
def explode(public_id, **options):
     params = {
        "timestamp": utils.now(),
        "public_id": public_id,
        "format": options.get("format"),
        "notification_url": options.get("notification_url"),
        "transformation": utils.generate_transformation_string(**options)[0]
        }
     return call_api("explode", params, **options)
コード例 #14
0
ファイル: uploader.py プロジェクト: nloadholtes/pycloudinary
def rename(from_public_id, to_public_id, **options):
    params = {
        "timestamp": utils.now(),
        "type": options.get("type"),
        "overwrite": options.get("overwrite"),
        "from_public_id": from_public_id,
        "to_public_id": to_public_id
    }
    return call_api("rename", params, **options)
コード例 #15
0
def generate_sprite(tag, **options):
     params = {
        "timestamp": utils.now(),
        "tag": tag,
        "async": options.get("async"),
        "notification_url": options.get("notification_url"),
        "transformation": utils.generate_transformation_string(fetch_format=options.get("format"), **options)[0]
        }
     return call_api("sprite", params, **options)
コード例 #16
0
ファイル: uploader.py プロジェクト: MatthiasEgli/pycloudinary
def rename(from_public_id, to_public_id, **options):
    params = {
        "timestamp": utils.now(),
        "type": options.get("type"),
        "overwrite": options.get("overwrite"),
        "from_public_id": from_public_id,
        "to_public_id": to_public_id
    }
    return call_api("rename", params, **options)
コード例 #17
0
ファイル: uploader.py プロジェクト: nloadholtes/pycloudinary
def generate_sprite(tag, **options):
     params = {
        "timestamp": utils.now(),
        "tag": tag,
        "async": options.get("async"),
        "notification_url": options.get("notification_url"),
        "transformation": utils.generate_transformation_string(fetch_format=options.get("format"), **options)[0]
        }
     return call_api("sprite", params, **options)
コード例 #18
0
def multi(tag, **options):
    params = {
        "timestamp": utils.now(),
        "tag": tag,
        "format": options.get("format"),
        "async": options.get("async"),
        "notification_url": options.get("notification_url"),
        "transformation": utils.generate_transformation_string(**options)[0]
    }
    return call_api("multi", params, **options)
コード例 #19
0
ファイル: uploader.py プロジェクト: m0she/pycloudinary
def explicit(public_id, **options):
     params = {
        "timestamp": utils.now(),
        "type": options.get("type"),
        "public_id": public_id,
        "callback": options.get("callback"),
        "headers": build_custom_headers(options.get("headers")),
        "eager": build_eager(options.get("eager")),
        "tags": options.get("tags") and ",".join(utils.build_array(options["tags"]))}
     return call_api("explicit", params, **options)
コード例 #20
0
ファイル: uploader.py プロジェクト: nloadholtes/pycloudinary
def multi(tag, **options):
     params = {
        "timestamp": utils.now(),
        "tag": tag,
        "format": options.get("format"),
        "async": options.get("async"),
        "notification_url": options.get("notification_url"),
        "transformation": utils.generate_transformation_string(**options)[0]
        }
     return call_api("multi", params, **options)
コード例 #21
0
ファイル: uploader.py プロジェクト: jmiller1/pycloudinary
def upload_large_part(file, **options):
    """ Upload large raw files. Note that public_id should include an extension for best results. """
    params = {
        "timestamp": utils.now(),
        "type": options.get("type"),
        "backup": options.get("backup"),
        "final": options.get("final"),
        "part_number": options.get("part_number"),
        "upload_id": options.get("upload_id"),
        "public_id": options.get("public_id")
    }
    return call_api("upload_large", params, resource_type="raw", file=file, **options)
コード例 #22
0
def explicit(public_id, **options):
     params = {
        "timestamp": utils.now(),
        "type": options.get("type"),
        "public_id": public_id,
        "callback": options.get("callback"),
        "headers": utils.build_custom_headers(options.get("headers")),
        "eager": utils.build_eager(options.get("eager")),
        "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])),
        "face_coordinates": utils.encode_double_array(options.get("face_coordinates")),
        "custom_coordinates": utils.encode_double_array(options.get("custom_coordinates"))}
     return call_api("explicit", params, **options)
コード例 #23
0
ファイル: uploader.py プロジェクト: codingkemboi/Vidly
def rename(from_public_id, to_public_id, **options):
    params = {
        "timestamp": utils.now(),
        "type": options.get("type"),
        "overwrite": options.get("overwrite"),
        "invalidate": options.get("invalidate"),
        "from_public_id": from_public_id,
        "to_public_id": to_public_id,
        "to_type": options.get("to_type"),
        "context": options.get("context"),
        "metadata": options.get("metadata")
    }
    return call_api("rename", params, **options)
コード例 #24
0
ファイル: uploader.py プロジェクト: nloadholtes/pycloudinary
def explicit(public_id, **options):
     params = {
        "timestamp": utils.now(),
        "type": options.get("type"),
        "public_id": public_id,
        "callback": options.get("callback"),
        "headers": utils.build_custom_headers(options.get("headers")),
        "eager": utils.build_eager(options.get("eager")),
        "eager_notification_url": options.get("eager_notification_url"),
        "eager_async": options.get("eager_async"),
        "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])),
        "face_coordinates": utils.encode_double_array(options.get("face_coordinates")),
        "custom_coordinates": utils.encode_double_array(options.get("custom_coordinates"))}
     return call_api("explicit", params, **options)
コード例 #25
0
ファイル: uploader.py プロジェクト: fer71/new
def explicit(public_id, **options):
    params = {
        "timestamp": utils.now(),
        "type": options.get("type"),
        "public_id": public_id,
        "callback": options.get("callback"),
        "headers": utils.build_custom_headers(options.get("headers")),
        "eager": utils.build_eager(options.get("eager")),
        "eager_notification_url": options.get("eager_notification_url"),
        "eager_async": options.get("eager_async"),
        "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])),
        "face_coordinates": utils.encode_double_array(options.get("face_coordinates")),
        "custom_coordinates": utils.encode_double_array(options.get("custom_coordinates")),
        "invalidate": options.get("invalidate"),
        "context": utils.encode_dict(options.get("context")),
        "responsive_breakpoints": utils.generate_responsive_breakpoints_string(options.get("responsive_breakpoints")),
    }
    return call_api("explicit", params, **options)
コード例 #26
0
ファイル: uploader.py プロジェクト: martyanov/pycloudinary
def build_upload_params(**options):
    params = {"timestamp": utils.now(),
              "transformation": utils.generate_transformation_string(**options)[0],
              "public_id": options.get("public_id"),
              "callback": options.get("callback"),
              "format": options.get("format"),
              "type": options.get("type"),
              "backup": options.get("backup"),
              "faces": options.get("faces"),
              "image_metadata": options.get("image_metadata"),
              "exif": options.get("exif"),
              "colors": options.get("colors"),
              "headers": build_custom_headers(options.get("headers")),
              "eager": build_eager(options.get("eager")),
              "use_filename": options.get("use_filename"),
              "invalidate": options.get("invalidate"),
              "notification_url": options.get("notification_url"),
              "eager_notification_url": options.get("eager_notification_url"),
              "eager_async": options.get("eager_async"),
              "tags": options.get("tags") and ",".join(utils.build_array(options["tags"]))}
    return params
コード例 #27
0
ファイル: uploader.py プロジェクト: nhutphong/djangoblog
def create_slideshow(**options):
    """
    Creates auto-generated video slideshows.

    :param options: The optional parameters.  See the upload API documentation.

    :return: a dictionary with details about created slideshow
    """
    options["resource_type"] = options.get("resource_type", "video")

    params = {param_name: options.get(param_name) for param_name in _SLIDESHOW_PARAMS}

    serialized_params = {
        "timestamp": utils.now(),
        "transformation": build_eager(options.get("transformation")),
        "manifest_transformation": build_eager(options.get("manifest_transformation")),
        "manifest_json": options.get("manifest_json") and utils.json_encode(options.get("manifest_json")),
        "tags": options.get("tags") and utils.encode_list(utils.build_array(options["tags"])),
    }

    params.update(serialized_params)

    return call_api("create_slideshow", params, **options)
コード例 #28
0
ファイル: uploader.py プロジェクト: jmiller1/pycloudinary
def build_upload_params(**options):
    params = {"timestamp": utils.now(),
              "transformation": utils.generate_transformation_string(**options)[0],
              "public_id": options.get("public_id"),
              "callback": options.get("callback"),
              "format": options.get("format"),
              "type": options.get("type"),
              "backup": options.get("backup"),
              "faces": options.get("faces"),
              "image_metadata": options.get("image_metadata"),
              "exif": options.get("exif"),
              "colors": options.get("colors"),
              "headers": build_custom_headers(options.get("headers")),
              "eager": build_eager(options.get("eager")),
              "use_filename": options.get("use_filename"),
              "unique_filename": options.get("unique_filename"),
              "discard_original_filename": options.get("discard_original_filename"),
              "invalidate": options.get("invalidate"),
              "notification_url": options.get("notification_url"),
              "eager_notification_url": options.get("eager_notification_url"),
              "eager_async": options.get("eager_async"),
              "proxy": options.get("proxy"),
              "folder": options.get("folder"),
              "overwrite": options.get("overwrite"),
              "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])),
              "allowed_formats": options.get("allowed_formats") and ",".join(utils.build_array(options["allowed_formats"])),
              "face_coordinates": utils.encode_double_array(options.get("face_coordinates")),
              "context": utils.encode_dict(options.get("context")),
              "moderation": options.get("moderation"),
              "raw_convert": options.get("raw_convert"),
              "ocr": options.get("ocr"),
              "categorization": options.get("categorization"),
              "detection": options.get("detection"),
              "similarity_search": options.get("similarity_search"),
              "auto_tagging": options.get("auto_tagging") and float(options.get("auto_tagging"))}
    params = dict( [ (k, __safe_value(v)) for (k,v) in params.items()] )
    return params
コード例 #29
0
def text(text, **options):
    params = {"timestamp": utils.now(), "text": text}
    for key in TEXT_PARAMS:
        params[key] = options.get(key)
    return call_api("text", params, **options)
コード例 #30
0
ファイル: uploader.py プロジェクト: jmiller1/pycloudinary
def build_upload_params(**options):
    params = {
        "timestamp":
        utils.now(),
        "transformation":
        utils.generate_transformation_string(**options)[0],
        "public_id":
        options.get("public_id"),
        "callback":
        options.get("callback"),
        "format":
        options.get("format"),
        "type":
        options.get("type"),
        "backup":
        options.get("backup"),
        "faces":
        options.get("faces"),
        "image_metadata":
        options.get("image_metadata"),
        "exif":
        options.get("exif"),
        "colors":
        options.get("colors"),
        "headers":
        build_custom_headers(options.get("headers")),
        "eager":
        build_eager(options.get("eager")),
        "use_filename":
        options.get("use_filename"),
        "unique_filename":
        options.get("unique_filename"),
        "discard_original_filename":
        options.get("discard_original_filename"),
        "invalidate":
        options.get("invalidate"),
        "notification_url":
        options.get("notification_url"),
        "eager_notification_url":
        options.get("eager_notification_url"),
        "eager_async":
        options.get("eager_async"),
        "proxy":
        options.get("proxy"),
        "folder":
        options.get("folder"),
        "overwrite":
        options.get("overwrite"),
        "tags":
        options.get("tags") and ",".join(utils.build_array(options["tags"])),
        "allowed_formats":
        options.get("allowed_formats")
        and ",".join(utils.build_array(options["allowed_formats"])),
        "face_coordinates":
        utils.encode_double_array(options.get("face_coordinates")),
        "context":
        utils.encode_dict(options.get("context")),
        "moderation":
        options.get("moderation"),
        "raw_convert":
        options.get("raw_convert"),
        "ocr":
        options.get("ocr"),
        "categorization":
        options.get("categorization"),
        "detection":
        options.get("detection"),
        "similarity_search":
        options.get("similarity_search"),
        "auto_tagging":
        options.get("auto_tagging") and float(options.get("auto_tagging"))
    }
    params = dict([(k, __safe_value(v)) for (k, v) in params.items()])
    return params
コード例 #31
0
import cloudinary
from cloudinary import uploader, utils, api
from cloudinary.compat import PY3, urllib2
import unittest
import tempfile
import os
import zipfile

ARCHIVE_TAG = "archive_tag_" + utils.now()
class ArchiveTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cloudinary.reset_config()
        uploader.upload("tests/logo.png", tags = [ARCHIVE_TAG])
        uploader.upload("tests/logo.png", tags = [ARCHIVE_TAG], transformation=dict(width=10))
    
    @classmethod
    def tearDownClass(cls):
        api.delete_resources_by_tag(ARCHIVE_TAG)

    @unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret")
    def test_create_archive(self):
        """should successfully generate an archive"""
        result = uploader.create_archive(tags = [ARCHIVE_TAG])
        self.assertEqual(2, result.get("file_count"))
        result = uploader.create_zip(tags = [ARCHIVE_TAG], transformations = [{"width": 0.5},{"width": 2.0}])
        self.assertEqual(4, result.get("file_count"))

    @unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret")
    def test_archive_url(self):
        result = utils.download_zip_url(tags = [ARCHIVE_TAG], transformations = [{"width": 0.5},{"width": 2.0}])
コード例 #32
0
import cloudinary
from cloudinary import uploader, utils, api
from cloudinary.compat import PY3, urllib2
import unittest
import tempfile
import os
import zipfile

ARCHIVE_TAG = "archive_tag_" + utils.now()


class ArchiveTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cloudinary.reset_config()
        uploader.upload("tests/logo.png", tags=[ARCHIVE_TAG])
        uploader.upload("tests/logo.png",
                        tags=[ARCHIVE_TAG],
                        transformation=dict(width=10))

    @classmethod
    def tearDownClass(cls):
        api.delete_resources_by_tag(ARCHIVE_TAG)

    @unittest.skipUnless(cloudinary.config().api_secret,
                         "requires api_key/api_secret")
    def test_create_archive(self):
        """should successfully generate an archive"""
        result = uploader.create_archive(tags=[ARCHIVE_TAG])
        self.assertEqual(2, result.get("file_count"))
        result = uploader.create_zip(tags=[ARCHIVE_TAG],
コード例 #33
0
 def setUp(self):
     if StreamingProfilesTest.initialized: return
     StreamingProfilesTest.initialized = True
     cloudinary.reset_config()
     if not cloudinary.config().api_secret: return
     StreamingProfilesTest.test_id = "api_test_{0}".format(utils.now())
コード例 #34
0
ファイル: uploader.py プロジェクト: nloadholtes/pycloudinary
def text(text, **options):
    params = {"timestamp": utils.now(), "text": text}
    for key in TEXT_PARAMS:
        params[key] = options.get(key)
    return call_api("text", params, **options)