Created
June 2, 2018 20:43
-
-
Save plukevdh/efa76463fdd05eff20bf56882ac95587 to your computer and use it in GitHub Desktop.
Quick and dirty transcoder job
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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