M3U is a file format, similar to the following:
#EXTINF:, CCTV 1
Mms://live.cctv.com/cctv_live1
#EXTINF:, CCTV 2
Mms://live.cctv.com/live12
For example, the first line is #extinf:,cctv 1, then a comma-separated 2nd string is the file name, and the second row is the file path
The corresponding pls file is as follows:
[Playlist]
numberofentries=116
File1=mms://live.cctv.com/cctv_live1
TITLE1=CCTV 1
File2=mms://live.cctv.com/live12
TITLE2=CCTV 2
It will indicate how many files, filenames, and file paths (shown in key=val this form) are in total.
Here is the code that uses the program to convert a m3u file to a pls file:
Package main import ("FMT" "OS" "strings") type Node struct{File string Title string} func Read File (filepath string,maxsize int) string{file,err: = os. Open (filepath) if err! = nil{FMT. PRINTLN (ERR) return ""} var buffer = make ([] byte,maxsize) Cur,err: = file. Read (buffer) If err! = nil{FMT. PRINTLN (ERR) return ""} var content string = string (Buffer[0:cur]) file. Close () return content} func WriteFile (filepath string,content string) {file,err: = os. Create (filepath) if err! = nil{FMT. PRINTLN (ERR) return} _,err = file. WriteString (content) file. Close () If err! = nil{FMT. PRINTLN (Err)}} func Transm3u2pls (filepath string,maxsize int) {var Dstpath string = "./result.pls" var cont ent string = ReadFile (filepath,maxsize) L: = make ([]node,1000) var cur Node var index int = 0 for _,line : = Range strings. SpLit (content, "\ n") {if index% 2 = = 0{lines: = Strings. Split (line, ",") cur. Title = lines[1]}else{cur. File = line L[INDEX/2] = cur} index++} var newcontent = "[playlist]\n" Newconte NT + = FMT. Sprintf ("numberofentries=%d\n", (INDEX/2)) for i:=0;i<index/2;i++{newcontent + = FMT. Sprintf ("file%d=%s\n", I+1,l[i]. File) Newcontent + = Fmt. Sprintf ("title%d=%s\n", I+1,l[i]. Title)} writefile (Dstpath,newcontent) fmt.
Println ("done!")} Func Main () {if Len (OS. Args) > 1{filepath: = OS. ARGS[1] const MAXSIZE int = 10240 if strings. Hassuffix (filepath, "m3u") {Transm3u2pls (filepath,maxsize)}else{FMT.
PRINTLN ("File format not Suffort (not. m3u)") }}else{FMT. Println ("Usage:./test1 [filepath]")}}