Created
August 9, 2013 04:16
-
-
Save levicole/6191159 to your computer and use it in GitHub Desktop.
id3 tags...not very pretty right now...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
"os" | |
"fmt" | |
"log" | |
"bufio" | |
) | |
func main() { | |
if len(os.Args) < 1 { | |
fmt.Println("Please give me a file name") | |
os.Exit(1) | |
} | |
inFile, err := os.Open(string(os.Args[1])) | |
if err != nil { | |
log.Fatal(err) | |
} | |
if _, err = inFile.Seek(-128, 2); err != nil { | |
log.Fatal(err) | |
} | |
reader := bufio.NewReader(inFile) | |
header := make([]byte, 3) | |
_, err = reader.Read(header) | |
if err != nil { | |
log.Fatal(err) | |
} | |
if string(header) != "TAG" { | |
fmt.Println("This file does not have id3 tags") | |
os.Exit(1) | |
} | |
tag := make([]byte, 125) | |
_, err = reader.Read(tag) | |
if err != nil { | |
log.Fatal(err) | |
} | |
name := string(tag[0:29]) | |
album := string(tag[30:60]) | |
comment := string(tag[61:91]) | |
year := string(tag[92:96]) | |
fmt.Println(name) | |
fmt.Println(album) | |
fmt.Println(comment) | |
fmt.Println(year) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment