|
|
|
|
|
|
|
|
package main |
|
|
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" |
|
|
const baseScheme = "http" |
|
|
|
|
|
|
|
|
type m3u8Json struct { |
|
|
type m3u8Json struct { |
|
|
master *m3u8.MasterPlaylist |
|
|
|
|
|
|
|
|
master *m3u8.MasterPlaylist |
|
|
playlist []*m3u8.MediaPlaylist |
|
|
playlist []*m3u8.MediaPlaylist |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isUrl = true |
|
|
isUrl = true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ! isUrl { |
|
|
|
|
|
|
|
|
if !isUrl { |
|
|
f, err := os.Open("playlist.m3u8") |
|
|
f, err := os.Open("playlist.m3u8") |
|
|
if err!= nil { |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
log.Fatal(err) |
|
|
log.Fatal(err) |
|
|
} |
|
|
} |
|
|
fmt.Println("ok") |
|
|
fmt.Println("ok") |
|
|
data = bufio.NewReader(f) |
|
|
data = bufio.NewReader(f) |
|
|
fmt.Println("ok2") |
|
|
fmt.Println("ok2") |
|
|
} else { |
|
|
} 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()) |
|
|
r, err := http.Get(u.String()) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Fatal(err) |
|
|
log.Fatal(err) |
|
|
|
|
|
|
|
|
case m3u8.MEDIA: |
|
|
case m3u8.MEDIA: |
|
|
mediapl := p.(*m3u8.MediaPlaylist) |
|
|
mediapl := p.(*m3u8.MediaPlaylist) |
|
|
fmt.Printf("%+v\n", mediapl) |
|
|
fmt.Printf("%+v\n", mediapl) |
|
|
output, err := json.MarshalIndent(mediapl,""," ") |
|
|
|
|
|
|
|
|
output, err := json.MarshalIndent(mediapl, "", " ") |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Fatal(err) |
|
|
log.Fatal(err) |
|
|
} |
|
|
} |
|
|
fmt.Printf("%s",output) |
|
|
|
|
|
|
|
|
fmt.Printf("%s", output) |
|
|
case m3u8.MASTER: |
|
|
case m3u8.MASTER: |
|
|
outputJson.master = p.(*m3u8.MasterPlaylist) |
|
|
outputJson.master = p.(*m3u8.MasterPlaylist) |
|
|
fmt.Printf("%+v\n", outputJson.master) |
|
|
fmt.Printf("%+v\n", outputJson.master) |
|
|
for _, entry := range outputJson.master.Variants { |
|
|
for _, entry := range outputJson.master.Variants { |
|
|
fmt.Println(entry.Resolution) |
|
|
fmt.Println(entry.Resolution) |
|
|
if isUrl { |
|
|
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 { |
|
|
if err != nil { |
|
|
log.Fatal(err) |
|
|
log.Fatal(err) |
|
|
} |
|
|
} |
|
|
fmt.Printf("%s",output) |
|
|
|
|
|
|
|
|
fmt.Printf("%s", output) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |