Skip to content

Instantly share code, notes, and snippets.

@plukevdh
Created June 2, 2018 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plukevdh/efa76463fdd05eff20bf56882ac95587 to your computer and use it in GitHub Desktop.
Save plukevdh/efa76463fdd05eff20bf56882ac95587 to your computer and use it in GitHub Desktop.
Quick and dirty transcoder job
require 'aws-sdk'
Aws.config.update({
region: "us-east-1",
credentials: Aws::SharedCredentials.new(profile_name: "...")
})
PRESET_ID = "..."
PIPELINE_ID = "..."
class Track
attr_reader :album
def initialize(album, path)
@album = album
@path = path
end
def input
{
key: @path
}
end
def name
File.basename(@path, ".wma")
end
def output
{
key: "#{album.artist}/#{album.name}/#{name}.mp3",
preset_id: PRESET_ID
}
end
end
class Album
BASE_PATH = "base-bucket"
attr_reader :name, artist
def initialize(artist, name)
@s3 = Aws::S3::Client.new
@artist = artist
@name = name
end
def tracks
@tracks ||= begin
objects = @s3.list_objects_v2({bucket: BASE_PATH, prefix: "#{artist}/#{name}"})
objects.contents.map {|object| Track.new(self, object.key) }
end
end
end
def transcode(album)
client = Aws::ElasticTranscoder::Client.new
album.tracks.each do |track|
resp = client.create_job({
pipeline_id: PIPELINE_ID,
output_key_prefix: "encoded/",
input: track.input,
output: track.output,
})
end
end
# Place files in a specific bucket like so:
# transcode-bucket
# - my artist
# - album 1
# - album 2
["...", "..."].each do |name|
transcode Album.new("...", name)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment