Class: Tavus::Resources::Videos

Inherits:
Object
  • Object
show all
Defined in:
lib/tavus/resources/videos.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Videos



6
7
8
# File 'lib/tavus/resources/videos.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#create(replica_id:, **options) ⇒ Hash

Generate a new video

Options Hash (**options):

  • :script (String)

    Text script for video generation (required if no audio_url)

  • :audio_url (String)

    URL to audio file (required if no script)

  • :video_name (String)

    Name for the video

  • :background_url (String)

    Link to website for background

  • :background_source_url (String)

    Direct link to background video

  • :callback_url (String)

    URL to receive callbacks

  • :fast (Boolean)

    Use fast rendering process (default: false)

  • :transparent_background (Boolean)

    Generate with transparent background (requires fast: true)

  • :watermark_image_url (String)

    URL to watermark image

  • :properties (Hash)

    Additional properties



24
25
26
27
28
29
30
31
32
33
# File 'lib/tavus/resources/videos.rb', line 24

def create(replica_id:, **options)
  body = options.merge(replica_id: replica_id)

  # Validate that either script or audio_url is provided
  unless body[:script] || body[:audio_url]
    raise ArgumentError, "Either :script or :audio_url must be provided"
  end

  @client.post("/v2/videos", body: body)
end

#delete(video_id, hard: false) ⇒ Hash

Delete a video



75
76
77
78
# File 'lib/tavus/resources/videos.rb', line 75

def delete(video_id, hard: false)
  params = hard ? { hard: true } : {}
  @client.delete("/v2/videos/#{video_id}", params: params)
end

#generate_from_audio(replica_id:, audio_url:, **options) ⇒ Hash

Convenient method to generate video from audio



49
50
51
# File 'lib/tavus/resources/videos.rb', line 49

def generate_from_audio(replica_id:, audio_url:, **options)
  create(replica_id: replica_id, audio_url: audio_url, **options)
end

#generate_from_text(replica_id:, script:, **options) ⇒ Hash

Convenient method to generate video from text



40
41
42
# File 'lib/tavus/resources/videos.rb', line 40

def generate_from_text(replica_id:, script:, **options)
  create(replica_id: replica_id, script: script, **options)
end

#get(video_id, verbose: false) ⇒ Hash

Get a single video by ID



57
58
59
60
# File 'lib/tavus/resources/videos.rb', line 57

def get(video_id, verbose: false)
  params = verbose ? { verbose: true } : {}
  @client.get("/v2/videos/#{video_id}", params: params)
end

#list(**options) ⇒ Hash

List all videos

Options Hash (**options):

  • :limit (Integer)

    Number of videos to return per page (default: 10)

  • :page (Integer)

    Page number to return (default: 1)



67
68
69
# File 'lib/tavus/resources/videos.rb', line 67

def list(**options)
  @client.get("/v2/videos", params: options)
end

#rename(video_id, video_name) ⇒ Hash

Rename a video



84
85
86
# File 'lib/tavus/resources/videos.rb', line 84

def rename(video_id, video_name)
  @client.patch("/v2/videos/#{video_id}/name", body: { video_name: video_name })
end