image_to_video_ai 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +98 -0
- data/lib/image_to_video_ai/client.rb +143 -0
- data/lib/image_to_video_ai/version.rb +5 -0
- data/lib/image_to_video_ai.rb +4 -0
- metadata +73 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 81c18626c41d20d3b9a9cade3237151c0842743efe0068be47a35f997f935470
|
|
4
|
+
data.tar.gz: 565eee3fd8b6313134854676fede2982d450038e803ff14becf97a910c2c82fb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9979b8d04e71185be432d3a764f3a565b645cbbe2247fb0c32b1c7506dc4a9b2a351ee79a956708130618cab960ecb9429b1503889dafa4fab28eb0f540f7318
|
|
7
|
+
data.tar.gz: f73c234dd420eca63ed6ed037b442194dee6c5de15bb1e9e118424186caaeec49da691ea3a02d87430bd2573523889c3d79e000a9040707543b95f1a9582914d
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FlowSpeech
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Image to Video AI Ruby
|
|
2
|
+
|
|
3
|
+
[](https://rubygems.org/gems/image_to_video_ai)
|
|
4
|
+
[](https://github.com/waeckerlinfederowicz66-sketch/image-to-video-ai-ruby/actions/workflows/test.yml)
|
|
5
|
+
|
|
6
|
+
A small Ruby client for the [Image to Video AI generator](https://imagetovideoai.pro/). It creates image-to-video tasks, polls task status, and returns generated video URLs. The gem uses only the Ruby standard library at runtime.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
gem install image_to_video_ai
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or add it to your Gemfile:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem "image_to_video_ai", "~> 0.1"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Create an API key in your Image to Video AI account, then keep it outside source control:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
export IMAGE_TO_VIDEO_AI_API_KEY="your_api_key"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Create a video
|
|
27
|
+
|
|
28
|
+
The input image must be available through a public HTTPS URL.
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
require "image_to_video_ai"
|
|
32
|
+
|
|
33
|
+
client = ImageToVideoAI::Client.new
|
|
34
|
+
task = client.create_video(
|
|
35
|
+
image_url: "https://example.com/start-frame.jpg",
|
|
36
|
+
prompt: "Slow camera push-in while the subject turns toward the light",
|
|
37
|
+
model: "seedance-1.5-pro",
|
|
38
|
+
duration: 5,
|
|
39
|
+
aspect_ratio: "16:9"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
puts "Created #{task.task_id} with status #{task.status}"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Query or wait for the result
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
task = client.result(task_id: task.task_id)
|
|
49
|
+
|
|
50
|
+
finished = client.wait_for_result(
|
|
51
|
+
task_id: task.task_id,
|
|
52
|
+
interval: 5,
|
|
53
|
+
timeout: 600
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
if finished.successful?
|
|
57
|
+
puts finished.url
|
|
58
|
+
else
|
|
59
|
+
warn "Generation ended with status: #{finished.status}"
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Optional generation controls
|
|
64
|
+
|
|
65
|
+
`create_video` also accepts `resolution`, `generate_audio`, `tail_image_url`, and `audio_url`. Model capabilities and credit costs vary; unsupported parameter combinations are returned as structured API errors.
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
begin
|
|
69
|
+
client.create_video(image_url: "https://example.com/frame.jpg", prompt: "Pan left")
|
|
70
|
+
rescue ImageToVideoAI::APIError => error
|
|
71
|
+
warn "#{error.status}: #{error.message} (API code #{error.code})"
|
|
72
|
+
end
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Development
|
|
76
|
+
|
|
77
|
+
Run tests without real credentials or network requests:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
ruby -Ilib test/client_test.rb
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Build the gem locally:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
gem build image_to_video_ai.gemspec
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Security
|
|
90
|
+
|
|
91
|
+
- Never commit API keys.
|
|
92
|
+
- Load `IMAGE_TO_VIDEO_AI_API_KEY` from the environment or a secret manager.
|
|
93
|
+
- The client sends the key only in the `Authorization: Bearer` header.
|
|
94
|
+
- Tests use an injected fake transport and contain no credentials.
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
MIT
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "uri"
|
|
6
|
+
|
|
7
|
+
module ImageToVideoAI
|
|
8
|
+
class Error < StandardError; end
|
|
9
|
+
|
|
10
|
+
class APIError < Error
|
|
11
|
+
attr_reader :status, :code
|
|
12
|
+
|
|
13
|
+
def initialize(message, status:, code: nil)
|
|
14
|
+
super(message)
|
|
15
|
+
@status = status
|
|
16
|
+
@code = code
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Task
|
|
21
|
+
TERMINAL_STATUSES = %w[success failed canceled].freeze
|
|
22
|
+
|
|
23
|
+
attr_reader :task_id, :request_id, :status, :url, :videos
|
|
24
|
+
|
|
25
|
+
def initialize(data)
|
|
26
|
+
@task_id = data.fetch("taskId")
|
|
27
|
+
@request_id = data["requestId"]
|
|
28
|
+
@status = data.fetch("status")
|
|
29
|
+
@url = data["url"]
|
|
30
|
+
@videos = data["videos"] || []
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def complete?
|
|
34
|
+
TERMINAL_STATUSES.include?(status)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def successful?
|
|
38
|
+
status == "success"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Client
|
|
43
|
+
DEFAULT_BASE_URL = "https://imagetovideoai.pro"
|
|
44
|
+
|
|
45
|
+
def initialize(api_key: ENV["IMAGE_TO_VIDEO_AI_API_KEY"], base_url: DEFAULT_BASE_URL,
|
|
46
|
+
open_timeout: 10, read_timeout: 90, transport: nil)
|
|
47
|
+
@api_key = api_key.to_s.strip
|
|
48
|
+
@base_url = URI(base_url)
|
|
49
|
+
@open_timeout = open_timeout
|
|
50
|
+
@read_timeout = read_timeout
|
|
51
|
+
@transport = transport
|
|
52
|
+
|
|
53
|
+
raise ArgumentError, "api_key is required" if @api_key.empty?
|
|
54
|
+
unless @base_url.is_a?(URI::HTTP) && @base_url.host
|
|
55
|
+
raise ArgumentError, "base_url must be an HTTP or HTTPS URL"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def create_video(image_url:, prompt:, model: "seedance-1.5-pro", duration: 5,
|
|
60
|
+
aspect_ratio: "1:1", resolution: nil, generate_audio: nil,
|
|
61
|
+
tail_image_url: nil, audio_url: nil)
|
|
62
|
+
raise ArgumentError, "image_url is required" if image_url.to_s.strip.empty?
|
|
63
|
+
raise ArgumentError, "prompt is required" if prompt.to_s.strip.empty?
|
|
64
|
+
|
|
65
|
+
payload = {
|
|
66
|
+
url: image_url,
|
|
67
|
+
prompt: prompt,
|
|
68
|
+
model: model,
|
|
69
|
+
duration: duration,
|
|
70
|
+
aspectRatio: aspect_ratio
|
|
71
|
+
}
|
|
72
|
+
payload[:resolution] = resolution if resolution
|
|
73
|
+
payload[:generateAudio] = generate_audio unless generate_audio.nil?
|
|
74
|
+
payload[:tailImageUrl] = tail_image_url if tail_image_url
|
|
75
|
+
payload[:audioUrl] = audio_url if audio_url
|
|
76
|
+
|
|
77
|
+
Task.new(request("/api/image2video-figma/create", payload))
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def result(task_id:)
|
|
81
|
+
raise ArgumentError, "task_id is required" if task_id.to_s.strip.empty?
|
|
82
|
+
|
|
83
|
+
Task.new(request("/api/image2video-figma/result", taskId: task_id))
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def wait_for_result(task_id:, interval: 5, timeout: 600)
|
|
87
|
+
deadline = monotonic_time + timeout
|
|
88
|
+
|
|
89
|
+
loop do
|
|
90
|
+
task = result(task_id: task_id)
|
|
91
|
+
return task if task.complete?
|
|
92
|
+
raise Error, "timed out waiting for video task #{task_id}" if monotonic_time >= deadline
|
|
93
|
+
|
|
94
|
+
sleep interval
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
def request(path, payload)
|
|
101
|
+
uri = @base_url + path
|
|
102
|
+
http_request = Net::HTTP::Post.new(uri)
|
|
103
|
+
http_request["Authorization"] = "Bearer #{@api_key}"
|
|
104
|
+
http_request["Accept"] = "application/json"
|
|
105
|
+
http_request["Content-Type"] = "application/json"
|
|
106
|
+
http_request.body = JSON.generate(payload)
|
|
107
|
+
|
|
108
|
+
response = @transport ? @transport.call(uri, http_request) : perform(uri, http_request)
|
|
109
|
+
parsed = parse_json(response.body)
|
|
110
|
+
|
|
111
|
+
unless response.code.to_i.between?(200, 299) && parsed["code"] == 0
|
|
112
|
+
message = parsed["message"].to_s.strip
|
|
113
|
+
message = "Image to Video AI request failed with HTTP #{response.code}" if message.empty?
|
|
114
|
+
raise APIError.new(message, status: response.code.to_i, code: parsed["code"])
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
data = parsed["data"]
|
|
118
|
+
raise Error, "Image to Video AI returned an unexpected response" unless data.is_a?(Hash)
|
|
119
|
+
|
|
120
|
+
data
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def perform(uri, request)
|
|
124
|
+
Net::HTTP.start(
|
|
125
|
+
uri.host,
|
|
126
|
+
uri.port,
|
|
127
|
+
use_ssl: uri.scheme == "https",
|
|
128
|
+
open_timeout: @open_timeout,
|
|
129
|
+
read_timeout: @read_timeout
|
|
130
|
+
) { |http| http.request(request) }
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def parse_json(body)
|
|
134
|
+
JSON.parse(body.to_s)
|
|
135
|
+
rescue JSON::ParserError => e
|
|
136
|
+
raise Error, "Image to Video AI returned invalid JSON: #{e.message}"
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def monotonic_time
|
|
140
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: image_to_video_ai
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Image to Video AI
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-08-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rake
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '12.3'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '14'
|
|
23
|
+
type: :development
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '12.3'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '14'
|
|
33
|
+
description: Create image-to-video tasks, poll their status, and retrieve generated
|
|
34
|
+
video URLs with Image to Video AI.
|
|
35
|
+
email:
|
|
36
|
+
- terazesthornton@gmail.com
|
|
37
|
+
executables: []
|
|
38
|
+
extensions: []
|
|
39
|
+
extra_rdoc_files: []
|
|
40
|
+
files:
|
|
41
|
+
- LICENSE
|
|
42
|
+
- README.md
|
|
43
|
+
- lib/image_to_video_ai.rb
|
|
44
|
+
- lib/image_to_video_ai/client.rb
|
|
45
|
+
- lib/image_to_video_ai/version.rb
|
|
46
|
+
homepage: https://imagetovideoai.pro/
|
|
47
|
+
licenses:
|
|
48
|
+
- MIT
|
|
49
|
+
metadata:
|
|
50
|
+
homepage_uri: https://imagetovideoai.pro/
|
|
51
|
+
source_code_uri: https://github.com/waeckerlinfederowicz66-sketch/image-to-video-ai-ruby
|
|
52
|
+
changelog_uri: https://github.com/waeckerlinfederowicz66-sketch/image-to-video-ai-ruby/releases
|
|
53
|
+
rubygems_mfa_required: 'true'
|
|
54
|
+
post_install_message:
|
|
55
|
+
rdoc_options: []
|
|
56
|
+
require_paths:
|
|
57
|
+
- lib
|
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: 2.6.0
|
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
requirements: []
|
|
69
|
+
rubygems_version: 3.5.22
|
|
70
|
+
signing_key:
|
|
71
|
+
specification_version: 4
|
|
72
|
+
summary: Ruby client for the Image to Video AI generation API
|
|
73
|
+
test_files: []
|