Commit b2dc95f

bryfry <bryon.fryer@gmail.com>
2016-04-17 01:28:40
code de-dupe
1 parent b4193b2
Changed files (1)
fcpxml2vtt.go
@@ -15,14 +15,7 @@ import (
 	"github.com/dchest/uniuri"
 )
 
-// Sometimes Chapters are inside a transition :/
-type Transition struct {
-	Start_s string  `xml:"offset,attr"`
-	Chapter Chapter `xml:"chapter-marker"`
-}
-
-// Sometimes Chapters are inside a clip :/
-type Clip struct {
+type Parent struct {
 	Start_s string  `xml:"offset,attr"`
 	Chapter Chapter `xml:"chapter-marker"`
 }
@@ -78,56 +71,33 @@ func fcpxParseChapters(filepath string) (chapters []Chapter, err error) {
 		doc.SetRoot(e.Copy())
 		b, _ := doc.WriteToBytes()
 
-		if e.Tag == "transition" {
+		if e.Tag == "transition" || e.Tag == "clip" {
 
-			var tr Transition
-			err = xml.Unmarshal(b, &tr)
+			var pr Parent
+			err = xml.Unmarshal(b, &pr)
 			if err != nil {
-				fmt.Println("Unmarshaling transition failed", tr, err)
+				fmt.Println("Unmarshaling transition failed", pr, err)
 				return chapters, err
 			}
-			if tr.Chapter != (Chapter{}) {
+			if pr.Chapter != (Chapter{}) {
 
-				tr.Chapter.Start, err = fcpxTimeConv(tr.Start_s)
+				pr.Chapter.Start, err = fcpxTimeConv(pr.Start_s)
 				if err != nil {
-					fmt.Println("Transition start timeconf failed: ", err)
+					fmt.Println("Transition start timeconf failed: ", pr.Start_s, err)
 					return chapters, err
 				}
 
-				tr.Chapter.Duration, err = fcpxTimeConv(tr.Chapter.Duration_s)
+				pr.Chapter.Duration, err = fcpxTimeConv(pr.Chapter.Duration_s)
 				if err != nil {
-					fmt.Println("Chapter duration timeconf failed: ", err)
+					fmt.Println("Chapter duration timeconf failed: ", pr.Chapter.Duration_s, err)
 					return chapters, err
 				}
-				chapters = append(chapters, tr.Chapter)
-			}
-
-		} else if e.Tag == "clip" {
-
-			var cl Clip
-			xml.Unmarshal(b, &cl)
-			if err != nil {
-				fmt.Println("Unmarshaling clip failed", cl, err)
-				return chapters, err
-			}
-
-			if cl.Chapter != (Chapter{}) {
-				cl.Chapter.Start, err = fcpxTimeConv(cl.Start_s)
-				if err != nil {
-					fmt.Println("Clip start timeconf failed: ", err)
-					continue
-				}
-				cl.Chapter.Duration, err = fcpxTimeConv(cl.Chapter.Duration_s)
-				if err != nil {
-					fmt.Println("Chapter duration timeconf failed: ", err)
-					continue
-				}
-				chapters = append(chapters, cl.Chapter)
+				chapters = append(chapters, pr.Chapter)
 			}
 
 		} else {
 
-			fmt.Println("Unexpected chapter-marker parent type!")
+			fmt.Println("Unexpected chapter-marker parent type! Call bryfry!")
 			return chapters, err
 
 		}