Skip to content

Commit

Permalink
Merge pull request #3 from NYTimes/master
Browse files Browse the repository at this point in the history
bumping bitmovin fork master to master
  • Loading branch information
davidrhodus authored Mar 28, 2017
2 parents 49d169b + 8950523 commit d4d0153
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export ZENCODER_DESTINATION=http://access.key.id:secret.access.key@your-s3-bucke
export BITMOVIN_API_KEY=your.api.key
export BITMOVIN_AWS_ACCESS_KEY_ID=your.access.key.id
export BITMOVIN_AWS_SECRET_ACCESS_KEY=your.secret.access.key
export BITMOVIN_AWS_STORAGE_REGION=your.s3.region.such.as.US_EAST_1.or.EU_WEST_1
export BITMOVIN_ENCODING_REGION=your.provider.region.such.as.AWS_US_EAST_1.or.GOOGLE_EUROPE_WEST_1
```


Expand Down
12 changes: 7 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ type ElementalConductor struct {
// Bitmovin represents the set of configurations for the Bitmovin
// provider.
type Bitmovin struct {
APIKey string `envconfig:"BITMOVIN_API_KEY"`
Endpoint string `envconfig:"BITMOVIN_ENDPOINT" default:"https://api.bitmovin.com/v1/"`
Timeout uint `envconfig:"BITMOVIN_TIMEOUT" default:"5"`
AccessKeyID string `envconfig:"BITMOVIN_AWS_ACCESS_KEY_ID"`
SecretAccessKey string `envconfig:"BITMOVIN_AWS_SECRET_ACCESS_KEY"`
APIKey string `envconfig:"BITMOVIN_API_KEY"`
Endpoint string `envconfig:"BITMOVIN_ENDPOINT" default:"https://api.bitmovin.com/v1/"`
Timeout uint `envconfig:"BITMOVIN_TIMEOUT" default:"5"`
AccessKeyID string `envconfig:"BITMOVIN_AWS_ACCESS_KEY_ID"`
SecretAccessKey string `envconfig:"BITMOVIN_AWS_SECRET_ACCESS_KEY"`
AWSStorageRegion string `envconfig:"BITMOVIN_AWS_STORAGE_REGION" default:"US_EAST_1"`
EncodingRegion string `envconfig:"BITMOVIN_ENCODING_REGION" default:"AWS_US_EAST_1"`
}

// LoadConfig loads the configuration of the API using environment variables.
Expand Down
26 changes: 16 additions & 10 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func TestLoadConfigFromEnv(t *testing.T) {
"BITMOVIN_TIMEOUT": "3",
"BITMOVIN_AWS_ACCESS_KEY_ID": "AKIANOTREALLY",
"BITMOVIN_AWS_SECRET_ACCESS_KEY": "secret-key",
"BITMOVIN_AWS_STORAGE_REGION": "US_WEST_1",
"BITMOVIN_ENCODING_REGION": "GOOGLE_EUROPE_WEST_1",
"SWAGGER_MANIFEST_PATH": "/opt/video-transcoding-api-swagger.json",
"HTTP_ACCESS_LOG": accessLog,
"HTTP_PORT": "8080",
Expand Down Expand Up @@ -80,11 +82,13 @@ func TestLoadConfigFromEnv(t *testing.T) {
Destination: "https://safe-stuff",
},
Bitmovin: &Bitmovin{
APIKey: "secret-key",
Endpoint: "bitmovin",
Timeout: 3,
AccessKeyID: "AKIANOTREALLY",
SecretAccessKey: "secret-key",
APIKey: "secret-key",
Endpoint: "bitmovin",
Timeout: 3,
AccessKeyID: "AKIANOTREALLY",
SecretAccessKey: "secret-key",
AWSStorageRegion: "US_WEST_1",
EncodingRegion: "GOOGLE_EUROPE_WEST_1",
},
Server: &server.Config{
HTTPPort: 8080,
Expand Down Expand Up @@ -182,11 +186,13 @@ func TestLoadConfigFromEnvWithDefauts(t *testing.T) {
Destination: "https://safe-stuff",
},
Bitmovin: &Bitmovin{
APIKey: "secret-key",
Endpoint: "https://api.bitmovin.com/v1/",
Timeout: 5,
AccessKeyID: "AKIANOTREALLY",
SecretAccessKey: "secret-key",
APIKey: "secret-key",
Endpoint: "https://api.bitmovin.com/v1/",
Timeout: 5,
AccessKeyID: "AKIANOTREALLY",
SecretAccessKey: "secret-key",
AWSStorageRegion: "US_EAST_1",
EncodingRegion: "AWS_US_EAST_1",
},
Server: &server.Config{
HTTPPort: 8080,
Expand Down
49 changes: 44 additions & 5 deletions provider/bitmovin/bitmovin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ const bitmovinAPIErrorMsg = "ERROR"
// Just to double check the interface is properly implemented
var _ provider.TranscodingProvider = (*bitmovinProvider)(nil)

var cloudRegions = map[string]struct{}{
"AWS_US_EAST_1": {},
"AWS_US_WEST_1": {},
"AWS_US_WEST_2": {},
"AWS_EU_WEST_1": {},
"AWS_EU_CENTRAL_1": {},
"AWS_AP_SOUTH_1": {},
"AWS_AP_NORTHEAST_1": {},
"AWS_AP_NORTHEAST_2": {},
"AWS_AP_SOUTHEAST_1": {},
"AWS_AP_SOUTHEAST_2": {},
"AWS_SA_EAST_1": {},
"GOOGLE_EUROPE_WEST_1": {},
"GOOGLE_US_EAST_1": {},
"GOOGLE_US_CENTRAL_1": {},
"GOOGLE_ASIA_EAST_1": {},
}

var awsCloudRegions = map[string]struct{}{
"US_EAST_1": {},
"US_WEST_1": {},
"US_WEST_2": {},
"EU_WEST_1": {},
"EU_CENTRAL_1": {},
"AP_SOUTH_1": {},
"AP_NORTHEAST_1": {},
"AP_NORTHEAST_2": {},
"AP_SOUTHEAST_1": {},
"AP_SOUTHEAST_2": {},
"SA_EAST_1": {},
}

func init() {
provider.Register(Name, bitmovinFactory)
}
Expand Down Expand Up @@ -267,10 +299,11 @@ func (p *bitmovinProvider) GetPreset(presetID string) (interface{}, error) {
}

func (p *bitmovinProvider) Transcode(job *db.Job) (*provider.JobStatus, error) {
bucketName, path, fileName, cloudRegion, err := parseS3URL(job.SourceMedia)
bucketName, path, fileName, err := parseS3URL(job.SourceMedia)
if err != nil {
return nil, err
}
cloudRegion := bitmovintypes.AWSCloudRegion(p.config.AWSStorageRegion)

aclEntry := models.ACLItem{
Permission: bitmovintypes.ACLPermissionPublicRead,
Expand Down Expand Up @@ -389,10 +422,11 @@ func (p *bitmovinProvider) Transcode(job *db.Job) (*provider.JobStatus, error) {
if outputtingHLS {
customData["manifest"] = manifestID
}
encodingRegion := bitmovintypes.CloudRegion(p.config.EncodingRegion)
encoding := &models.Encoding{
Name: stringToPtr("encoding"),
CustomData: customData,
CloudRegion: bitmovintypes.CloudRegionAWSUSEast1,
CloudRegion: encodingRegion,
}

encodingResp, err := encodingS.Create(encoding)
Expand Down Expand Up @@ -735,22 +769,27 @@ func bitmovinFactory(cfg *config.Config) (provider.TranscodingProvider, error) {
if cfg.Bitmovin.APIKey == "" {
return nil, errBitmovinInvalidConfig
}
if _, ok := cloudRegions[cfg.Bitmovin.EncodingRegion]; !ok {
return nil, errBitmovinInvalidConfig
}
if _, ok := awsCloudRegions[cfg.Bitmovin.AWSStorageRegion]; !ok {
return nil, errBitmovinInvalidConfig
}
client := bitmovin.NewBitmovin(cfg.Bitmovin.APIKey, cfg.Bitmovin.Endpoint, int64(cfg.Bitmovin.Timeout))
return &bitmovinProvider{client: client, config: cfg.Bitmovin}, nil
}

func parseS3URL(input string) (bucketName string, path string, fileName string, cloudRegion bitmovintypes.AWSCloudRegion, err error) {
func parseS3URL(input string) (bucketName string, path string, fileName string, err error) {
if s3Pattern.MatchString(input) {
truncatedInput := strings.TrimPrefix(input, "s3://")
splitTruncatedInput := strings.Split(truncatedInput, "/")
bucketName = splitTruncatedInput[0]
fileName = splitTruncatedInput[len(splitTruncatedInput)-1]
truncatedInput = strings.TrimPrefix(truncatedInput, bucketName+"/")
path = strings.TrimSuffix(truncatedInput, fileName)
cloudRegion = bitmovintypes.AWSCloudRegionUSEast1
return
}
return "", "", "", bitmovintypes.AWSCloudRegion(""), errors.New("Could not parse S3 URL")
return "", "", "", errors.New("Could not parse S3 URL")
}

func stringToPtr(s string) *string {
Expand Down

0 comments on commit d4d0153

Please sign in to comment.