aibirthday 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 +21 -0
- data/README.md +16 -0
- data/lib/aibirthday/version.rb +3 -0
- data/lib/aibirthday.rb +130 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d63269decd9ca0401f28c21ff524e6d6f15661de456d66aaa1f124409f2a1066
|
|
4
|
+
data.tar.gz: e13a92734d8f1a973fd6cd03ada268ed98d820e4367b49538bfe5a72d9659850
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 50595003172207198c0ac5ec169ce6151d52bf602e72c2d201c1a2421c53d555675a6abf8b400b0769956647163625682461d1c662655a7320a08971648dd583
|
|
7
|
+
data.tar.gz: 0f6e9be2f81e4b30eb5b6b04714b2be6e62c68dbdbe653d5cdaaa2908307077a1cc6486471cfb497f6976e08d7ef2b0fd556b0f4eeda4d2fd4c84543c233a959
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AI Birthday Video Generator (https://movoa.ai)
|
|
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.
|
data/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# aibirthday (Ruby SDK)
|
|
2
|
+
|
|
3
|
+
AI birthday video generator from a single photo: they pop champagne on a park bench, blow out a Scorpio cake, or light a crown cake at the car window.
|
|
4
|
+
|
|
5
|
+
Official Ruby gem for [AI Birthday Video Generator](https://aibirthdayvideogenerator.com/?utm_source=rubygems&utm_medium=gem) (`https://aibirthdayvideogenerator.com/`).
|
|
6
|
+
|
|
7
|
+
- Create an API key at [API Keys](https://aibirthdayvideogenerator.com/settings/apikeys) and set `ABVG_API_KEY`.
|
|
8
|
+
- Scene guides: [Read the Docs](https://aibirthdayvideogenerator.readthedocs.io/en/latest/) · Credit packs: [Pricing](https://aibirthdayvideogenerator.com/pricing?utm_source=rubygems&utm_medium=gem).
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
require "aibirthday"
|
|
12
|
+
|
|
13
|
+
client = Aibirthday::Client.new
|
|
14
|
+
clip_url = client.generate_video("pop champagne on a park bench", image_url: "https://example.com/photo.jpg")
|
|
15
|
+
puts clip_url
|
|
16
|
+
```
|
data/lib/aibirthday.rb
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
require_relative "aibirthday/version"
|
|
5
|
+
|
|
6
|
+
module Aibirthday
|
|
7
|
+
BASE_URL = "https://aibirthdayvideogenerator.com".freeze
|
|
8
|
+
KEYS_URL = "https://aibirthdayvideogenerator.com/settings/apikeys".freeze
|
|
9
|
+
DEFAULT_PROVIDER = "kie".freeze
|
|
10
|
+
DEFAULT_MODEL = "seedance-2-mini".freeze
|
|
11
|
+
|
|
12
|
+
class Error < StandardError
|
|
13
|
+
attr_reader :status, :code, :reason, :task_id
|
|
14
|
+
def initialize(msg = nil, status: nil, code: nil, reason: nil, task_id: nil)
|
|
15
|
+
super(msg)
|
|
16
|
+
@status = status
|
|
17
|
+
@code = code
|
|
18
|
+
@reason = reason
|
|
19
|
+
@task_id = task_id
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
class AuthError < Error; end
|
|
23
|
+
class QuotaError < Error; end
|
|
24
|
+
class PlanError < Error; end
|
|
25
|
+
class BusyError < Error; end
|
|
26
|
+
class RejectedError < Error; end
|
|
27
|
+
class GenerationError < Error; end
|
|
28
|
+
class TimeoutError < Error; end
|
|
29
|
+
|
|
30
|
+
def self.classify(status, body)
|
|
31
|
+
body = {} unless body.is_a?(Hash)
|
|
32
|
+
msg = body["message"].to_s
|
|
33
|
+
msg = "request failed (HTTP #{status})" if msg.empty?
|
|
34
|
+
code = body["code"].is_a?(Integer) ? body["code"] : nil
|
|
35
|
+
reason = body["data"].is_a?(Hash) ? body["data"]["reason"] : nil
|
|
36
|
+
klass =
|
|
37
|
+
if status == 401 || msg.downcase.include?("invalid api key") || msg.downcase.include?("no auth") then AuthError
|
|
38
|
+
elsif [-2, -3].include?(code) then RejectedError
|
|
39
|
+
elsif reason == "insufficient_credits" then QuotaError
|
|
40
|
+
elsif reason == "plan_required" then PlanError
|
|
41
|
+
elsif reason == "concurrency" then BusyError
|
|
42
|
+
else Error
|
|
43
|
+
end
|
|
44
|
+
klass.new(msg, status: status, code: code, reason: reason)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class Client
|
|
48
|
+
attr_accessor :poll_every, :timeout
|
|
49
|
+
def initialize(api_key = nil, base_url: nil, poll_every: 10, timeout: 1800, transport: nil)
|
|
50
|
+
@key = (api_key || ENV["ABVG_API_KEY"]).to_s.strip
|
|
51
|
+
base = base_url || ENV["ABVG_BASE_URL"]
|
|
52
|
+
@base = (base.nil? || base.strip.empty? ? BASE_URL : base.strip).chomp("/")
|
|
53
|
+
@poll_every = poll_every
|
|
54
|
+
@timeout = timeout
|
|
55
|
+
@transport = transport || method(:http)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def submit(prompt, image_url: nil)
|
|
59
|
+
raise ArgumentError, "prompt is required" if prompt.to_s.strip.empty?
|
|
60
|
+
opts = { "duration" => "12", "resolution" => "720p", "aspect_ratio" => "9:16" }
|
|
61
|
+
opts["image_input"] = [image_url] if image_url
|
|
62
|
+
body = {
|
|
63
|
+
"provider" => DEFAULT_PROVIDER,
|
|
64
|
+
"mediaType" => "video",
|
|
65
|
+
"model" => DEFAULT_MODEL,
|
|
66
|
+
"scene" => image_url ? "image-to-video" : "text-to-video",
|
|
67
|
+
"prompt" => prompt,
|
|
68
|
+
"options" => opts
|
|
69
|
+
}
|
|
70
|
+
data = call("/api/ai/generate", body)["data"]
|
|
71
|
+
id = data.is_a?(Hash) ? data["id"] : nil
|
|
72
|
+
raise Error, "accepted run but returned no id" if id.nil? || id.to_s.empty?
|
|
73
|
+
id.to_s
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def status(task_id)
|
|
77
|
+
data = call("/api/ai/query", { "taskId" => task_id })["data"]
|
|
78
|
+
data.is_a?(Hash) ? data : {}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def credits
|
|
82
|
+
data = call("/api/user/get-user-credits", {})["data"]
|
|
83
|
+
(data.is_a?(Hash) ? data["remainingCredits"] : 0).to_i
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def wait(task_id)
|
|
87
|
+
deadline = Time.now + @timeout
|
|
88
|
+
loop do
|
|
89
|
+
t = status(task_id)
|
|
90
|
+
case t["status"]
|
|
91
|
+
when "success"
|
|
92
|
+
raise GenerationError.new("finished with no video", task_id: task_id) unless t["videos"].is_a?(Array) && !t["videos"].empty?
|
|
93
|
+
return t
|
|
94
|
+
when "failed", "canceled"
|
|
95
|
+
raise GenerationError.new(t["errorMessage"] || "generation failed", task_id: task_id)
|
|
96
|
+
end
|
|
97
|
+
raise TimeoutError.new("still generating", task_id: task_id) if Time.now + @poll_every > deadline
|
|
98
|
+
sleep @poll_every if @poll_every > 0
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def generate_video(prompt, image_url: nil)
|
|
103
|
+
id = submit(prompt, image_url: image_url)
|
|
104
|
+
wait(id)["videos"].first
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
def call(path, body)
|
|
110
|
+
raise AuthError, "ABVG_API_KEY is not set — create one at #{KEYS_URL}" if @key.empty?
|
|
111
|
+
status_code, raw = @transport.call("#{@base}#{path}", body, @key)
|
|
112
|
+
parsed = begin; JSON.parse(raw.to_s); rescue JSON::ParserError; {}; end
|
|
113
|
+
if status_code >= 400 || (parsed.is_a?(Hash) && parsed["code"].is_a?(Integer) && parsed["code"] != 0)
|
|
114
|
+
raise Aibirthday.classify(status_code, parsed)
|
|
115
|
+
end
|
|
116
|
+
parsed
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def http(url, body, key)
|
|
120
|
+
uri = URI.parse(url)
|
|
121
|
+
req = Net::HTTP::Post.new(uri)
|
|
122
|
+
req["Content-Type"] = "application/json"
|
|
123
|
+
req["Authorization"] = "Bearer #{key}"
|
|
124
|
+
req["User-Agent"] = "aibirthday-rb/#{VERSION}"
|
|
125
|
+
req.body = JSON.generate(body)
|
|
126
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |h| h.request(req) }
|
|
127
|
+
[res.code.to_i, res.body]
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: aibirthday
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- AI Birthday Video Generator
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: 'AI birthday video generator from a single photo: they pop champagne
|
|
14
|
+
on a park bench, blow out a Scorpio cake, or light a crown cake at the car window.'
|
|
15
|
+
email:
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/aibirthday.rb
|
|
23
|
+
- lib/aibirthday/version.rb
|
|
24
|
+
homepage: https://aibirthdayvideogenerator.com/?utm_source=rubygems&utm_medium=gem
|
|
25
|
+
licenses:
|
|
26
|
+
- MIT
|
|
27
|
+
metadata:
|
|
28
|
+
homepage_uri: https://aibirthdayvideogenerator.com/?utm_source=rubygems&utm_medium=gem
|
|
29
|
+
source_code_uri: https://github.com/hanshs474/abvg-rb
|
|
30
|
+
documentation_uri: https://aibirthdayvideogenerator.readthedocs.io/en/latest/
|
|
31
|
+
bug_tracker_uri: https://github.com/hanshs474/abvg-rb/issues
|
|
32
|
+
rubygems_mfa_required: 'false'
|
|
33
|
+
post_install_message:
|
|
34
|
+
rdoc_options: []
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '2.6'
|
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
requirements: []
|
|
48
|
+
rubygems_version: 3.0.3.1
|
|
49
|
+
signing_key:
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: Ruby SDK for AI Birthday Video Generator (aibirthdayvideogenerator.com)
|
|
52
|
+
test_files: []
|