| @@ -1,21 +1,24 @@ | |||
| package main | |||
| import "fmt" | |||
| import "os" | |||
| import "github.com/grafov/m3u8" | |||
| import "bufio" | |||
| import "encoding/json" | |||
| import "net/url" | |||
| import "net/http" | |||
| import "flag" | |||
| import "log" | |||
| import "strings" | |||
| import "path" | |||
| import ( | |||
| "bufio" | |||
| "encoding/json" | |||
| "flag" | |||
| "fmt" | |||
| "log" | |||
| "net/http" | |||
| "net/url" | |||
| "os" | |||
| "path" | |||
| "strings" | |||
| "github.com/grafov/m3u8" | |||
| ) | |||
| const baseScheme = "http" | |||
| type m3u8Json struct { | |||
| master *m3u8.MasterPlaylist | |||
| master *m3u8.MasterPlaylist | |||
| playlist []*m3u8.MediaPlaylist | |||
| } | |||
| @@ -40,16 +43,16 @@ func main() { | |||
| isUrl = true | |||
| } | |||
| if ! isUrl { | |||
| if !isUrl { | |||
| f, err := os.Open("playlist.m3u8") | |||
| if err!= nil { | |||
| if err != nil { | |||
| log.Fatal(err) | |||
| } | |||
| fmt.Println("ok") | |||
| data = bufio.NewReader(f) | |||
| fmt.Println("ok2") | |||
| } else { | |||
| baseUrl = fmt.Sprintf("%v://%v%v",u.Scheme,u.Host,path.Dir(u.EscapedPath())) | |||
| baseUrl = fmt.Sprintf("%v://%v%v", u.Scheme, u.Host, path.Dir(u.EscapedPath())) | |||
| r, err := http.Get(u.String()) | |||
| if err != nil { | |||
| log.Fatal(err) | |||
| @@ -65,24 +68,24 @@ func main() { | |||
| case m3u8.MEDIA: | |||
| mediapl := p.(*m3u8.MediaPlaylist) | |||
| fmt.Printf("%+v\n", mediapl) | |||
| output, err := json.MarshalIndent(mediapl,""," ") | |||
| output, err := json.MarshalIndent(mediapl, "", " ") | |||
| if err != nil { | |||
| log.Fatal(err) | |||
| } | |||
| fmt.Printf("%s",output) | |||
| fmt.Printf("%s", output) | |||
| case m3u8.MASTER: | |||
| outputJson.master = p.(*m3u8.MasterPlaylist) | |||
| fmt.Printf("%+v\n", outputJson.master) | |||
| for _, entry := range outputJson.master.Variants { | |||
| fmt.Println(entry.Resolution) | |||
| if isUrl { | |||
| fmt.Printf("%v/%v\n",baseUrl,entry.URI) | |||
| fmt.Printf("%v/%v\n", baseUrl, entry.URI) | |||
| } | |||
| } | |||
| output, err := json.MarshalIndent(outputJson.master,""," ") | |||
| output, err := json.MarshalIndent(outputJson.master, "", " ") | |||
| if err != nil { | |||
| log.Fatal(err) | |||
| } | |||
| fmt.Printf("%s",output) | |||
| fmt.Printf("%s", output) | |||
| } | |||
| } | |||