From e21b77dfae84d25ec1cc65cb50fd821cdaf6cee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Ribeiro?= Date: Sat, 14 Sep 2019 20:52:22 -0400 Subject: [PATCH] expose helper port to mapper in order to mediainfo to get the duration --- handlers/map.go | 5 ++--- vodmodule/mapper.go | 13 +++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/handlers/map.go b/handlers/map.go index 30c1eaa..a75a10a 100644 --- a/handlers/map.go +++ b/handlers/map.go @@ -2,7 +2,6 @@ package handlers import ( "encoding/json" - "fmt" "net/http" "regexp" "strings" @@ -18,7 +17,6 @@ func Map(c Config, client *storage.Client) http.Handler { logger := c.Logger() return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - fmt.Println("URL:", r.URL) if r.Method != http.MethodGet { http.Error(w, "method not allowed", http.StatusMethodNotAllowed) return @@ -37,7 +35,8 @@ func Map(c Config, client *storage.Client) http.Handler { m, err := mapper.Map(r.Context(), vodmodule.MapOptions{ Prefix: prefix, Filter: filter, - ProxyEndpoint: fmt.Sprintf("http://127.0.0.1%s%s", c.Listen, c.Proxy.Endpoint), + ProxyEndpoint: c.Proxy.Endpoint, + ProxyListen: c.Listen, ChapterBreaks: chapterBreaks, }) if err != nil { diff --git a/vodmodule/mapper.go b/vodmodule/mapper.go index 83f5777..53228eb 100644 --- a/vodmodule/mapper.go +++ b/vodmodule/mapper.go @@ -36,6 +36,9 @@ type MapOptions struct { // Optional and specific to cbsinteractive case ChapterBreaks string + // Optional used to build url and fetch duration with mediainfo + ProxyListen string + // Optional regexp that is used to filter the list of objects. Filter *regexp.Regexp } @@ -48,7 +51,7 @@ func (m *Mapper) Map(ctx context.Context, opts MapOptions) (Mapping, error) { var err error r := Mapping{} if opts.ChapterBreaks != "" { - r.Durations, _ = m.chapterBreaksToDurations(ctx, opts.ChapterBreaks, opts.ProxyEndpoint, opts.Prefix) + r.Durations, _ = m.chapterBreaksToDurations(ctx, opts.ChapterBreaks, opts.ProxyListen, opts.ProxyEndpoint, opts.Prefix) } r.Sequences, err = m.getSequences(ctx, opts.Prefix, opts.Filter, opts.ProxyEndpoint, r.Durations) return r, err @@ -105,18 +108,16 @@ func (m *Mapper) getSequences(ctx context.Context, prefix string, filter *regexp return nil, err } -func (m *Mapper) chapterBreaksToDurations(ctx context.Context, chapterBreaks string, endpoint string, prefix string) ([]int, error) { +func (m *Mapper) chapterBreaksToDurations(ctx context.Context, chapterBreaks string, proxyListen string, endpoint string, prefix string) ([]int, error) { var err error var obj *storage.ObjectAttrs previousTimestamp := 0 - totalDurations := 0 splittedChapterBreaks := strings.Split(chapterBreaks, ",") result := make([]int, 0) // is there something better than this? for i := range splittedChapterBreaks { chapterBreakInMs := m.convertChapterBreakInMs(splittedChapterBreaks[i]) result = append(result, chapterBreakInMs-previousTimestamp) - totalDurations = totalDurations + chapterBreakInMs previousTimestamp = chapterBreakInMs } @@ -126,10 +127,10 @@ func (m *Mapper) chapterBreaksToDurations(ctx context.Context, chapterBreaks str Delimiter: "/", }) obj, _ = iter.Next() // ignoring error for now - fileURL := fmt.Sprintf("%s/%s", endpoint, obj.Name) + fileURL := fmt.Sprintf("http://127.0.0.1%s%s/%s", proxyListen, endpoint, obj.Name) mi, _ := mediainfo.New(fileURL, logger, "sample_file") - result = append(result, int(mi.General.Duration.Val)-totalDurations) // last piece should have all the content + result = append(result, int(mi.General.Duration.Val)-previousTimestamp) // last piece should have all the content return result, err }