Skip to content

Commit

Permalink
Add auto_chaptering and auto_transcription to Upload API
Browse files Browse the repository at this point in the history
  • Loading branch information
adimiz1 authored Sep 12, 2024
1 parent f3c8dac commit d9a826a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import Foundation

internal enum CommonResultKeys: CustomStringConvertible {
case publicId, format, version, resourceType, urlType, createdAt, length, width, height, x, y, url, secureUrl, exif, metadata, faces, colors, tags, moderation, context, phash, info, accessControl, eager, qualityAnalysis, coordinates, accessibilityAnalysis, originalFilename, assetFolder, displayName
case publicId, format, version, resourceType, urlType, createdAt, length, width, height, x, y, url, secureUrl, exif, metadata, faces, colors, tags, moderation, context, phash, info, accessControl, eager, qualityAnalysis, coordinates, accessibilityAnalysis, originalFilename, assetFolder, displayName, playbackUrl

var description: String {
switch self {
Expand Down Expand Up @@ -59,6 +59,7 @@ internal enum CommonResultKeys: CustomStringConvertible {
case .originalFilename: return "original_filename"
case .assetFolder: return "asset_folder"
case .displayName: return "display_name"
case .playbackUrl: return "playback_url"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,15 @@ import Foundation
open var displayName: String? {
return getParam(.DisplayName) as? String
}


open var autoChaptering: Bool? {
return getParam(.AutoChaptering) as? Bool
}

open var autoTranscription: Bool? {
return getParam(.AutoTranscription) as? Bool
}

fileprivate func getParam(_ param: UploadRequestParams) -> AnyObject? {
return params[param.rawValue] as AnyObject
}
Expand Down Expand Up @@ -352,7 +360,33 @@ import Foundation
setParam(UploadRequestParams.FilenameOverride.rawValue, value: filenameOverride)
return self
}


/**
Setting this will generate chapters file.

- parameter autoChaptering: The boolean paramter

- returns: The same instance of CLDUploadRequestParams.
*/
@discardableResult
open func setAutoChpatering(_ autoChaptering: Bool) -> Self {
setParam(UploadRequestParams.AutoChaptering.rawValue, value: autoChaptering)
return self
}

/**
Setting this will generate transcription file.

- parameter autoChaptering: The boolean paramter

- returns: The same instance of CLDUploadRequestParams.
*/
@discardableResult
open func setAutoTranscription(_ autoTranscription: Bool) -> Self {
setParam(UploadRequestParams.AutoTranscription.rawValue, value: autoTranscription)
return self
}

/**
Set an HTTP URL to send notification to (a webhook) when the generation of eager transformations is completed.

Expand Down Expand Up @@ -1232,5 +1266,7 @@ import Foundation
case Ocr = "ocr"
case BackgroundRemoval = "background_removal"
case FilenameOverride = "filename_override"
case AutoChaptering = "auto_chaptering"
case AutoTranscription = "auto_transcription"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ import Foundation
open var originalFilename: String? {
return getParam(.originalFilename) as? String
}


open var playbackUrl: String? {
return getParam(.playbackUrl) as? String
}

open var info: CLDInfo? {
guard let info = getParam(.info) as? [String : AnyObject] else {
return nil
Expand Down
54 changes: 54 additions & 0 deletions Example/Tests/NetworkTests/UploaderTests/UploaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,60 @@ class UploaderTests: NetworkBaseTest {
XCTAssertTrue(isUsedFilename(filename: filename, publicId: requestResult?.publicId))
}

func testAutoChaptering() {
XCTAssertNotNil(cloudinary!.config.apiSecret, "Must set api secret for this test")

let expectation = self.expectation(description: "Upload should succeed and return playback url")
let file = TestResourceType.dog.url

var result: CLDUploadResult?
var error: NSError?

let params = CLDUploadRequestParams()
params.setColors(true)
params.setResourceType(.video)
params.setAutoChpatering(true)
cloudinary!.createUploader().signedUpload(url: file, params: params).response({ (resultRes, errorRes) in
result = resultRes
error = errorRes

expectation.fulfill()
})

waitForExpectations(timeout: timeout, handler: nil)

XCTAssertNotNil(result, "result should not be nil")
XCTAssertNotNil(result?.playbackUrl, "playback url should not be nil")
XCTAssertNil(error, "error should be nil")
}

func testAutoTranscription() {
XCTAssertNotNil(cloudinary!.config.apiSecret, "Must set api secret for this test")

let expectation = self.expectation(description: "Upload should succeed and return playback url")
let file = TestResourceType.dog.url

var result: CLDUploadResult?
var error: NSError?

let params = CLDUploadRequestParams()
params.setColors(true)
params.setResourceType(.video)
params.setAutoTranscription(true)
cloudinary!.createUploader().signedUpload(url: file, params: params).response({ (resultRes, errorRes) in
result = resultRes
error = errorRes

expectation.fulfill()
})

waitForExpectations(timeout: timeout, handler: nil)

XCTAssertNotNil(result, "result should not be nil")
XCTAssertNotNil(result?.playbackUrl, "playback url should not be nil")
XCTAssertNil(error, "error should be nil")
}


func validateQualityOverride(publicId: String, quality: String, shouldSucceed: Bool){

Expand Down

0 comments on commit d9a826a

Please sign in to comment.