diff --git a/.bumpversion.cfg b/.bumpversion.cfg index a9f550e4..484cfe2d 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.1.0 +current_version = 1.2.0 commit = True tag = True diff --git a/frameioclient/client.py b/frameioclient/client.py index 7706706b..9985cd39 100644 --- a/frameioclient/client.py +++ b/frameioclient/client.py @@ -4,8 +4,14 @@ from requests.adapters import HTTPAdapter from requests.packages.urllib3.util.retry import Retry -from .lib import ClientVersion, PaginatedResponse, Utils, ClientVersion, FrameioDownloader - +from .lib import ( + ClientVersion, + PaginatedResponse, + Utils, + ClientVersion, + FrameioDownloader, + PresentationException +) class FrameioConnection(object): def __init__(self, token, host='https://api.frame.io'): @@ -128,3 +134,8 @@ def projects(self): def teams(self): from .service import Team return Team(self) + + @property + def helpers(self): + from .service import FrameioHelpers + return FrameioHelpers(self) diff --git a/frameioclient/lib/__init__.py b/frameioclient/lib/__init__.py index a29d8999..6bc3b71e 100644 --- a/frameioclient/lib/__init__.py +++ b/frameioclient/lib/__init__.py @@ -2,4 +2,4 @@ from .upload import FrameioUploader from .utils import Utils, PaginatedResponse, KB, MB from .exceptions import * -from .version import ClientVersion \ No newline at end of file +from .version import ClientVersion diff --git a/frameioclient/lib/download.py b/frameioclient/lib/download.py index 9605d71a..2533bde5 100644 --- a/frameioclient/lib/download.py +++ b/frameioclient/lib/download.py @@ -1,5 +1,6 @@ import io import os +import sys import math import time import requests @@ -12,7 +13,7 @@ thread_local = threading.local() class FrameioDownloader(object): - def __init__(self, asset, download_folder, prefix, multi_part=False, concurrency=5): + def __init__(self, asset, download_folder, prefix, multi_part=False, concurrency=5, replace=False): self.multi_part = multi_part self.asset = asset self.asset_type = None @@ -27,6 +28,7 @@ def __init__(self, asset, download_folder, prefix, multi_part=False, concurrency self.chunks = math.ceil(self.file_size/self.chunk_size) self.prefix = prefix self.filename = Utils.normalize_filename(asset["name"]) + self.replace = replace self._evaluate_asset() @@ -48,8 +50,12 @@ def _create_file_stub(self): # fp.write(b"\0" * self.file_size) # Disabled to prevent pre-allocatation of disk space fp.close() except FileExistsError as e: - print(e) - raise e + if self.replace == True: + os.remove(self.destination) # Remove the file + self._create_file_stub() # Create a new stub + else: + print(e) + raise e return True def get_download_key(self): diff --git a/frameioclient/service/__init__.py b/frameioclient/service/__init__.py index 0cd634d5..8959ebc8 100644 --- a/frameioclient/service/__init__.py +++ b/frameioclient/service/__init__.py @@ -4,4 +4,5 @@ from .logs import AuditLogs from .comments import Comment from .projects import Project -from .links import ReviewLink, PresentationLink \ No newline at end of file +from .links import ReviewLink, PresentationLink +from .helpers import FrameioHelpers \ No newline at end of file diff --git a/frameioclient/service/assets.py b/frameioclient/service/assets.py index 28e07bc9..3e691482 100644 --- a/frameioclient/service/assets.py +++ b/frameioclient/service/assets.py @@ -75,6 +75,24 @@ def create(self, parent_asset_id, **kwargs): endpoint = '/assets/{}/children'.format(parent_asset_id) return self.client._api_call('post', endpoint, payload=kwargs) + def create_folder(self, parent_asset_id, name="New Folder"): + """ + Create a new folder. + + :Args: + parent_asset_id (string): The parent asset id. + name (string): The name of the new folder. + + Example:: + + client.assets.create_folder( + parent_asset_id="123abc", + name="ExampleFile.mp4", + ) + """ + endpoint = '/assets/{}/children'.format(parent_asset_id) + return self.client._api_call('post', endpoint, payload={"name": name, "type":"folder"}) + def from_url(self, parent_asset_id, name, url): """ Create an asset from a URL. @@ -242,7 +260,7 @@ def upload(self, destination_id, filepath, asset=None): return asset - def download(self, asset, download_folder, prefix=None, multi_part=False, concurrency=5): + def download(self, asset, download_folder, prefix=None, multi_part=False, concurrency=5, replace=False): """ Download an asset. The method will exit once the file is downloaded. diff --git a/frameioclient/service/helpers.py b/frameioclient/service/helpers.py new file mode 100644 index 00000000..adaa5fba --- /dev/null +++ b/frameioclient/service/helpers.py @@ -0,0 +1,32 @@ +from .service import Service + +class FrameioHelpers(Service): + def get_updated_assets(self, account_id, project_id, timestamp): + """ + Get assets added or updated since timestamp. + + :Args: + account_id (string): The account id. + project_id (string): The project id. + timestamp (string): ISO 8601 UTC format. + (datetime.now(timezone.utc).isoformat()) + """ + payload = { + "account_id": account_id, + "page": 1, + "page_size": 50, + "include": "children", + "sort": "-inserted_at", + "filter": { + "project_id": { + "op": "eq", + "value": project_id + }, + "updated_at": { + "op": "gte", + "value": timestamp + } + } + } + endpoint = '/search/library' + return self.client._api_call('post', endpoint, payload=payload) diff --git a/setup.py b/setup.py index 70acd024..aab7c210 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools.command.install import install -version='1.1.0' +version='1.2.0' with open("README.md", "r") as f: long_description = f.read()